]> sourceware.org Git - systemtap.git/commitdiff
PR16716 partial fix: Better types in 'syscall.shutdown'.
authorDavid Smith <dsmith@redhat.com>
Thu, 3 Apr 2014 20:08:56 +0000 (15:08 -0500)
committerDavid Smith <dsmith@redhat.com>
Thu, 3 Apr 2014 20:08:56 +0000 (15:08 -0500)
* tapset/linux/syscalls2.stp: Fix types in syscall.shutdown.
* tapset/linux/aux_syscalls.stp: Convert _shutdown_how_str() to use
  _stp_lookup_str().
* runtime/linux/compat_net.h: Define SHUT_* for RHEL5.
* testsuite/systemtap.syscall/shutdown.c: New testcase.

runtime/linux/compat_net.h
tapset/linux/aux_syscalls.stp
tapset/linux/syscalls2.stp
testsuite/systemtap.syscall/shutdown.c [new file with mode: 0644]

index ca8050ce19de620079e510fd08dcc52abc41cd9a..91c56aff3c627589254bd8b4b9d177890f3244a0 100644 (file)
 #define SYS_SENDMMSG 20
 #endif
 
+/* Older kernels don't have these defined. On some kernels these are
+ * enums, but the following code should still work. */
+#ifndef SHUT_RD
+#define SHUT_RD 0
+#endif
+#ifndef SHUT_WR
+#define SHUT_WR 1
+#endif
+#ifndef SHUT_RDWR
+#define SHUT_RDWR 2
+#endif
+
 #endif /* _COMPAT_NET_H_ */
index e6fce7c7ac50558e87339ae403b1fa5f7968aac8..1c072b1d69fd0e7ee3702d8c00abe2c172badb64 100644 (file)
@@ -1330,12 +1330,20 @@ function _priority_which_str(which) {
    return sprintf("UNKNOWN VALUE: %d", which)
 }
 
-function _shutdown_how_str(how) {
-   if(how==0) return "SHUT_RD"
-   if(how==1) return "SHUT_WR"
-   if(how==2) return "SHUT_RDWR"
-   return sprintf("UNKNOWN VALUE: %d", how)
-}
+%{
+static const _stp_val_array const _stp_shutdown_how_list[] = {
+       V(SHUT_RD),
+       V(SHUT_WR),
+       V(SHUT_RDWR),
+       {0, NULL}
+};
+%}
+
+function _shutdown_how_str(how)
+%{ /* pure */
+       _stp_lookup_str(_stp_shutdown_how_list, (unsigned int)STAP_ARG_how,
+                       STAP_RETVALUE, MAXSTRINGLEN);
+%}
 
 %{
 // Needed for function __reboot_magic_str:string. Unfortunately cannot
index fe8ce26a1ceea7861cb2ab9287387ebe7eb935e4..ce1b2d084fb6663e0d0bb95b58dc846962204313 100644 (file)
@@ -2867,10 +2867,10 @@ probe syscall.shmget.return = kernel.function("sys_shmget").return ?
 probe syscall.shutdown = kernel.function("sys_shutdown").call ?
 {
        name = "shutdown"
-       s = $fd
-       how = $how
-       how_str = _shutdown_how_str($how)
-       argstr = sprintf("%d, %s", $fd, how_str)
+       s = __int32($fd)
+       how = __int32($how)
+       how_str = _shutdown_how_str(how)
+       argstr = sprintf("%d, %s", s, how_str)
 }
 probe syscall.shutdown.return = kernel.function("sys_shutdown").return ?
 {
diff --git a/testsuite/systemtap.syscall/shutdown.c b/testsuite/systemtap.syscall/shutdown.c
new file mode 100644 (file)
index 0000000..1781f42
--- /dev/null
@@ -0,0 +1,53 @@
+/* COVERAGE: shutdown */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+int main()
+{
+  char buf[1024];
+  int s;
+  int fd_null;
+  struct sockaddr_in sin1;
+
+  sin1.sin_family = AF_INET;
+  /* this port must be unused! */
+  sin1.sin_port = htons((getpid() % 32768) + 10000);
+  sin1.sin_addr.s_addr = INADDR_ANY;
+
+  fd_null = open("/dev/null", O_WRONLY);
+
+  shutdown(-1, SHUT_RD);
+  //staptest// shutdown (-1, SHUT_RD) = -NNNN (EBADF)
+
+  shutdown(fd_null, SHUT_WR);
+  //staptest// shutdown (NNNN, SHUT_WR) = -NNNN (ENOTSOCK)
+
+  s = socket(PF_INET, SOCK_STREAM, 0);
+  //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_IP) = NNNN
+
+  shutdown(s, SHUT_RDWR);
+  //staptest// shutdown (NNNN, SHUT_RDWR) = -NNNN (ENOTCONN)
+
+  close(s);
+  //staptest// close (NNNN) = 0
+  
+  s = socket(PF_INET, SOCK_STREAM, 0);
+  //staptest// socket (PF_INET, SOCK_STREAM, IPPROTO_IP) = NNNN
+
+  shutdown(s, -1);
+  //staptest// shutdown (NNNN, 0xffffffff) = -NNNN (EINVAL)
+
+  close(s);
+  //staptest// close (NNNN) = 0
+
+  close(fd_null);
+  //staptest// close (NNNN) = 0
+
+  return 0;
+}
This page took 0.045708 seconds and 5 git commands to generate.