commit f4e8c21cb2dc6a468bae32a4dcf3a9e18f269527 from: Omar Polo date: Tue Jan 17 15:31:44 2023 UTC gotd: print configuration errors without -d Defer the absolute path check on argv[0] and log_init so that it becomes possible to run `gotd -n' to check the configuration file and get errors without specifying -d. Erorrs in the configuration now are actually always printed regardless of -d. While here also tweak an error message and print 'configuration OK' if -n ok stsp@ commit - 484be064c7a134692680b71ddc159693ac4b0f72 commit + f4e8c21cb2dc6a468bae32a4dcf3a9e18f269527 blob - 717b4729fac0259057de6bd02cadff694a709e40 blob + 070e37a9d1342993266222f1483916a70450a206 --- gotd/gotd.c +++ gotd/gotd.c @@ -1757,25 +1757,13 @@ main(int argc, char **argv) if (argc != 0) usage(); - - /* Require an absolute path in argv[0] for reliable re-exec. */ - if (!got_path_is_absolute(argv0)) - fatalx("bad path \"%s\": must be an absolute path", argv0); if (geteuid() && (proc_id == PROC_GOTD || proc_id == PROC_LISTEN)) fatalx("need root privileges"); - log_init(daemonize ? 0 : 1, LOG_DAEMON); - log_setverbose(verbosity); - if (parse_config(confpath, proc_id, &gotd) != 0) return 1; - gotd.argv0 = argv0; - gotd.daemonize = daemonize; - gotd.verbosity = verbosity; - gotd.confpath = confpath; - if (proc_id == PROC_GOTD && (gotd.nrepos == 0 || TAILQ_EMPTY(&gotd.repos))) fatalx("no repository defined in configuration file"); @@ -1784,20 +1772,31 @@ main(int argc, char **argv) if (pw == NULL) fatalx("user %s not found", gotd.user_name); - if (pw->pw_uid == 0) { - fatalx("cannot run %s as %s: the user running %s " - "must not be the superuser", - getprogname(), pw->pw_name, getprogname()); - } + if (pw->pw_uid == 0) + fatalx("cannot run %s as the superuser", getprogname()); if (proc_id == PROC_LISTEN && !got_path_is_absolute(gotd.unix_socket_path)) fatalx("bad unix socket path \"%s\": must be an absolute path", gotd.unix_socket_path); - if (noaction) + if (noaction) { + fprintf(stderr, "configuration OK\n"); return 0; + } + gotd.argv0 = argv0; + gotd.daemonize = daemonize; + gotd.verbosity = verbosity; + gotd.confpath = confpath; + + /* Require an absolute path in argv[0] for reliable re-exec. */ + if (!got_path_is_absolute(argv0)) + fatalx("bad path \"%s\": must be an absolute path", argv0); + + log_init(daemonize ? 0 : 1, LOG_DAEMON); + log_setverbose(verbosity); + if (proc_id == PROC_GOTD) { gotd.pid = getpid(); snprintf(title, sizeof(title), "%s", gotd_proc_names[proc_id]);