summaryrefslogtreecommitdiffstats
path: root/usr.bin/time
diff options
context:
space:
mode:
authorcracauer <cracauer@FreeBSD.org>1998-08-24 10:17:20 +0000
committercracauer <cracauer@FreeBSD.org>1998-08-24 10:17:20 +0000
commitf3d290b0b53aa55bf027aba6c54dd0e5b1d101f3 (patch)
treef26bf7d06a6acaf0ba2829e55a588da97f3ea4a7 /usr.bin/time
parent5112766b07ec301856c63e772236ab606ccb7942 (diff)
downloadFreeBSD-src-f3d290b0b53aa55bf027aba6c54dd0e5b1d101f3.zip
FreeBSD-src-f3d290b0b53aa55bf027aba6c54dd0e5b1d101f3.tar.gz
When exiting on SIGINT, exit with signal status
Diffstat (limited to 'usr.bin/time')
-rw-r--r--usr.bin/time/time.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/usr.bin/time/time.c b/usr.bin/time/time.c
index 707ba10..f74b6db 100644
--- a/usr.bin/time/time.c
+++ b/usr.bin/time/time.c
@@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)time.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
- "$Id: time.c,v 1.9 1998/07/27 16:54:05 des Exp $";
+ "$Id: time.c,v 1.10 1998/07/28 10:08:16 des Exp $";
#endif /* not lint */
#include <sys/types.h>
@@ -57,6 +57,7 @@ static const char rcsid[] =
#include <stdio.h>
#include <string.h>
#include <unistd.h>
+#include <signal.h>
static int getstathz __P((void));
static void usage __P((void));
@@ -75,6 +76,7 @@ main(argc, argv)
struct rusage ru;
FILE *out = stderr;
char *ofn = NULL;
+ int exitonsig = 0; /* Die with same signal as child */
aflag = lflag = 0;
while ((ch = getopt(argc, argv, "alo:")) != -1)
@@ -119,8 +121,10 @@ main(argc, argv)
(void)signal(SIGQUIT, SIG_IGN);
while (wait3(&status, 0, &ru) != pid); /* XXX use waitpid */
gettimeofday(&after, (struct timezone *)NULL);
- if (status&0377)
+ if ( ! WIFEXITED(status))
warnx("command terminated abnormally");
+ if (WIFSIGNALED(status))
+ exitonsig = WTERMSIG(status);
after.tv_sec -= before.tv_sec;
after.tv_usec -= before.tv_usec;
if (after.tv_usec < 0)
@@ -173,6 +177,12 @@ main(argc, argv)
fprintf(out, "%10ld %s\n",
ru.ru_nivcsw, "involuntary context switches");
}
+ if (exitonsig) {
+ if (signal(exitonsig, SIG_DFL) < 0)
+ perror("signal");
+ else
+ kill(getpid(), exitonsig);
+ }
exit (WIFEXITED(status) ? WEXITSTATUS(status) : EXIT_FAILURE);
}
OpenPOWER on IntegriCloud