From bcce6ddf6bce31a3347528c69211805e787f1635 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 14 Jan 2012 10:47:29 +0100 Subject: [PATCH] New options: --debug-raw and --log-dir --- arexxd.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/arexxd.c b/arexxd.c index 554d45a..5ebf3b2 100644 --- a/arexxd.c +++ b/arexxd.c @@ -19,7 +19,7 @@ #include #include -#define LOG_PATH "/var/log/arexxd" +#define DEFAULT_LOG_DIR "/var/log/arexxd" typedef unsigned char byte; static libusb_context *usb_ctxt; @@ -29,6 +29,7 @@ static int use_syslog; static int debug_mode; static int debug_packets; static int debug_raw_data; +static char *log_dir = DEFAULT_LOG_DIR; static void die(char *fmt, ...) { @@ -482,26 +483,41 @@ static void sigterm_handler(int sig __attribute__((unused))) static const struct option long_options[] = { { "debug", 0, NULL, 'd' }, - { "log-packets", 0, NULL, 'p' }, + { "log-dir", 1, NULL, 'l' }, + { "debug-packets", 0, NULL, 'p' }, + { "debug-raw", 0, NULL, 'r' }, { NULL, 0, NULL, 0 }, }; static void usage(void) { - fprintf(stderr, "Usage: arexxd [--debug] [--log-packets]\n"); + fprintf(stderr, "\n\ +Usage: arexxd \n\ +\n\ +Options:\n\ +-d, --debug Debug mode (no chdir, no fork, no syslog)\n\ +-l, --log-dir= Directory where all received data should be stored\n\ +-p, --debug-packets Log all packets sent and received\n\ +-r, --debug-raw Log conversion from raw values\n\ +"); exit(1); } int main(int argc, char **argv) { int opt; - while ((opt = getopt_long(argc, argv, "dp", long_options, NULL)) >= 0) + while ((opt = getopt_long(argc, argv, "dl:pr", long_options, NULL)) >= 0) switch (opt) { case 'd': debug_mode++; break; + case 'l': + log_dir = optarg; + break; case 'p': debug_packets++; + break; + case 'r': debug_raw_data++; break; default: @@ -516,8 +532,8 @@ int main(int argc, char **argv) // libusb_set_debug(usb_ctxt, 3); if (!debug_mode) { - if (chdir(LOG_PATH) < 0) - die("Cannot change directory to %s: %m", LOG_PATH); + if (chdir(log_dir) < 0) + die("Cannot change directory to %s: %m", log_dir); if (debug_packets || debug_raw_data) { close(1); if (open("debug", O_WRONLY | O_CREAT | O_APPEND, 0666) < 0) -- 2.39.5