From 40afaeb63754c8495b92696a3f663a9e42b7b7ac Mon Sep 17 00:00:00 2001 From: rofl0r Date: Wed, 15 Jan 2020 14:45:23 +0000 Subject: [PATCH] move commandline parsing to main() --- src/main.c | 82 +++++++++++++++++++++++------------------------------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/src/main.c b/src/main.c index 7f6d947..aac9a5b 100644 --- a/src/main.c +++ b/src/main.c @@ -162,52 +162,6 @@ get_id (char *str) return atoi (str); } -/** - * process_cmdline: - * @argc: argc as passed to main() - * @argv: argv as passed to main() - * - * This function parses command line arguments. - **/ -static void -process_cmdline (int argc, char **argv, struct config_s *conf) -{ - int opt; - - while ((opt = getopt (argc, argv, "c:vdh")) != EOF) { - switch (opt) { - case 'v': - display_version (); - exit (EX_OK); - - case 'd': - conf->godaemon = FALSE; - break; - - case 'c': - if (conf->config_file != NULL) { - safefree (conf->config_file); - } - conf->config_file = safestrdup (optarg); - if (!conf->config_file) { - fprintf (stderr, - "%s: Could not allocate memory.\n", - argv[0]); - exit (EX_SOFTWARE); - } - break; - - case 'h': - display_usage (); - exit (EX_OK); - - default: - display_usage (); - exit (EX_USAGE); - } - } -} - /** * change_user: * @program: The name of the program. Pass argv[0] here. @@ -309,6 +263,8 @@ done: int main (int argc, char **argv) { + int opt; + srand(time(NULL)); /* for hashmap seeds */ /* Only allow u+rw bits. This may be required for some versions @@ -323,7 +279,39 @@ main (int argc, char **argv) } initialize_config_defaults (&config_defaults); - process_cmdline (argc, argv, &config_defaults); + + while ((opt = getopt (argc, argv, "c:vdh")) != EOF) { + switch (opt) { + case 'v': + display_version (); + exit (EX_OK); + + case 'd': + (&config_defaults)->godaemon = FALSE; + break; + + case 'c': + if ((&config_defaults)->config_file != NULL) { + safefree ((&config_defaults)->config_file); + } + (&config_defaults)->config_file = safestrdup (optarg); + if (!(&config_defaults)->config_file) { + fprintf (stderr, + "%s: Could not allocate memory.\n", + argv[0]); + exit (EX_SOFTWARE); + } + break; + + case 'h': + display_usage (); + exit (EX_OK); + + default: + display_usage (); + exit (EX_USAGE); + } + } if (reload_config_file (config_defaults.config_file, &config,