commit: 72667749cf505fb425d17338ab550059ae47f957
parent 941c815f0ad8aef6b7e3cce18209abd42c39dc4c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 20 Sep 2024 04:40:58 +0200
cmd/timeout: unify error message formatting
Diffstat:
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/cmd/timeout.c b/cmd/timeout.c
@@ -69,7 +69,7 @@ main(int argc, char *argv[])
if(time_kill.tv_sec == 0 && time_kill.tv_nsec == 0)
{
- fprintf(stderr, "timeout: Got a duration of 0 for SIGKILL timeout.\n");
+ fprintf(stderr, "timeout: error: Got a duration of 0 for SIGKILL timeout.\n");
return CMD_EXIT_FAILURE;
}
break;
@@ -85,9 +85,10 @@ main(int argc, char *argv[])
unsigned long optoul = strtoul(optarg, &endptr, 10);
if(!(errno == 0 && endptr != NULL && *endptr == '\0'))
{
- fprintf(stderr,
- "timeout: Mix of digit and non-digit characters passed to -s option '%s'\n",
- endptr);
+ fprintf(
+ stderr,
+ "timeout: error: Mix of digit and non-digit characters passed to -s option '%s'\n",
+ endptr);
return 1;
}
if(errno == 0 && optoul == 0) errno = EINVAL;
@@ -95,7 +96,7 @@ main(int argc, char *argv[])
if(errno != 0)
{
fprintf(stderr,
- "timeout: Invalid number passed to -s '%s' (got: %lu): %s\n",
+ "timeout: error: Invalid number passed to -s '%s' (got: %lu): %s\n",
optarg,
optoul,
strerror(errno));
@@ -104,7 +105,7 @@ main(int argc, char *argv[])
if(util_sys_signame[optoul] == NULL)
{
- fprintf(stderr, "timeout: Unknown signal number %lu\n", optoul);
+ fprintf(stderr, "timeout: error: Unknown signal number %lu\n", optoul);
return 1;
}
@@ -128,17 +129,17 @@ main(int argc, char *argv[])
}
if(i >= util_sys_signame_len)
{
- fprintf(stderr, "timeout: Unknown signal name '%s'\n", optarg);
+ fprintf(stderr, "timeout: error: Unknown signal name '%s'\n", optarg);
return CMD_EXIT_FAILURE;
}
}
break;
case ':':
- fprintf(stderr, "timeout: Error: Missing operand for option: '-%c'\n", optopt);
+ fprintf(stderr, "timeout: error: Missing operand for option: '-%c'\n", optopt);
usage();
return 1;
case '?':
- fprintf(stderr, "timeout: Error: Unrecognised option: '-%c'\n", optopt);
+ fprintf(stderr, "timeout: error: Unrecognised option: '-%c'\n", optopt);
usage();
return 1;
}
@@ -154,7 +155,7 @@ main(int argc, char *argv[])
if(term.tv_sec == 0 && term.tv_nsec == 0)
{
- fprintf(stderr, "timeout: Got a duration of 0 for (%s) timeout.\n", term_signame);
+ fprintf(stderr, "timeout: error: Got a duration of 0 for (%s) timeout.\n", term_signame);
return CMD_EXIT_FAILURE;
}
@@ -164,13 +165,14 @@ main(int argc, char *argv[])
assert(errno == 0);
if(signal(SIGCHLD, handle_sigchld) == SIG_ERR)
{
- fprintf(stderr, "timeout: Failed registering handler for SIGCHLD: %s\n", strerror(errno));
+ fprintf(
+ stderr, "timeout: error: Failed registering handler for SIGCHLD: %s\n", strerror(errno));
return CMD_EXIT_FAILURE;
}
if(posix_spawnp(&child, argv[0], NULL, NULL, argv, environ) != 0)
{
- fprintf(stderr, "timeout: Failed launching command '%s': %s\n", argv[0], strerror(errno));
+ fprintf(stderr, "timeout: error: Failed executing '%s': %s\n", argv[0], strerror(errno));
return CMD_EXIT_E_EXEC;
}
@@ -181,7 +183,7 @@ main(int argc, char *argv[])
{
if(errno != EINTR)
{
- fprintf(stderr, "timeout: Error sleeping: %s\n", strerror(errno));
+ fprintf(stderr, "timeout: error: Failed sleeping: %s\n", strerror(errno));
return CMD_EXIT_FAILURE;
}
}
@@ -195,7 +197,7 @@ main(int argc, char *argv[])
if(kill(child, term_sig) != 0)
{
fprintf(stderr,
- "timeout: Failed sending %s to child %d after timeout: %s\n",
+ "timeout: error: Failed sending %s to child %d after timeout: %s\n",
term_signame,
child,
strerror(errno));
@@ -211,7 +213,7 @@ main(int argc, char *argv[])
{
if(errno != EINTR)
{
- fprintf(stderr, "timeout: Error sleeping: %s\n", strerror(errno));
+ fprintf(stderr, "timeout: error: Failed sleeping: %s\n", strerror(errno));
return CMD_EXIT_FAILURE;
}
}
@@ -220,7 +222,7 @@ main(int argc, char *argv[])
if(kill(child, SIGKILL) != 0)
{
fprintf(stderr,
- "timeout: Failed sending SIGKILL to child %d after timeout: %s\n",
+ "timeout: error: Failed sending SIGKILL to child %d after timeout: %s\n",
child,
strerror(errno));
return CMD_EXIT_FAILURE;