From: Martin Mares Date: Sat, 14 Jan 2012 09:47:29 +0000 (+0100) Subject: New options: --debug-raw and --log-dir X-Git-Tag: v1.2~15 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=bcce6ddf6bce31a3347528c69211805e787f1635;p=arexx.git New options: --debug-raw and --log-dir --- 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)