From: Dmitry V. Levin Date: Fri, 18 Sep 2015 01:54:59 +0000 (+0000) Subject: Add is_erestart helper function X-Git-Tag: v4.11~180 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9af94a2f486064a62cce5439fd417a992e591eae;p=strace Add is_erestart helper function * defs.h (is_erestart): New prototype. * syscall.c (is_erestart): New function. * time.c (sys_nanosleep): Use is_erestart, temporarily_clear_syserror, and restore_cleared_syserror. --- diff --git a/defs.h b/defs.h index 119f9b44..b7e00806 100644 --- a/defs.h +++ b/defs.h @@ -538,6 +538,7 @@ extern void get_regs(pid_t pid); extern int get_scno(struct tcb *tcp); extern const char *syscall_name(long scno); +extern bool is_erestart(struct tcb *); extern void temporarily_clear_syserror(struct tcb *); extern void restore_cleared_syserror(struct tcb *); diff --git a/syscall.c b/syscall.c index aaa44ead..d4599e40 100644 --- a/syscall.c +++ b/syscall.c @@ -1131,6 +1131,20 @@ trace_syscall(struct tcb *tcp) trace_syscall_exiting(tcp) : trace_syscall_entering(tcp); } +bool +is_erestart(struct tcb *tcp) +{ + switch (tcp->u_error) { + case ERESTARTSYS: + case ERESTARTNOINTR: + case ERESTARTNOHAND: + case ERESTART_RESTARTBLOCK: + return true; + default: + return false; + } +} + static int saved_u_error; void diff --git a/time.c b/time.c index e37f26e0..47023c59 100644 --- a/time.c +++ b/time.c @@ -203,22 +203,19 @@ SYS_FUNC(nanosleep) print_timespec(tcp, tcp->u_arg[0]); tprints(", "); } else { - /* Second (returned) timespec is only significant - * if syscall was interrupted. On success, we print - * only its address, since kernel doesn't modify it, + + /* + * Second (returned) timespec is only significant if syscall + * was interrupted. On success and in case of other errors we + * print only its address, since kernel doesn't modify it, * and printing the value may show uninitialized data. */ - switch (tcp->u_error) { - default: - /* Not interrupted (slept entire interval) */ - printaddr(tcp->u_arg[1]); - break; - case ERESTARTSYS: - case ERESTARTNOINTR: - case ERESTARTNOHAND: - case ERESTART_RESTARTBLOCK: - /* Interrupted */ + if (is_erestart(tcp)) { + temporarily_clear_syserror(tcp); print_timespec(tcp, tcp->u_arg[1]); + restore_cleared_syserror(tcp); + } else { + printaddr(tcp->u_arg[1]); } } return 0;