diff --git a/doc/CONFIGURATION.md b/doc/CONFIGURATION.md index c461689..0ec994e 100644 --- a/doc/CONFIGURATION.md +++ b/doc/CONFIGURATION.md @@ -20,6 +20,9 @@ when installing aprsc from a binary package. and debugging, or "syslog" for syslogd) * `-r logs` - log file directory, log files are placed in /opt/aprsc/logs * `-c etc/aprsc.conf` - configuration file location + * `-y` - try to parse the configuration, report success or error, + quit after reading configuration. Useful for validating your + configuration before restarting aprsc. Since the daemon does a [chroot][chroot] to /opt/aprsc, all paths are relative to that directory and the daemon cannot access any files outside diff --git a/src/aprsc.c b/src/aprsc.c index d2cdf65..c0b4f3d 100644 --- a/src/aprsc.c +++ b/src/aprsc.c @@ -9,7 +9,8 @@ */ #define HELPS "Usage: aprsc [-t ] [-u ] [-c ] [-f (fork)]\n" \ - " [-n ] [-e ] [-o ] [-r ] [-h (help)]\n" + " [-n ] [-e ] [-o ] [-r ]\n" \ + " [-y (try config)] [-h (help)]\n" #include #include @@ -60,6 +61,7 @@ int reopen_logs; // should we reopen log files now? int reconfiguring; // should we reconfigure now? int fileno_limit = -1; int dbdump_at_exit; +int quit_after_config; int want_dbdump; /* random instance ID, alphanumeric low-case */ @@ -77,7 +79,7 @@ void parse_cmdline(int argc, char *argv[]) int s, i; int failed = 0; - while ((s = getopt(argc, argv, "c:ft:u:n:r:d:De:o:?h")) != -1) { + while ((s = getopt(argc, argv, "c:ft:u:n:r:d:Dye:o:?h")) != -1) { switch (s) { case 'c': cfgfile = hstrdup(optarg); @@ -110,6 +112,9 @@ void parse_cmdline(int argc, char *argv[]) case 'D': dbdump_at_exit = 1; break; + case 'y': + quit_after_config = 1; + break; case 'e': i = pick_loglevel(optarg, log_levelnames); if (i > -1) @@ -144,6 +149,10 @@ void parse_cmdline(int argc, char *argv[]) fputs(HELPS, stderr); exit(failed); } + + if (quit_after_config) { + fork_a_daemon = 0; + } } /* @@ -784,7 +793,8 @@ int main(int argc, char **argv) /* open syslog, write an initial log message and read configuration */ open_log(logname, 0); - hlog(LOG_NOTICE, "Starting up version %s, instance id %s ...", version_build, instance_id); + if (!quit_after_config) + hlog(LOG_NOTICE, "Starting up version %s, instance id %s ...", version_build, instance_id); int orig_log_dest = log_dest; log_dest |= L_STDERR; @@ -794,6 +804,9 @@ int main(int argc, char **argv) exit(1); } + if (quit_after_config) + exit(0); + /* adjust file limits as requested, not after every reconfigure * but only at startup - we won't have root privileges available * later.