]> granicus.if.org Git - strace/commitdiff
inotify: decode file descriptor returned by inotify_init
authorEugene Syromyatnikov <evgsyr@gmail.com>
Mon, 24 Sep 2018 06:02:38 +0000 (08:02 +0200)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Tue, 9 Jul 2019 15:42:40 +0000 (17:42 +0200)
* inotify.c (SYS_FUNC(inotify_init)): New function.
* linux/dummy.h (sys_inotify_init): Remove macro definition.
* tests/inotify_init.c: New file.
* tests/inotify_init-y.c: Likewise.
* tests/inotify_init1-y.c: Likewise.
* tests/inotify_init1.c [PRINT_PATHS]: Print inotify fd path.
* tests/inotify_init-y.test: New test.
* tests/.gitignore: Add inotify_init, inotify_init-y, inotify_init1-y.
* tests/pure_executables.list: Likewise.
* tests/gen_tests.in (inotify_init, inotify_init1-y): New tests.
* tests/Makefile.am (DECODER_TESTS): Add inotify_init-y.test.

inotify.c
linux/dummy.h
tests/.gitignore
tests/Makefile.am
tests/gen_tests.in
tests/inotify_init-y.c [new file with mode: 0644]
tests/inotify_init-y.test [new file with mode: 0755]
tests/inotify_init.c [new file with mode: 0644]
tests/inotify_init1-y.c [new file with mode: 0644]
tests/inotify_init1.c
tests/pure_executables.list

index e12df34b014f7582858d810d597dfa012a89b697..cd1562f98c114c455a623cdbef7ce0e7ad6da67c 100644 (file)
--- a/inotify.c
+++ b/inotify.c
@@ -36,6 +36,11 @@ SYS_FUNC(inotify_rm_watch)
        return RVAL_DECODED;
 }
 
