[hackers] [sbase] time: show which signal terminated the program, exit status || Hiltjo Posthuma
commit 6becc0d4935d31f2324fdaaaf1c1f1369b0e9a5b
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
Date: Sun Mar 8 12:49:24 2015 +0100
time: show which signal terminated the program, exit status
The exit status when a program is signaled is not specified in POSIX afaik.
The GNU behaviour of 128 + signalno is used.
diff --git a/time.c b/time.c
index fc17bf0..0b8e607 100644
--- a/time.c
+++ b/time.c
_AT_@ -21,7 +21,7 @@ main(int argc, char *argv[])
struct tms tms; /* user and sys times */
clock_t r0, r1; /* real time */
long ticks; /* per second */
- int status, savederrno;
+ int status, savederrno, ret = 0;
ARGBEGIN {
case 'p':
_AT_@ -55,10 +55,19 @@ main(int argc, char *argv[])
if ((r1 = times(&tms)) < 0)
eprintf("times:");
+ if (WIFSIGNALED(status)) {
+ fprintf(stderr, "Command terminated by signal %d\n",
+ WTERMSIG(status));
+ ret = 128 + WTERMSIG(status);
+ }
+
fprintf(stderr, "real %f\nuser %f\nsys %f\n",
(r1 - r0) / (double)ticks,
tms.tms_cutime / (double)ticks,
tms.tms_cstime / (double)ticks);
- return WIFEXITED(status) ? WEXITSTATUS(status) : 0;
+ if (WIFEXITED(status))
+ ret = WEXITSTATUS(status);
+
+ return ret;
}
Received on Sun Mar 08 2015 - 15:27:16 CET
This archive was generated by hypermail 2.3.0
: Sun Mar 08 2015 - 15:36:11 CET