]> granicus.if.org Git - strace/commitdiff
tests/attach-p-cmd-p.c: cleanup
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 10 Jun 2016 14:20:25 +0000 (14:20 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 10 Jun 2016 14:34:32 +0000 (14:34 +0000)
* attach-p-cmd-p.c (handler): Move code ...
(main): ... here.  Unblock SIGALRM only.
Use alarm() instead of setitimer().
Replace endless loop with a pause() call.
Check that chdir() returns ENOENT.

tests/attach-p-cmd-p.c

index 528d35a98ad615d70ed9f8f19117bc7c295add95..a059ce5311167651e901f85976f86447fc897686 100644 (file)
  */
 
 #include "tests.h"
-#include <assert.h>
+#include <errno.h>
 #include <signal.h>
 #include <stdlib.h>
-#include <time.h>
-#include <sys/time.h>
 #include <unistd.h>
 
 static void
 handler(int signo)
 {
-       _exit(!chdir("attach-p-cmd.test -p"));
 }
 
 int
@@ -50,16 +47,17 @@ main(int ac, char **av)
        if (ac > 2)
                error_msg_and_fail("extra operand");
 
-       const sigset_t set = {};
        const struct sigaction act = { .sa_handler = handler };
-       const struct itimerval itv = { .it_value.tv_sec = atoi(av[1]) };
+       if (sigaction(SIGALRM, &act, NULL))
+               perror_msg_and_skip("sigaction");
 
-       assert(sigaction(SIGALRM, &act, NULL) == 0);
-       assert(sigprocmask(SIG_SETMASK, &set, NULL) == 0);
-       if (setitimer(ITIMER_REAL, &itv, NULL))
-               perror_msg_and_skip("setitimer");
+       sigset_t mask = {};
+       sigaddset(&mask, SIGALRM);
+       if (sigprocmask(SIG_UNBLOCK, &mask, NULL))
+               perror_msg_and_skip("sigprocmask");
 
-       for (;;);
+       alarm(atoi(av[1]));
+       pause();
 
-       return 0;
+       return !(chdir("attach-p-cmd.test -p") && ENOENT == errno);
 }