diff options
| author | 2014-10-14 18:05:31 +0200 | |
|---|---|---|
| committer | 2014-10-14 18:05:31 +0200 | |
| commit | 4a5bddef1ea5f19308eaae417d7bbc57dc3246d1 (patch) | |
| tree | 6b10408c568f93f08fa256c418959a6204fd9339 | |
| parent | 18d1419408205956cca308781202e064a3122d99 (diff) | |
| download | usbmuxd-4a5bddef1ea5f19308eaae417d7bbc57dc3246d1.tar.gz usbmuxd-4a5bddef1ea5f19308eaae417d7bbc57dc3246d1.tar.bz2 | |
Fix support for more than one device with systemd by extending usbmuxd usage
Upon connecting a new device, usbmuxd was not notified to scan for it if
systemd was used as the activation method. This change introduces the
"--disable-hotplug" and "--enable-exit" options to have a finer control
over usbmuxd's signaling behavior. The convenience option "--systemd"
complements the "--udev" option and setups the right settings for systemd.
| -rw-r--r-- | src/main.c | 56 |
1 files changed, 41 insertions, 15 deletions
| @@ -1,6 +1,7 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * main.c | 2 | * main.c |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2013-2014 Martin Szulecki <m.szulecki@libimobiledevice.org> | ||
| 4 | * Copyright (C) 2009 Hector Martin <hector@marcansoft.com> | 5 | * Copyright (C) 2009 Hector Martin <hector@marcansoft.com> |
| 5 | * Copyright (C) 2009 Nikias Bassen <nikias@gmx.li> | 6 | * Copyright (C) 2009 Nikias Bassen <nikias@gmx.li> |
| 6 | * Copyright (C) 2009 Paul Sladen <libiphone@paul.sladen.org> | 7 | * Copyright (C) 2009 Paul Sladen <libiphone@paul.sladen.org> |
| @@ -58,7 +59,8 @@ static int verbose = 0; | |||
| 58 | static int foreground = 0; | 59 | static int foreground = 0; |
| 59 | static int drop_privileges = 0; | 60 | static int drop_privileges = 0; |
| 60 | static const char *drop_user = NULL; | 61 | static const char *drop_user = NULL; |
| 61 | static int opt_udev = 0; | 62 | static int opt_disable_hotplug = 0; |
| 63 | static int opt_enable_exit = 0; | ||
| 62 | static int opt_exit = 0; | 64 | static int opt_exit = 0; |
| 63 | static int exit_signal = 0; | 65 | static int exit_signal = 0; |
| 64 | static int daemon_pipe; | 66 | static int daemon_pipe; |
| @@ -105,7 +107,7 @@ static void handle_signal(int sig) | |||
| 105 | usbmuxd_log(LL_NOTICE,"Caught signal %d, exiting", sig); | 107 | usbmuxd_log(LL_NOTICE,"Caught signal %d, exiting", sig); |
| 106 | should_exit = 1; | 108 | should_exit = 1; |
| 107 | } else { | 109 | } else { |
| 108 | if(opt_udev) { | 110 | if(opt_enable_exit) { |
| 109 | if (sig == SIGUSR1) { | 111 | if (sig == SIGUSR1) { |
| 110 | usbmuxd_log(LL_INFO, "Caught SIGUSR1, checking if we can terminate (no more devices attached)..."); | 112 | usbmuxd_log(LL_INFO, "Caught SIGUSR1, checking if we can terminate (no more devices attached)..."); |
| 111 | if (device_get_count(1) > 0) { | 113 | if (device_get_count(1) > 0) { |
| @@ -120,7 +122,7 @@ static void handle_signal(int sig) | |||
| 120 | should_discover = 1; | 122 | should_discover = 1; |
| 121 | } | 123 | } |
| 122 | } else { | 124 | } else { |
| 123 | usbmuxd_log(LL_INFO, "Caught SIGUSR1/2 but we weren't started in --udev mode, ignoring"); | 125 | usbmuxd_log(LL_INFO, "Caught SIGUSR1/2 but this instance was not started with \"--enable-exit\", ignoring."); |
| 124 | } | 126 | } |
| 125 | } | 127 | } |
| 126 | } | 128 | } |
| @@ -200,7 +202,7 @@ static int main_loop(int listenfd) | |||
| 200 | } | 202 | } |
| 201 | if(should_discover) { | 203 | if(should_discover) { |
| 202 | should_discover = 0; | 204 | should_discover = 0; |
| 203 | usbmuxd_log(LL_INFO, "Device discovery triggered by udev"); | 205 | usbmuxd_log(LL_INFO, "Device discovery triggered"); |
| 204 | usb_discover(); | 206 | usb_discover(); |
| 205 | } | 207 | } |
| 206 | } | 208 | } |
| @@ -351,11 +353,16 @@ static void usage() | |||
| 351 | printf(" -v, --verbose\t\tBe verbose (use twice or more to increase).\n"); | 353 | printf(" -v, --verbose\t\tBe verbose (use twice or more to increase).\n"); |
| 352 | printf(" -f, --foreground\tDo not daemonize (implies one -v).\n"); | 354 | printf(" -f, --foreground\tDo not daemonize (implies one -v).\n"); |
| 353 | printf(" -U, --user USER\tChange to this user after startup (needs USB privileges).\n"); | 355 | printf(" -U, --user USER\tChange to this user after startup (needs USB privileges).\n"); |
| 354 | printf(" -u, --udev\t\tRun in udev operation mode.\n"); | 356 | printf(" -n, --disable-hotplug\tDisables automatic discovery of devices on hotplug.\n"); |
| 355 | printf(" -x, --exit\t\tTell a running instance to exit if there are no devices\n"); | 357 | printf(" \tStarting another instance will trigger discovery instead.\n"); |
| 356 | printf(" \t\tconnected (must be in udev mode).\n"); | 358 | printf(" -z, --enable-exit\tEnable \"--exit\" request from other instances and exit\n"); |
| 357 | printf(" -X, --force-exit\tTell a running instance to exit, even if there are still\n"); | 359 | printf(" \tautomatically if no device is attached.\n"); |
| 358 | printf(" \tdevices connected (always works).\n"); | 360 | printf(" -u, --udev\t\tRun in udev operation mode (implies -n and -z).\n"); |
| 361 | printf(" -s, --systemd\t\tRun in systemd operation mode (implies -z and -f).\n"); | ||
| 362 | printf(" -x, --exit\t\tNotify a running instance to exit if there are no devices\n"); | ||
| 363 | printf(" \t\tconnected (sends SIGUSR1 to running instance) and exit.\n"); | ||
| 364 | printf(" -X, --force-exit\tNotify a running instance to exit even if there are still\n"); | ||
| 365 | printf(" \tdevices connected (always works) and exit.\n"); | ||
| 359 | printf(" -V, --version\t\tPrint version information and exit.\n"); | 366 | printf(" -V, --version\t\tPrint version information and exit.\n"); |
| 360 | printf("\n"); | 367 | printf("\n"); |
| 361 | } | 368 | } |
| @@ -367,7 +374,10 @@ static void parse_opts(int argc, char **argv) | |||
| 367 | {"foreground", 0, NULL, 'f'}, | 374 | {"foreground", 0, NULL, 'f'}, |
| 368 | {"verbose", 0, NULL, 'v'}, | 375 | {"verbose", 0, NULL, 'v'}, |
| 369 | {"user", 1, NULL, 'U'}, | 376 | {"user", 1, NULL, 'U'}, |
| 377 | {"disable-hotplug", 0, NULL, 'n'}, | ||
| 378 | {"enable-exit", 0, NULL, 'z'}, | ||
| 370 | {"udev", 0, NULL, 'u'}, | 379 | {"udev", 0, NULL, 'u'}, |
| 380 | {"systemd", 0, NULL, 's'}, | ||
| 371 | {"exit", 0, NULL, 'x'}, | 381 | {"exit", 0, NULL, 'x'}, |
| 372 | {"force-exit", 0, NULL, 'X'}, | 382 | {"force-exit", 0, NULL, 'X'}, |
| 373 | {"version", 0, NULL, 'V'}, | 383 | {"version", 0, NULL, 'V'}, |
| @@ -376,7 +386,7 @@ static void parse_opts(int argc, char **argv) | |||
| 376 | int c; | 386 | int c; |
| 377 | 387 | ||
| 378 | while (1) { | 388 | while (1) { |
| 379 | c = getopt_long(argc, argv, "hfvVuU:xX", longopts, (int *) 0); | 389 | c = getopt_long(argc, argv, "hfvVuU:xXsnz", longopts, (int *) 0); |
| 380 | if (c == -1) { | 390 | if (c == -1) { |
| 381 | break; | 391 | break; |
| 382 | } | 392 | } |
| @@ -399,7 +409,18 @@ static void parse_opts(int argc, char **argv) | |||
| 399 | drop_user = optarg; | 409 | drop_user = optarg; |
| 400 | break; | 410 | break; |
| 401 | case 'u': | 411 | case 'u': |
| 402 | opt_udev = 1; | 412 | opt_disable_hotplug = 1; |
| 413 | opt_enable_exit = 1; | ||
| 414 | break; | ||
| 415 | case 's': | ||
| 416 | opt_enable_exit = 1; | ||
| 417 | foreground = 1; | ||
| 418 | break; | ||
| 419 | case 'n': | ||
| 420 | opt_disable_hotplug = 1; | ||
| 421 | break; | ||
| 422 | case 'z': | ||
| 423 | opt_enable_exit = 1; | ||
| 403 | break; | 424 | break; |
| 404 | case 'x': | 425 | case 'x': |
| 405 | opt_exit = 1; | 426 | opt_exit = 1; |
| @@ -474,7 +495,7 @@ int main(int argc, char *argv[]) | |||
| 474 | goto terminate; | 495 | goto terminate; |
| 475 | } | 496 | } |
| 476 | } else { | 497 | } else { |
| 477 | if (!opt_udev) { | 498 | if (!opt_disable_hotplug) { |
| 478 | usbmuxd_log(LL_ERROR, "Another instance is already running (pid %d). exiting.", lock.l_pid); | 499 | usbmuxd_log(LL_ERROR, "Another instance is already running (pid %d). exiting.", lock.l_pid); |
| 479 | res = -1; | 500 | res = -1; |
| 480 | } else { | 501 | } else { |
| @@ -497,7 +518,7 @@ int main(int argc, char *argv[]) | |||
| 497 | unlink(lockfile); | 518 | unlink(lockfile); |
| 498 | 519 | ||
| 499 | if (opt_exit) { | 520 | if (opt_exit) { |
| 500 | usbmuxd_log(LL_NOTICE, "No running instance found, none killed. exiting."); | 521 | usbmuxd_log(LL_NOTICE, "No running instance found, none killed. Exiting."); |
| 501 | goto terminate; | 522 | goto terminate; |
| 502 | } | 523 | } |
| 503 | 524 | ||
| @@ -635,8 +656,13 @@ int main(int argc, char *argv[]) | |||
| 635 | if((res = notify_parent(0)) < 0) | 656 | if((res = notify_parent(0)) < 0) |
| 636 | goto terminate; | 657 | goto terminate; |
| 637 | 658 | ||
| 638 | if(opt_udev) | 659 | if(opt_disable_hotplug) { |
| 639 | usb_autodiscover(0); // discovery triggered by udev | 660 | usbmuxd_log(LL_NOTICE, "Automatic device discovery on hotplug disabled."); |
| 661 | usb_autodiscover(0); // discovery to be triggered by new instance | ||
| 662 | } | ||
| 663 | if (opt_enable_exit) { | ||
| 664 | usbmuxd_log(LL_NOTICE, "Enabled exit on SIGUSR1 if no devices are attached. Start a new instance with \"--exit\" to trigger."); | ||
| 665 | } | ||
| 640 | 666 | ||
| 641 | res = main_loop(listenfd); | 667 | res = main_loop(listenfd); |
| 642 | if(res < 0) | 668 | if(res < 0) |
