mirror of
https://git.FreeBSD.org/src.git
synced 2024-11-29 08:08:37 +00:00
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...
This commit is contained in:
parent
2b6bbe110f
commit
e48a49b333
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=283073
@ -65,6 +65,7 @@ static void showtime(FILE *, struct timeval *, struct timeval *,
|
||||
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 *before, struct timeval *after,
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user