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
This commit is contained in:
Baptiste Daroussin 2014-10-28 10:33:31 +00:00
parent 4524db570f
commit 54c2e46443
2 changed files with 27 additions and 8 deletions

View File

@ -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

View File

@ -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)