svn commit: r283073 - head/usr.bin/time
John-Mark Gurney
jmg at FreeBSD.org
Mon May 18 19:18:43 UTC 2015
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;
}
More information about the svn-src-head
mailing list