+SYS_FUNC(inotify_init)
+{
+       return RVAL_DECODED | RVAL_FD;
+}
+
 SYS_FUNC(inotify_init1)
 {
        printflags(inotify_init_flags, tcp->u_arg[0], "IN_???");
index 15621bd530c1ce66edb2436bf575e7a8ed50ad9f..2f859a6084898218f02e940faeaa2890e582615c 100644 (file)
@@ -92,7 +92,6 @@
 # define sys_getppid           printargs
 # define sys_gettid            printargs
 # define sys_idle              printargs
-# define sys_inotify_init      printargs
 # define sys_munlockall                printargs
 # define sys_pause             printargs
 # define sys_printargs         printargs
index 1a2a653f24a0ef57edb8c59a02d12d97918c1b7b..59c71e00a5999c4e1f69b2554b0dd18a411c5594 100644 (file)
@@ -148,7 +148,10 @@ inet-cmsg
 init_module
 inject-nf
 inotify
+inotify_init
+inotify_init-y
 inotify_init1
+inotify_init1-y
 int_0x80
 io_uring_enter
 io_uring_register
index 7247a5977c3a03af6a4bbea914e8a82c5b215708..a6b79d07cea5c60e6e2ca79c05d89b62c6e67532 100644 (file)
@@ -234,6 +234,7 @@ DECODER_TESTS = \
        futex.test \
        getuid.test \
        int_0x80.test \
+       inotify_init-y.test \
        ioctl.test \
        ioctl_evdev-success-v.test \
        ioctl_evdev-success.test \
index db162bc62d7d9c5f78426394d3bceee5b1c5f778..22e8c93ae7a13f70103e0578d8187bef24f29374 100644 (file)
@@ -123,7 +123,9 @@ group_req   -e trace=setsockopt
 inet-cmsg      -e trace=recvmsg
 init_module    -a27
 inotify        -a23 -e trace=inotify_add_watch,inotify_rm_watch
+inotify_init   -a15
 inotify_init1  -a27
+inotify_init1-y        -a27 -y -e trace=inotify_init1
 io_uring_enter -y
 io_uring_register      -y
 io_uring_setup -a26 -y
diff --git a/tests/inotify_init-y.c b/tests/inotify_init-y.c
new file mode 100644 (file)
index 0000000..cbe094b
--- /dev/null
@@ -0,0 +1,2 @@
+#define PRINT_PATHS
+#include "inotify_init.c"
diff --git a/tests/inotify_init-y.test b/tests/inotify_init-y.test
new file mode 100755 (executable)
index 0000000..69021c9
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+#
+# Check decoding of inotify_init with path decoding enabled.
+#
+# Copyright (c) 2019 The strace developers.
+# All rights reserved.
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+. "${srcdir=.}/init.sh"
+
+# Test expects "anon_inode:inotify" link path format for a inotify fd, which
+# is in place since v2.6.33-rc1~34^2~7. Check for older link path formats
+# is implemented in inotify_init1 test.
+require_min_kernel_version_or_skip 2.6.33
+
+run_strace_match_diff -a15 -y -e trace=inotify_init
diff --git a/tests/inotify_init.c b/tests/inotify_init.c
new file mode 100644 (file)
index 0000000..363811c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Check decoding of inotify_init syscall.
+ *
+ * Copyright (c) 2018-2019 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "tests.h"
+#include <asm/unistd.h>
+#include "scno.h"
+
+#ifdef __NR_inotify_init
+
+# include <stdio.h>
+# include <unistd.h>
+
+int
+main(void)
+{
+#ifdef PRINT_PATHS
+       skip_if_unavailable("/proc/self/fd/");
+#endif
+
+       long rc = syscall(__NR_inotify_init, 42);
+
+#ifdef PRINT_PATHS
+       if (rc < 0)
+               perror_msg_and_skip("inotify_init");
+#endif
+
+       printf("inotify_init() = "
+#ifdef PRINT_PATHS
+              "%ld<anon_inode:inotify>\n", rc
+#else
+              "%s\n", sprintrc(rc)
+#endif
+              );
+
+       puts("+++ exited with 0 +++");
+       return 0;
+}
+
+#else
+
+SKIP_MAIN_UNDEFINED("__NR_inotify_init");
+
+#endif
diff --git a/tests/inotify_init1-y.c b/tests/inotify_init1-y.c
new file mode 100644 (file)
index 0000000..53c65e6
--- /dev/null
@@ -0,0 +1,2 @@
+#define PRINT_PATHS
+#include "inotify_init1.c"
index 4f352b70d46f3796ba0636333e5fcc853c889baf..2408b6471136bcb48e180107307e0fcd3f108832 100644 (file)
 # endif
 # define all_flags (O_NONBLOCK | cloexec_flag)
 
+#ifdef PRINT_PATHS
+# define RC_FMT "%ld<%s>"
+#else
+# define RC_FMT "%s"
+#endif
+
 int
 main(void)
 {
+#ifdef PRINT_PATHS
+       skip_if_unavailable("/proc/self/fd/");
+#endif
+
        static const kernel_ulong_t bogus_flags1 =
                (kernel_ulong_t) 0xfacefeeddeadbeefULL | O_NONBLOCK;
        static const kernel_ulong_t bogus_flags2 =
@@ -46,8 +56,51 @@ main(void)
               (unsigned int) bogus_flags2, sprintrc(rc));
 
        rc = syscall(__NR_inotify_init1, all_flags);
-       printf("inotify_init1(IN_NONBLOCK%s) = %s\n",
-              all_flags & cloexec_flag ? "|IN_CLOEXEC" : "", sprintrc(rc));
+
+#ifdef PRINT_PATHS
+       if (rc < 0)
+               perror_msg_and_skip("inotify_init(%#x)", all_flags);
+
+       /*
+        * Kernels that do not have v2.6.33-rc1~34^2~7 do not have
+        * "anon_inode:" prefix.  Let's assume that it can be either "inotify"
+        * or "anon_inode:inotify" for now, as any change there may be
+        * of interest.
+        */
+       char path[sizeof("/proc/self/fd/") + sizeof(rc) * 3];
+       char buf[2] = "";
+       const char *inotify_path;
+       ssize_t ret;
+
+       ret = snprintf(path, sizeof(path), "/proc/self/fd/%ld", rc);
+       if ((ret < 0) || ((size_t) ret >= sizeof(path)))
+               perror_msg_and_fail("snprintf(path)");
+
+       ret = readlink(path, buf, sizeof(buf));
+       if (ret < 0)
+               perror_msg_and_fail("readlink");
+
+       switch (buf[0]) {
+       case 'a':
+               inotify_path = "anon_inode:inotify";
+               break;
+       case 'i':
+               inotify_path = "inotify";
+               break;
+       default:
+               error_msg_and_fail("Unexpected first char '%c' of inotify fd "
+                                  "link path", buf[0]);
+       }
+#endif
+
+       printf("inotify_init1(IN_NONBLOCK%s) = " RC_FMT "\n",
+              all_flags & cloexec_flag ? "|IN_CLOEXEC" : "",
+#ifdef PRINT_PATHS
+              rc, inotify_path
+#else
+              sprintrc(rc)
+#endif
+              );
 
        puts("+++ exited with 0 +++");
 
index d306085e176b10e18d629ed3efaa3d6a8d77e340..5874979707b4b6e6e708e22387588f51ca3ca758 100755 (executable)
@@ -126,7 +126,10 @@ group_req
 inet-cmsg
 init_module
 inotify
+inotify_init
+inotify_init-y
 inotify_init1
+inotify_init1-y
 io_uring_enter
 io_uring_register
 io_uring_setup