]> granicus.if.org Git - strace/commitdiff
tests: robustify unix-yy.test
authorDmitry V. Levin <ldv@altlinux.org>
Thu, 5 Mar 2015 17:30:23 +0000 (17:30 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Thu, 5 Mar 2015 17:44:32 +0000 (17:44 +0000)
Implement additional synchronization between parent and child processes
to guarantee that the child starts closing connected socket only after
exiting of the parent's accept() syscall.
This guarantee seems to be necessary to reliably receive UNIX_DIAG_PEER
messages from NETLINK_SOCK_DIAG interface.

* tests/net-accept-connect.c: Implement additional synchronization
between parent and child processes.
* tests/unix-yy-connect.awk: Update.

tests/net-accept-connect.c
tests/unix-yy-connect.awk

index 6d99e3aa850b0bcb469d63da8472c2f361897f91..c9bc8e4d7439ff1a26506c4d39872ec637680a1e 100644 (file)
@@ -1,12 +1,21 @@
 #include <assert.h>
 #include <stddef.h>
 #include <string.h>
+#include <signal.h>
 #include <unistd.h>
 #include <sys/wait.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 
-int main(int ac, const char **av)
+static void
+handler(int sig)
+{
+       assert(close(1) == 0);
+       _exit(0);
+}
+
+int
+main(int ac, const char **av)
 {
        struct sockaddr_un addr = {
                .sun_family = AF_UNIX,
@@ -40,16 +49,24 @@ int main(int ac, const char **av)
        if (pid) {
                assert(accept(0, (struct sockaddr *) &addr, &len) == 1);
                assert(close(0) == 0);
+               assert(kill(pid, SIGUSR1) == 0);
                int status;
                assert(waitpid(pid, &status, 0) == pid);
                assert(status == 0);
                assert(close(1) == 0);
        } else {
+               sigset_t set;
+               sigemptyset(&set);
+               sigaddset(&set, SIGUSR1);
+
+               assert(sigprocmask(SIG_BLOCK, &set, NULL) == 0);
+               assert(signal(SIGUSR1, handler) != SIG_ERR);
                assert(socket(PF_LOCAL, SOCK_STREAM, 0) == 1);
                assert(close(0) == 0);
                assert(connect(1, (struct sockaddr *) &addr, len) == 0);
-               assert(close(1) == 0);
-               return 0;
+               assert(sigprocmask(SIG_UNBLOCK, &set, NULL) == 0);
+               assert(pause() == 99);
+               return 1;
        }
 
        unlink(av[1]);
index bbbcff910e576284d0a227d3000e408b3dd1a4fa..4641d7839454f732898000da38df65ed121c7a37 100644 (file)
@@ -1,5 +1,5 @@
 BEGIN {
-  lines = 5
+  lines = 6
   fail = 0
   addrlen = length(addr) + 3
 
@@ -20,7 +20,9 @@ NR == 3 {
   }
 }
 
-NR == 4 {
+NR == 4 && /^--- SIGUSR1 / {next}
+
+NR == 5 {
   if (inode != "" && r_close_connected != "" && match($0, r_close_connected, a) && a[1] == inode) {
     next
   }