timeout.c's parse_signal() basically does what kill.c's signame_to_num()
does, except it expects "SIG" in string signals.
Borrow the isalpha() check from kill.c to get the same behaviour:
$ time ./obj/timeout -s kill 1 sleep 3
Killed
0m01.01s real 0m00.00s user 0m00.01s system
$ time timeout -s kill 1 sleep 3
timeout: signal kill invalid
0m00.00s real 0m00.00s user 0m00.00s system
Feedback? OK?
Index: timeout.c
===================================================================
RCS file: /cvs/src/usr.bin/timeout/timeout.c,v
retrieving revision 1.20
diff -u -p -r1.20 timeout.c
--- timeout.c 12 Jan 2022 22:51:44 -0000 1.20
+++ timeout.c 2 Jul 2022 07:13:45 -0000
@@ -32,6 +32,7 @@
#include <sys/time.h>
#include <sys/wait.h>
+#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <getopt.h>
@@ -104,10 +105,11 @@ parse_signal(const char *str)
long long sig;
const char *errstr;
- if (strncasecmp(str, "SIG", 3) == 0) {
+ if (isalpha((unsigned char)*str)) {
int i;
- str += 3;
+ if (strncasecmp(str, "SIG", 3) == 0)
+ str += 3;
for (i = 1; i < NSIG; i++) {
if (strcasecmp(str, sys_signame[i]) == 0)
return (i);