diff options
author | bapt <bapt@FreeBSD.org> | 2014-10-28 10:33:31 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2014-10-28 10:33:31 +0000 |
commit | 8dd706ab6c61912ba47ee92ebac23b27fd296d85 (patch) | |
tree | f11bc173236541d49a8d0f28f4cab778dec2023d /usr.bin/timeout | |
parent | 962052e82a82836ae5d54d0398e64a77e9f30cb0 (diff) | |
download | FreeBSD-src-8dd706ab6c61912ba47ee92ebac23b27fd296d85.zip FreeBSD-src-8dd706ab6c61912ba47ee92ebac23b27fd296d85.tar.gz |
Improve compatibility with GNU timeout
According to the coreutils regression testsuite for timeout(1)
It is expect to exit with a status being:
125 in case an invalid duration or signal is passed in arguments
126 in case an invalid command is passed in arguments
127 in case the command passed in arguments does not exists.
While here document this behaviour in the man page
Diffstat (limited to 'usr.bin/timeout')
-rw-r--r-- | usr.bin/timeout/timeout.1 | 19 | ||||
-rw-r--r-- | usr.bin/timeout/timeout.c | 16 |
2 files changed, 27 insertions, 8 deletions
diff --git a/usr.bin/timeout/timeout.1 b/usr.bin/timeout/timeout.1 index 028fc62..70a9106 100644 --- a/usr.bin/timeout/timeout.1 +++ b/usr.bin/timeout/timeout.1 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd July 19, 2014 +.Dd Oct 28, 2014 .Dt TIMEOUT 1 .Os .Sh NAME @@ -108,7 +108,22 @@ is not set, an exit status of 124 is returned. .Pp If .Ar command -exits after receiving a signal, the exit status returned is the signal number plus 128. +exits after receiving a signal, the exit status returned is the signal number +plus 128. +.Pp +If +.Ar command +is an invalid command, the exit status returned is 126. +.Pp +If +.Ar command +is a non existing command, the exit status returned is 127. +.Pp +If an invalid parameter is passed to +.Fl s +or +.Fl k , +the exit status return is 125. .Sh SEE ALSO .Xr kill 1 , .Xr signal 3 diff --git a/usr.bin/timeout/timeout.c b/usr.bin/timeout/timeout.c index 8171600..214ab13 100644 --- a/usr.bin/timeout/timeout.c +++ b/usr.bin/timeout/timeout.c @@ -68,7 +68,7 @@ parse_duration(const char *duration) ret = strtod(duration, &end); if (ret == 0 && end == duration) - errx(EXIT_FAILURE, "invalid duration"); + errx(125, "invalid duration"); if (end == NULL || *end == '\0') return (ret); @@ -89,11 +89,11 @@ parse_duration(const char *duration) ret *= 60 * 60 * 24; break; default: - errx(EX_USAGE, "invalid duration"); + errx(125, "invalid duration"); } if (ret < 0 || ret >= 100000000UL) - errx(EX_USAGE, "invalid duration"); + errx(125, "invalid duration"); return (ret); } @@ -116,7 +116,7 @@ parse_signal(const char *str) return (i); } - errx(EX_USAGE, "invalid signal"); + errx(125, "invalid signal"); } static void @@ -260,8 +260,12 @@ main(int argc, char **argv) signal(SIGTTOU, SIG_DFL); error = execvp(argv[0], argv); - if (error == -1) - err(EX_UNAVAILABLE, "exec()"); + if (error == -1) { + if (errno == ENOENT) + err(127, "exec(%s)", argv[0]); + else + err(126, "exec(%s)", argv[0]); + } } if (sigprocmask(SIG_BLOCK, &signals.sa_mask, NULL) == -1) |