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
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 ?
{
--- /dev/null
+/* 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;
+}