just making things look a bit nicer

This commit is contained in:
snit 2024-10-04 00:15:23 -05:00
parent 174ed1ed30
commit 96ce1aa0fe

View File

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