Date: Mon, 18 May 2015 19:18:43 +0000 (UTC) From: John-Mark Gurney <jmg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r283073 - head/usr.bin/time Message-ID: <201505181918.t4IJIhlx077733@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jmg Date: Mon May 18 19:18:42 2015 New Revision: 283073 URL: https://svnweb.freebsd.org/changeset/base/283073 Log: Don't do things we aren't allowed to do in a signal handler... Defer the work to the main thread... This fixes a possible crash if SIGINFO is delivered at the wrong time... This still leaves getrusage broken for some reason, but I believe that is a kernel issue and cannot be fixed here... Modified: head/usr.bin/time/time.c Modified: head/usr.bin/time/time.c ============================================================================== --- head/usr.bin/time/time.c Mon May 18 18:25:38 2015 (r283072) +++ head/usr.bin/time/time.c Mon May 18 19:18:42 2015 (r283073) @@ -65,6 +65,7 @@ static void showtime(FILE *, struct time static void siginfo(int); static void usage(void); +static sig_atomic_t siginfo_recvd; static char decimal_point; static struct timeval before_tv; static int hflag, pflag; @@ -130,8 +131,17 @@ main(int argc, char **argv) /* parent */ (void)signal(SIGINT, SIG_IGN); (void)signal(SIGQUIT, SIG_IGN); + siginfo_recvd = 0; (void)signal(SIGINFO, siginfo); - while (wait4(pid, &status, 0, &ru) != pid); + (void)siginterrupt(SIGINFO, 1); + while (wait4(pid, &status, 0, &ru) != pid) { + if (siginfo_recvd) { + siginfo_recvd = 0; + (void)gettimeofday(&after, NULL); + getrusage(RUSAGE_CHILDREN, &ru); + showtime(stdout, &before_tv, &after, &ru); + } + } (void)gettimeofday(&after, NULL); if ( ! WIFEXITED(status)) warnx("command terminated abnormally"); @@ -292,10 +302,6 @@ showtime(FILE *out, struct timeval *befo static void siginfo(int sig __unused) { - struct timeval after; - struct rusage ru; - (void)gettimeofday(&after, NULL); - getrusage(RUSAGE_CHILDREN, &ru); - showtime(stdout, &before_tv, &after, &ru); + siginfo_recvd = 1; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201505181918.t4IJIhlx077733>