#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;
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, ...)
{
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:
// 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)