From: David Smith Date: Thu, 3 Apr 2014 20:08:56 +0000 (-0500) Subject: PR16716 partial fix: Better types in 'syscall.shutdown'. X-Git-Tag: release-2.5~91 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=96a6d28eeaa0f7a34368f369f1d704f2968ab401;p=systemtap.git PR16716 partial fix: Better types in 'syscall.shutdown'. * 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. --- diff --git a/runtime/linux/compat_net.h b/runtime/linux/compat_net.h index ca8050ce1..91c56aff3 100644 --- a/runtime/linux/compat_net.h +++ b/runtime/linux/compat_net.h @@ -19,4 +19,16 @@ #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_ */ diff --git a/tapset/linux/aux_syscalls.stp b/tapset/linux/aux_syscalls.stp index e6fce7c7a..1c072b1d6 100644 --- a/tapset/linux/aux_syscalls.stp +++ b/tapset/linux/aux_syscalls.stp @@ -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 diff --git a/tapset/linux/syscalls2.stp b/tapset/linux/syscalls2.stp index fe8ce26a1..ce1b2d084 100644 --- a/tapset/linux/syscalls2.stp +++ b/tapset/linux/syscalls2.stp @@ -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 index 000000000..1781f424a --- /dev/null +++ b/testsuite/systemtap.syscall/shutdown.c @@ -0,0 +1,53 @@ +/* COVERAGE: shutdown */ + +#include +#include +#include +#include +#include +#include +#include + +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; +}