diff options
author | Mukund Sivaraman <muks@banu.com> | 2009-09-15 01:34:30 +0530 |
---|---|---|
committer | Mukund Sivaraman <muks@banu.com> | 2009-09-15 01:55:16 +0530 |
commit | 5ec5449194a8f9d977d3ab0be7a1f7e5d41cb638 (patch) | |
tree | 066360df64a08d47eb9722440e2ba91775ba4fff | |
parent | f25b0e287237584425bc973b5f9e843d785120d7 (diff) | |
download | tinyproxy-5ec5449194a8f9d977d3ab0be7a1f7e5d41cb638.tar.gz tinyproxy-5ec5449194a8f9d977d3ab0be7a1f7e5d41cb638.zip |
Extract cmdline parsing code into a function
-rw-r--r-- | src/main.c | 59 | ||||
-rw-r--r-- | src/main.h | 1 |
2 files changed, 38 insertions, 22 deletions
@@ -161,36 +161,32 @@ static int get_id (char *str) return atoi (str); } -int main (int argc, char **argv) +/** + * 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) { - int optch; - unsigned int godaemon = TRUE; /* boolean */ - struct passwd *thisuser = NULL; - struct group *thisgroup = NULL; - FILE *config_file; - - /* Only allow u+rw bits. This may be required for some versions - * of glibc so that mkstemp() doesn't make us vulnerable. - */ - umask (0177); - - /* Default configuration file location */ - config.config_file = DEFAULT_CONF_FILE; + int opt; - /* - * Process the various options - */ - while ((optch = getopt (argc, argv, "c:vldh")) != EOF) { - switch (optch) { + while ((opt = getopt (argc, argv, "c:vldh")) != EOF) { + switch (opt) { case 'v': display_version (); exit (EX_OK); + case 'l': display_license (); exit (EX_OK); + case 'd': - godaemon = FALSE; + config.godaemon = FALSE; break; + case 'c': config.config_file = safestrdup (optarg); if (!config.config_file) { @@ -200,12 +196,31 @@ int main (int argc, char **argv) exit (EX_SOFTWARE); } break; + case 'h': default: display_usage (); exit (EX_OK); } } +} + +int +main (int argc, char **argv) +{ + struct passwd *thisuser = NULL; + struct group *thisgroup = NULL; + FILE *config_file; + + /* Only allow u+rw bits. This may be required for some versions + * of glibc so that mkstemp() doesn't make us vulnerable. + */ + umask (0177); + + config.config_file = DEFAULT_CONF_FILE; + config.godaemon = TRUE; + + process_cmdline (argc, argv); log_message (LOG_INFO, "Initializing " PACKAGE " ..."); @@ -244,7 +259,7 @@ int main (int argc, char **argv) } config.syslog = FALSE; /* disable syslog */ } else if (config.syslog) { - if (godaemon == TRUE) + if (config.godaemon == TRUE) openlog ("tinyproxy", LOG_PID, LOG_DAEMON); else openlog ("tinyproxy", LOG_PID, LOG_USER); @@ -299,7 +314,7 @@ int main (int argc, char **argv) anonymous_insert ("Content-Type"); } - if (godaemon == TRUE) + if (config.godaemon == TRUE) makedaemon (); if (config.pidpath) { @@ -50,6 +50,7 @@ struct config_s { unsigned int syslog; /* boolean */ int port; char *stathost; + unsigned int godaemon; /* boolean */ unsigned int quit; /* boolean */ char *user; char *group; |