summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorleedagee <leedageea@gmail.com>2023-04-29 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2023-04-29 08:00:00 +0000
commit50111982e27976c3dfa3e3411281b88d778f49d5 (patch)
treeec5898c380412863c830c674861531407bf327e1 /tests
parent551870dc5cc2421bd960bb42fb25d5027af67efc (diff)
downloadstrace-50111982e27976c3dfa3e3411281b88d778f49d5.tar.gz
Implement decoding of signal masks associated with signalfd file descriptors
When signalfds are used, normal signal handling method is usually disabled, leaving strace without signals to catch and decode. This patch adds decoding of signal masks associated with signalfd file descriptors. Decoding the signalfd_siginfo struct requires additional work mentioned in github#199. Signed-off-by: leedagee <leedageea@gmail.com> * NEWS: Mention this change. * doc/strace.1.in: Document --decode-fds=signalfd. * src/strace.c (usage): Likewise. * src/number_set.h (enum decode_fd_bits): Add DECODE_FD_SIGNALFD. * src/filter_qualify.c (decode_fd_str_to_uint): Handle signalfd. * src/util.c (print_fdinfo_sigmask, printsignalfd): New functions. (printfd_pid_with_finfo): Use printsignalfd when DECODE_FD_SIGNALFD is set in decode_fd_set. * tests/signalfd4.c [PRINT_SIGNALFD]: Check decoding of signal masks associated with signalfd file descriptors. * tests/signalfd4-yy.c: New file. * tests/pure_executables.list: Add signalfd4-yy. * tests/.gitignore: Likewise. * tests/gen_tests.in (signalfd4): Add -a32. (signalfd4-yy): New test. Co-authored-by: Dmitry V. Levin <ldv@strace.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/gen_tests.in3
-rwxr-xr-xtests/pure_executables.list1
-rw-r--r--tests/signalfd4-yy.c4
-rw-r--r--tests/signalfd4.c35
5 files changed, 39 insertions, 5 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 4c753e324..d0f99f01e 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -982,6 +982,7 @@ signal
signal_receive
signal_receive--pidns-translation
signalfd4
+signalfd4-yy
sigpending
sigprocmask
sigreturn
diff --git a/tests/gen_tests.in b/tests/gen_tests.in
index 1316ad6e8..f19963b06 100644
--- a/tests/gen_tests.in
+++ b/tests/gen_tests.in
@@ -960,7 +960,8 @@ siginfo -e trace=none
signal -a25 -e signal=none -e trace='/^signal$'
signal_receive -a16 -e trace=kill
signal_receive--pidns-translation test_pidns -a16 -e trace=kill
-signalfd4
+signalfd4 -a32
+signalfd4-yy --trace=signalfd4 -yy
sigpending -a15
sigprocmask -a34
sigreturn -esignal='!USR1'
diff --git a/tests/pure_executables.list b/tests/pure_executables.list
index a1315f64e..4c32d8b99 100755
--- a/tests/pure_executables.list
+++ b/tests/pure_executables.list
@@ -695,6 +695,7 @@ sigaltstack
siginfo
signal
signalfd4
+signalfd4-yy
sigpending
sigprocmask
sigreturn
diff --git a/tests/signalfd4-yy.c b/tests/signalfd4-yy.c
new file mode 100644
index 000000000..6a5262628
--- /dev/null
+++ b/tests/signalfd4-yy.c
@@ -0,0 +1,4 @@
+#define SKIP_IF_PROC_IS_UNAVAILABLE skip_if_unavailable("/proc/self/fd/")
+#define PRINT_SIGNALFD
+
+#include "signalfd4.c"
diff --git a/tests/signalfd4.c b/tests/signalfd4.c
index e45e9425c..97e7977a2 100644
--- a/tests/signalfd4.c
+++ b/tests/signalfd4.c
@@ -20,20 +20,47 @@
# include <sys/signalfd.h>
# include "kernel_fcntl.h"
+#ifndef SKIP_IF_PROC_IS_UNAVAILABLE
+# define SKIP_IF_PROC_IS_UNAVAILABLE
+#endif
+
int
main(void)
{
- const char *const sigs = SIGUSR2 < SIGCHLD ? "USR2 CHLD" : "CHLD USR2";
+ SKIP_IF_PROC_IS_UNAVAILABLE;
+
+ const char *const sigs1 = "USR2";
+ const char *const sigs2 = SIGUSR2 < SIGCHLD ? "USR2 CHLD" : "CHLD USR2";
const unsigned int size = get_sigset_size();
sigset_t mask;
sigemptyset(&mask);
sigaddset(&mask, SIGUSR2);
+
+ int fd = signalfd(-1, &mask, SFD_CLOEXEC | SFD_NONBLOCK);
+
+#ifdef PRINT_SIGNALFD
+ if (fd == -1)
+ perror_msg_and_skip("signalfd");
+#endif
+
+ printf("signalfd4(-1, [%s], %u, SFD_CLOEXEC|SFD_NONBLOCK) = %s",
+ sigs1, size, sprintrc(fd));
+#ifdef PRINT_SIGNALFD
+ printf("<signalfd:[%s]>\n", sigs1);
+#else
+ putchar('\n');
+#endif
+
sigaddset(&mask, SIGCHLD);
+ fd = signalfd(fd, &mask, 0);
- int fd = signalfd(-1, &mask, O_CLOEXEC | O_NONBLOCK);
- printf("signalfd4(-1, [%s], %u, SFD_CLOEXEC|SFD_NONBLOCK) = %s\n",
- sigs, size, sprintrc(fd));
+#ifdef PRINT_SIGNALFD
+ printf("signalfd4(%d<signalfd:[%s]>, [%s], %u, 0) = %s<signalfd:[%s]>\n",
+ fd, sigs1, sigs2, size, sprintrc(fd), sigs2);
+#else
+ printf("signalfd4(%d, [%s], %u, 0) = %s\n", fd, sigs2, size, sprintrc(fd));
+#endif
puts("+++ exited with 0 +++");
return 0;