sbase

suckless unix tools
git clone git://git.2f30.org/sbase
Log | Files | Refs | README | LICENSE

commit 603499b6740839c2b3b6123f784a1237e6451074
parent ad6776e9a1bdecf49208d4299a60cee07b083416
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  8 Mar 2015 12:49:24 +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.

Diffstat:
Mtime.c | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/time.c b/time.c @@ -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': @@ -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; }