initctl: fix runlevel and start/stop/restart segfault regression

Introduced in e2f6ac0.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-03-02 20:31:34 +01:00
parent 63033d7dcf
commit 5da0a460fe
+11 -2
View File
@@ -143,10 +143,9 @@ static int do_runlevel(char *arg)
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = INIT_CMD_RUNLVL,
.runlevel = (int)arg[0],
};
if (!rq.runlevel) {
if (!arg) {
int prevlevel = 0;
int runlevel;
char prev;
@@ -165,6 +164,9 @@ static int do_runlevel(char *arg)
return 0;
}
/* set runlevel */
rq.runlevel = (int)arg[0];
return client_send(&rq, sizeof(rq));
}
@@ -195,6 +197,13 @@ static int do_startstop(int cmd, char *arg)
.cmd = INIT_CMD_SVC_QUERY
};
if (!arg || !arg[0])
errx(1, "missing argument to %s", (cmd == INIT_CMD_START_SVC
? "start"
: (cmd == INIT_CMD_STOP_SVC
? "stop"
: "restart")));
strlcpy(rq.data, arg, sizeof(rq.data));
if (client_send(&rq, sizeof(rq))) {
fprintf(stderr, "No such job(s) or service(s): %s\n\n", rq.data);