diff --git a/server/src/main.c b/server/src/main.c index ced09dc..8f35a68 100644 --- a/server/src/main.c +++ b/server/src/main.c @@ -15,26 +15,23 @@ struct options_t { bool daemonise; }; -enum error_t parse_arguments(struct options_t *options, int argc, char **argv) { - static struct option long_options[] = { +static enum error_t parse_arguments( + struct options_t *options, + int argc, char **argv +) { + static struct option const long_options[] = { { "daemon", no_argument, 0, 'd' }, - { 0, 0, 0, 0 }, }; while (true) { int option_index = 0; int c = getopt_long(argc, argv, "d", long_options, &option_index); - if (c == -1) break; switch (c) { - case 'd': - options->daemonise = true; - break; - - default: - return ERR_INPUT; + case 'd': options->daemonise = true; break; + default: return ERR_INPUT; } } @@ -56,11 +53,13 @@ int main(int argc, char **argv) { syslog(LOG_NOTICE, "Daemon initialised"); } - - if (options.daemonise) closelog(); - return EXIT_SUCCESS; + goto handle_exit; + // Is this the best way to do this? I didn't want to duplicate + // closing the syslog handle_error: printf("ERROR: %s\n", ERROR_STRS[err]); +handle_exit: + if (options.daemonise) closelog(); return err; }