summaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c51
1 files changed, 35 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index a276e90..f3c58b7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,9 +1,9 @@
1/* 1/*
2 * main.c 2 * main.c
3 * 3 *
4 * Copyright (C) 2009-2019 Nikias Bassen <nikias@gmx.li>
4 * Copyright (C) 2013-2014 Martin Szulecki <m.szulecki@libimobiledevice.org> 5 * Copyright (C) 2013-2014 Martin Szulecki <m.szulecki@libimobiledevice.org>
5 * Copyright (C) 2009 Hector Martin <hector@marcansoft.com> 6 * Copyright (C) 2009 Hector Martin <hector@marcansoft.com>
6 * Copyright (C) 2009 Nikias Bassen <nikias@gmx.li>
7 * Copyright (C) 2009 Paul Sladen <libiphone@paul.sladen.org> 7 * Copyright (C) 2009 Paul Sladen <libiphone@paul.sladen.org>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
@@ -54,6 +54,7 @@ static const char *lockfile = "/var/run/usbmuxd.pid";
54 54
55int should_exit; 55int should_exit;
56int should_discover; 56int should_discover;
57int use_logfile = 0;
57 58
58static int verbose = 0; 59static int verbose = 0;
59static int foreground = 0; 60static int foreground = 0;
@@ -376,6 +377,7 @@ static void usage()
376 printf(" \t\tconnected (sends SIGUSR1 to running instance) and exit.\n"); 377 printf(" \t\tconnected (sends SIGUSR1 to running instance) and exit.\n");
377 printf(" -X, --force-exit\tNotify a running instance to exit even if there are still\n"); 378 printf(" -X, --force-exit\tNotify a running instance to exit even if there are still\n");
378 printf(" \tdevices connected (always works) and exit.\n"); 379 printf(" \tdevices connected (always works) and exit.\n");
380 printf(" -l, --logfile=LOGFILE\tLog (append) to LOGFILE instead of stderr or syslog.\n");
379 printf(" -V, --version\t\tPrint version information and exit.\n"); 381 printf(" -V, --version\t\tPrint version information and exit.\n");
380 printf("\n"); 382 printf("\n");
381} 383}
@@ -383,31 +385,32 @@ static void usage()
383static void parse_opts(int argc, char **argv) 385static void parse_opts(int argc, char **argv)
384{ 386{
385 static struct option longopts[] = { 387 static struct option longopts[] = {
386 {"help", 0, NULL, 'h'}, 388 {"help", no_argument, NULL, 'h'},
387 {"foreground", 0, NULL, 'f'}, 389 {"foreground", no_argument, NULL, 'f'},
388 {"verbose", 0, NULL, 'v'}, 390 {"verbose", no_argument, NULL, 'v'},
389 {"user", 1, NULL, 'U'}, 391 {"user", required_argument, NULL, 'U'},
390 {"disable-hotplug", 0, NULL, 'n'}, 392 {"disable-hotplug", no_argument, NULL, 'n'},
391 {"enable-exit", 0, NULL, 'z'}, 393 {"enable-exit", no_argument, NULL, 'z'},
392#ifdef HAVE_UDEV 394#ifdef HAVE_UDEV
393 {"udev", 0, NULL, 'u'}, 395 {"udev", no_argument, NULL, 'u'},
394#endif 396#endif
395#ifdef HAVE_SYSTEMD 397#ifdef HAVE_SYSTEMD
396 {"systemd", 0, NULL, 's'}, 398 {"systemd", no_argument, NULL, 's'},
397#endif 399#endif
398 {"exit", 0, NULL, 'x'}, 400 {"exit", no_argument, NULL, 'x'},
399 {"force-exit", 0, NULL, 'X'}, 401 {"force-exit", no_argument, NULL, 'X'},
400 {"version", 0, NULL, 'V'}, 402 {"logfile", required_argument, NULL, 'l'},
403 {"version", no_argument, NULL, 'V'},
401 {NULL, 0, NULL, 0} 404 {NULL, 0, NULL, 0}
402 }; 405 };
403 int c; 406 int c;
404 407
405#ifdef HAVE_SYSTEMD 408#ifdef HAVE_SYSTEMD
406 const char* opts_spec = "hfvVuU:xXsnz"; 409 const char* opts_spec = "hfvVuU:xXsnzl:";
407#elif HAVE_UDEV 410#elif HAVE_UDEV
408 const char* opts_spec = "hfvVuU:xXnz"; 411 const char* opts_spec = "hfvVuU:xXnzl:";
409#else 412#else
410 const char* opts_spec = "hfvVU:xXnz"; 413 const char* opts_spec = "hfvVU:xXnzl:";
411#endif 414#endif
412 415
413 while (1) { 416 while (1) {
@@ -459,6 +462,22 @@ static void parse_opts(int argc, char **argv)
459 opt_exit = 1; 462 opt_exit = 1;
460 exit_signal = SIGTERM; 463 exit_signal = SIGTERM;
461 break; 464 break;
465 case 'l':
466 if (!*optarg) {
467 usbmuxd_log(LL_FATAL, "ERROR: --logfile requires a non-empty filename");
468 usage();
469 exit(2);
470 }
471 if (use_logfile) {
472 usbmuxd_log(LL_FATAL, "ERROR: --logfile cannot be used multiple times");
473 exit(2);
474 }
475 if (!freopen(optarg, "a", stderr)) {
476 usbmuxd_log(LL_FATAL, "ERROR: fdreopen: %s", strerror(errno));
477 } else {
478 use_logfile = 1;
479 }
480 break;
462 default: 481 default:
463 usage(); 482 usage();
464 exit(2); 483 exit(2);
@@ -479,7 +498,7 @@ int main(int argc, char *argv[])
479 argc -= optind; 498 argc -= optind;
480 argv += optind; 499 argv += optind;
481 500
482 if (!foreground) { 501 if (!foreground && !use_logfile) {
483 verbose += LL_WARNING; 502 verbose += LL_WARNING;
484 log_enable_syslog(); 503 log_enable_syslog();
485 } else { 504 } else {