]> mj.ucw.cz Git - arexx.git/commitdiff
New options: --debug-raw and --log-dir
authorMartin Mares <mj@ucw.cz>
Sat, 14 Jan 2012 09:47:29 +0000 (10:47 +0100)
committerMartin Mares <mj@ucw.cz>
Sat, 14 Jan 2012 09:47:29 +0000 (10:47 +0100)
arexxd.c

index 554d45aa7fd3d7961afcf9b47c4cc5901d53d08f..5ebf3b2764de338e085d1af742e25d166998f838 100644 (file)
--- a/arexxd.c
+++ b/arexxd.c
@@ -19,7 +19,7 @@
 #include <libusb-1.0/libusb.h>
 #include <rrd.h>
 
-#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 <options>\n\
+\n\
+Options:\n\
+-d, --debug            Debug mode (no chdir, no fork, no syslog)\n\
+-l, --log-dir=<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)