mirror of
https://github.com/troglobit/finit.git
synced 2026-11-03 13:28:27 +00:00
initctl: simplify error output of start/stop/restart/signal
No need for the verbose output on error, simply state the cause of the problem. The user can issue `initctl -h` to check the syntax of the command. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
f8bed5c7af
commit
fb8a7caa99
1 file changed
+10
-31
+10
-31
@@ -245,20 +245,11 @@ static int do_startstop(int cmd, char *arg)
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!arg || !arg[0])
|
if (!arg || !arg[0])
|
||||||
errx(1, "missing argument to %s", (cmd == INIT_CMD_START_SVC
|
errx(1, "missing command argument");
|
||||||
? "start"
|
|
||||||
: (cmd == INIT_CMD_STOP_SVC
|
|
||||||
? "stop"
|
|
||||||
: "restart")));
|
|
||||||
|
|
||||||
strlcpy(rq.data, arg, sizeof(rq.data));
|
strlcpy(rq.data, arg, sizeof(rq.data));
|
||||||
if (client_send(&rq, sizeof(rq))) {
|
if (client_send(&rq, sizeof(rq)))
|
||||||
fprintf(stderr, "No such task or service(s): %s\n\n", arg);
|
errx(1, "No such task or service(s): %s", arg);
|
||||||
fprintf(stderr, "Usage: initctl %s <NAME>[:ID]\n",
|
|
||||||
cmd == INIT_CMD_START_SVC ? "start" :
|
|
||||||
(cmd == INIT_CMD_STOP_SVC ? "stop" : "restart"));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return do_svc(cmd, arg);
|
return do_svc(cmd, arg);
|
||||||
}
|
}
|
||||||
@@ -290,7 +281,7 @@ static int do_restart(char *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (retries == 0)
|
if (retries == 0)
|
||||||
errx(1, "Failed stopping %s (restart)", arg);
|
errx(1, "failed stopping %s (restart)", arg);
|
||||||
|
|
||||||
return do_startstop(INIT_CMD_RESTART_SVC, arg);
|
return do_startstop(INIT_CMD_RESTART_SVC, arg);
|
||||||
}
|
}
|
||||||
@@ -316,25 +307,17 @@ int do_signal(int argc, char *argv[])
|
|||||||
if (argc != 2)
|
if (argc != 2)
|
||||||
errx(1, "invalid number of arguments to signal");
|
errx(1, "invalid number of arguments to signal");
|
||||||
|
|
||||||
/* Validate service name */
|
|
||||||
strlcpy(rq.data, argv[0], sizeof(rq.data));
|
strlcpy(rq.data, argv[0], sizeof(rq.data));
|
||||||
if (client_send(&rq, sizeof(rq))) {
|
if (client_send(&rq, sizeof(rq)))
|
||||||
fprintf(stderr, "No such task or service(s): %s\n\n", argv[0]);
|
errx(1, "no such task or service(s): %s", argv[0]);
|
||||||
goto show_usage;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Validate signal name (or number) */
|
|
||||||
signo = str2sig(argv[1]);
|
signo = str2sig(argv[1]);
|
||||||
if (signo == -1) {
|
if (signo == -1) {
|
||||||
/* Not a signal name, is it an actual signal number? */
|
const char *errstr = NULL;
|
||||||
errno = 0;
|
|
||||||
signo = (int)strtol(argv[1], NULL, 10);
|
|
||||||
|
|
||||||
/* Was it a number? Was it a signo that finit recognizes? */
|
signo = (int)strtonum(argv[1], 1, 31, &errstr);
|
||||||
if (errno || !*(sig2str(signo))) {
|
if (errstr)
|
||||||
fprintf(stderr, "Not a valid signal (or signo): %s\n", argv[1]);
|
errx(1, "%s signal: %s", errstr, argv[1]);
|
||||||
goto show_usage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reuse runlevel for signal number. */
|
/* Reuse runlevel for signal number. */
|
||||||
@@ -344,10 +327,6 @@ int do_signal(int argc, char *argv[])
|
|||||||
strlcpy(rq.data, argv[0], sizeof(rq.data));
|
strlcpy(rq.data, argv[0], sizeof(rq.data));
|
||||||
|
|
||||||
return client_send(&rq, sizeof(rq));
|
return client_send(&rq, sizeof(rq));
|
||||||
|
|
||||||
show_usage:
|
|
||||||
fprintf(stderr, "Usage: initctl signal <NAME>[:ID] <S>\n");
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
|
static int dump_one_cond(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf)
|
||||||
|
|||||||
Reference in new issue
Block a user