diff options
author | Karl Palsson <karlp@etactica.com> | 2016-09-28 16:32:39 +0000 |
---|---|---|
committer | John Crispin <john@phrozen.org> | 2016-11-21 12:13:46 +0100 |
commit | a94aff09bc3a36b7ebe6cdc90323f396fa2f78c8 (patch) | |
tree | d5f7869fba0cde9d4062ff4f33eb79174a153ce3 | |
parent | 371a80c7257d9207e242db15e257b12d4c0238b2 (diff) |
enable loglevel setting via command line
Currently the loglevel is hardcoded to LOG_WARNING, even though there is
debug log messages. Allow setting the loglevel via cli option.
Include basic help text because we're adding command line options.
Signed-off-by: Karl Palsson <karlp@etactica.com>
-rw-r--r-- | src/odhcpd.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/odhcpd.c b/src/odhcpd.c index 6f034bf..e83a700 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -54,11 +54,33 @@ static void sighandler(_unused int signal) uloop_end(); } +static void print_usage(const char *app) +{ + printf( + "== %s Usage ==\n\n" + " -h, --help Print this help\n" + " -l level Specify log level 0..7 (default %d)\n", + app, LOG_WARNING + ); +} -int main() +int main(int argc, char **argv) { openlog("odhcpd", LOG_PERROR | LOG_PID, LOG_DAEMON); - setlogmask(LOG_UPTO(LOG_WARNING)); + int opt; + int log_level = LOG_WARNING; + while ((opt = getopt(argc, argv, "hl:")) != -1) { + switch (opt) { + case 'h': + print_usage(argv[0]); + return 0; + case 'l': + log_level = atoi(optarg); + fprintf(stderr, "Log level set to %d\n", log_level); + break; + } + } + setlogmask(LOG_UPTO(log_level)); uloop_init(); if (getuid() != 0) { |