commit 6576093aa0f0a23c584d95c79c03c4ea9a390aaa from: Omar Polo date: Mon Jul 11 16:54:07 2022 UTC initialize status_format early in the main() otherwise we may leave it NULL (it's set only in ctl_status) and crash in print_status. commit - 127f376a4797636687374f562e7a65cae3586040 commit + 6576093aa0f0a23c584d95c79c03c4ea9a390aaa blob - f291251e0884125eb6c5005512407a7e5dfb58df blob + dd7b94f7ce9191b416561e685a269a2fd1c3ccad --- ctl.c +++ ctl.c @@ -130,15 +130,12 @@ canonpath(const char *input, char *buf, size_t bufsize } static int -parse(int argc, char **argv) +parse(struct parse_result *res, int argc, char **argv) { struct ctl_command *ctl = NULL; - struct parse_result res; const char *argv0; int i, status; - memset(&res, 0, sizeof(res)); - if ((argv0 = argv[0]) == NULL) argv0 = "status"; @@ -159,8 +156,8 @@ parse(int argc, char **argv) usage(); } - res.action = ctl->action; - res.ctl = ctl; + res->action = ctl->action; + res->ctl = ctl; if (!ctl->has_pledge) { /* pledge(2) default if command doesn't have its own */ @@ -168,7 +165,7 @@ parse(int argc, char **argv) fatal("pledge"); } - status = ctl->main(&res, argc, argv); + status = ctl->main(res, argc, argv); close(ibuf->fd); free(ibuf); return status; @@ -827,13 +824,12 @@ done: static int ctl_status(struct parse_result *res, int argc, char **argv) { - const char *fmt = NULL; int ch; while ((ch = getopt(argc, argv, "f:")) != -1) { switch (ch) { case 'f': - fmt = optarg; + res->status_format = optarg; break; default: ctl_usage(res->ctl); @@ -845,9 +841,6 @@ ctl_status(struct parse_result *res, int argc, char ** if (argc > 0) ctl_usage(res->ctl); - if (fmt == NULL && (fmt = getenv("AMUSED_STATUS_FORMAT")) == NULL) - fmt = "status,time,repeat"; - res->status_format = fmt; return ctlaction(res); } @@ -956,8 +949,15 @@ failed: __dead void ctl(int argc, char **argv) { + struct parse_result res; + const char *fmt; int ctl_sock; + memset(&res, 0, sizeof(res)); + if ((fmt = getenv("AMUSED_STATUS_FORMAT")) == NULL) + fmt = "status,time,repeat"; + res.status_format = fmt; + log_init(1, LOG_DAEMON); log_setverbose(verbose); @@ -976,5 +976,5 @@ ctl(int argc, char **argv) optreset = 1; optind = 1; - exit(parse(argc, argv)); + exit(parse(&res, argc, argv)); }