]> granicus.if.org Git - strace/commitdiff
tests: check signal disposition transparency
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 3 Nov 2017 23:10:38 +0000 (23:10 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 3 Nov 2017 23:10:38 +0000 (23:10 +0000)
Starting with commit v4.17-8-ge97a66f strace is expected
to forward the signal disposition to tracees unchanged.

* tests/check_sigign.c: New file.
* tests/list_sigaction_signum.c: Likewise.
* tests/set_sigign.c: Likewise.
* tests/sigign.test: New test.
* tests/.gitignore: Add check_sigign, list_sigaction_signum,
and set_sigign.
* tests/Makefile.am (check_PROGRAMS): Likewise.
(MISC_TESTS): Add sigign.test.

tests/.gitignore
tests/Makefile.am
tests/check_sigign.c [new file with mode: 0644]
tests/list_sigaction_signum.c [new file with mode: 0644]
tests/set_sigign.c [new file with mode: 0644]
tests/sigign.test [new file with mode: 0755]

index cd4dcc57b867848bf9123a46cac705b248ba5337..976dd7530bedf01dc100be090f673d2ce53d2d61 100644 (file)
@@ -24,6 +24,7 @@ brk
 btrfs
 caps
 caps-abbrev
+check_sigign
 chmod
 chown
 chown32
@@ -162,6 +163,7 @@ lchown32
 libtests.a
 link
 linkat
+list_sigaction_signum
 llseek
 lookup_dcookie
 lseek
@@ -366,6 +368,7 @@ sendfile
 sendfile64
 set_mempolicy
 set_ptracer_any
+set_sigign
 setdomainname
 setfsgid
 setfsgid32
index b4ba22a6443dcfc6ab53b9b46e396125fc743e34..cd74c828d4f7530f1d01a203ab939be22641cc50 100644 (file)
@@ -87,6 +87,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
        attach-p-cmd-p \
        block_reset_raise_run \
        caps-abbrev \
+       check_sigign \
        clone_parent \
        clone_ptrace \
        count-f \
@@ -106,6 +107,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
        ioctl_rtc-v \
        is_linux_mips_n64 \
        ksysent \
+       list_sigaction_signum \
        mmsg-silent \
        mmsg_name-v \
        msg_control-v \
@@ -135,6 +137,7 @@ check_PROGRAMS = $(PURE_EXECUTABLES) \
        seccomp-filter-v \
        seccomp-strict \
        set_ptracer_any \
+       set_sigign \
        signal_receive \
        sleep \
        stack-fcall \
@@ -278,6 +281,7 @@ MISC_TESTS = \
        redirect-fds.test \
        redirect.test \
        restart_syscall.test \
+       sigign.test \
        strace-C.test \
        strace-E.test \
        strace-S.test \
diff --git a/tests/check_sigign.c b/tests/check_sigign.c
new file mode 100644 (file)
index 0000000..6dbe0ab
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Check that the signal handler for the given signan number is set
+ * to SIG_IGN/SIG_DFL.
+ *
+ * Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <signal.h>
+#include <stdlib.h>
+
+int
+main(int ac, char **av)
+{
+       if (ac != 3)
+               error_msg_and_fail("usage: check_sigign 0|1 signum");
+
+       const int ign = !!atoi(av[1]);
+       const int signum = atoi(av[2]);
+       struct sigaction act;
+
+       if (sigaction(signum, NULL, &act))
+               perror_msg_and_fail("sigaction: %s", av[2]);
+
+       return ign ^ (act.sa_handler == SIG_IGN);
+}
diff --git a/tests/list_sigaction_signum.c b/tests/list_sigaction_signum.c
new file mode 100644 (file)
index 0000000..13a78c6
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * List signal numbers that are valid arguments for sigaction syscall.
+ *
+ * Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+
+#include <signal.h>
+#include <stdio.h>
+
+int
+main(void)
+{
+       unsigned int i;
+
+       for (i = 1; i < 32; ++i) {
+               static const struct sigaction ign = { .sa_handler = SIG_IGN };
+               static const struct sigaction dfl = { .sa_handler = SIG_DFL };
+               struct sigaction act;
+
+               if (sigaction(i, &ign, NULL) ||
+                   sigaction(i, NULL, &act) ||
+                   ign.sa_handler != act.sa_handler ||
+                   sigaction(i, &dfl, NULL) ||
+                   sigaction(i, NULL, &act) ||
+                   dfl.sa_handler != act.sa_handler)
+                       continue;
+
+               printf("%u\n", i);
+       }
+
+       return 0;
+}
diff --git a/tests/set_sigign.c b/tests/set_sigign.c
new file mode 100644 (file)
index 0000000..0319fed
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Execute a command with a signal handler set to SIG_IGN/SIG_DFL.
+ *
+ * Copyright (c) 2017 Dmitry V. Levin <ldv@altlinux.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "tests.h"
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+int
+main(int ac, char **av)
+{
+       if (ac < 4)
+               error_msg_and_fail("usage: set_sigign 0|1 signum path...");
+
+       const int ign = atoi(av[1]);
+       const int signum = atoi(av[2]);
+
+       if (signal(signum, ign ? SIG_IGN : SIG_DFL) == SIG_ERR)
+               perror_msg_and_fail("signal: %s", av[2]);
+
+       execvp(av[3], av + 3);
+       perror_msg_and_fail("execvp: %s", av[3]);
+}
diff --git a/tests/sigign.test b/tests/sigign.test
new file mode 100755 (executable)
index 0000000..3164e72
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+# Check signal disposition transparency.
+# Starting with commit v4.17-8-ge97a66f strace is expected
+# to forward the signal disposition to tracees unchanged.
+
+. "${srcdir=.}/init.sh"
+
+run_prog ../list_sigaction_signum > /dev/null
+saved_STRACE="$STRACE"
+
+for sig in $(../list_sigaction_signum); do
+       for ign in 0 1; do
+               set_cmd="../set_sigign $ign $sig"
+               check_cmd="../check_sigign $ign $sig"
+               run_prog $set_cmd $check_cmd
+               STRACE="$set_cmd $saved_STRACE"
+               for i in '' -I1 -I2 -I3 -I4; do
+                       run_strace $i -enone $check_cmd
+               done
+       done
+done