]> granicus.if.org Git - strace/commitdiff
strace: do not call sigsetjmp without a delay timer
authorDmitry V. Levin <ldv@altlinux.org>
Fri, 23 Mar 2018 00:20:33 +0000 (00:20 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 23 Mar 2018 00:20:33 +0000 (00:20 +0000)
As sigsetjmp costs a syscall, do not call it unless a delay timer
is already created and its signal handler is going to be unblocked.

* strace.c (next_event): Move sigsetjmp invocation under
is_delay_timer_created() condition.

Optimizes: v4.21-108-gba8e768 ("Implement delay injection")

strace.c

index 397f5d51939e943dece6ab1c22d7c80fe795491c..173fdab7be5f70c276d10e61a74cd427991484b1 100644 (file)
--- a/strace.c
+++ b/strace.c
@@ -2238,14 +2238,6 @@ next_event(int *pstatus, siginfo_t *si)
                        return TE_BREAK;
        }
 
-       if (sigsetjmp(timer_jmp_buf, 1)) {
-               /*
-                * restart_delayed_tcbs() forwarded an error
-                * from dispatch_event().
-                */
-               return TE_BREAK;
-       }
-
        /*
         * The window of opportunity to handle expirations
         * of the delay timer opens here.
@@ -2253,8 +2245,16 @@ next_event(int *pstatus, siginfo_t *si)
         * Unblock the signal handler for the delay timer
         * iff the delay timer is already created.
         */
-       if (is_delay_timer_created())
+       if (is_delay_timer_created()) {
+               if (sigsetjmp(timer_jmp_buf, 1)) {
+                       /*
+                        * restart_delayed_tcbs() forwarded an error
+                        * from dispatch_event().
+                        */
+                       return TE_BREAK;
+               }
                sigprocmask(SIG_UNBLOCK, &timer_set, NULL);
+       }
 
        /*
         * If the delay timer has expired, then its expiration