]> granicus.if.org Git - strace/commitdiff
strace.c: pass signal to cleanup() instead of reading it inside it
authorEugene Syromyatnikov <evgsyr@gmail.com>
Thu, 21 Feb 2019 11:56:29 +0000 (12:56 +0100)
committerEugene Syromyatnikov <evgsyr@gmail.com>
Wed, 27 Feb 2019 16:30:51 +0000 (17:30 +0100)
* strace.c (die): Pass 0 as an argument to cleanup().
(cleanup): Add fatal_sig parameter, remove the local variable
of the same name, do not use interrupted.
(terminate): Initialise new sig local variable with interrupted,
pass it to cleanup and use it instead of the latter for exit_code
initialisation.

strace.c

index 8ab962064b46c0bd82dd7ad5ffccc68fe7b0404b..aa337090bed4b780a6090952c963f6bc368a9c9f 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -162,7 +162,7 @@ char *program_invocation_name;
 unsigned os_release; /* generated from uname()'s u.release */
 
 static void detach(struct tcb *tcp);
-static void cleanup(void);
+static void cleanup(int sig);
 static void interrupt(int sig);
 
 #ifdef HAVE_SIG_ATOMIC_T
@@ -314,7 +314,7 @@ void ATTRIBUTE_NORETURN
 die(void)
 {
        if (strace_tracer_pid == getpid()) {
-               cleanup();
+               cleanup(0);
                exit(1);
        }
 
@@ -1932,14 +1932,11 @@ pid2tcb(const int pid)
 }
 
 static void
-cleanup(void)
+cleanup(int fatal_sig)
 {
        unsigned int i;
        struct tcb *tcp;
-       int fatal_sig;
 
-       /* 'interrupted' is a volatile object, fetch it only once */
-       fatal_sig = interrupted;
        if (!fatal_sig)
                fatal_sig = SIGTERM;
 
@@ -2789,7 +2786,9 @@ extern void __gcov_flush(void);
 static void ATTRIBUTE_NORETURN
 terminate(void)
 {
-       cleanup();
+       int sig = interrupted;
+
+       cleanup(sig);
        if (cflag)
                call_summary(shared_log);
        fflush(NULL);
@@ -2799,8 +2798,8 @@ terminate(void)
                while (waitpid(popen_pid, NULL, 0) < 0 && errno == EINTR)
                        ;
        }
-       if (interrupted) {
-               exit_code = 0x100 | interrupted;
+       if (sig) {
+               exit_code = 0x100 | sig;
        }
        if (exit_code > 0xff) {
                /* Avoid potential core file clobbering.  */