diff options
Diffstat (limited to 'usbmuxd/main.c')
| -rw-r--r-- | usbmuxd/main.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/usbmuxd/main.c b/usbmuxd/main.c index f1aa1cc..525e095 100644 --- a/usbmuxd/main.c +++ b/usbmuxd/main.c | |||
| @@ -92,17 +92,21 @@ int create_socket(void) { | |||
| 92 | 92 | ||
| 93 | void handle_signal(int sig) | 93 | void handle_signal(int sig) |
| 94 | { | 94 | { |
| 95 | if (sig == SIGTERM) { | 95 | if (sig != SIGUSR1) { |
| 96 | usbmuxd_log(LL_NOTICE,"Caught signal %d, exiting", sig); | ||
| 96 | should_exit = 1; | 97 | should_exit = 1; |
| 97 | } else { | 98 | } else { |
| 98 | usbmuxd_log(LL_NOTICE,"Caught signal %d", sig); | 99 | if(opt_udev) { |
| 99 | usbmuxd_log(LL_INFO, "Checking if we can terminate (no more devices attached)..."); | 100 | usbmuxd_log(LL_INFO, "Caught SIGUSR1, checking if we can terminate (no more devices attached)..."); |
| 100 | if (device_get_count() > 0) { | 101 | if (device_get_count() > 0) { |
| 101 | // we can't quit, there are still devices attached. | 102 | // we can't quit, there are still devices attached. |
| 102 | usbmuxd_log(LL_NOTICE, "Refusing to terminate, there are still devices attached. Kill me with signal 15 (TERM) to force quit."); | 103 | usbmuxd_log(LL_NOTICE, "Refusing to terminate, there are still devices attached. Kill me with signal 15 (TERM) to force quit."); |
| 104 | } else { | ||
| 105 | // it's safe to quit | ||
| 106 | should_exit = 1; | ||
| 107 | } | ||
| 103 | } else { | 108 | } else { |
| 104 | // it's safe to quit | 109 | usbmuxd_log(LL_INFO, "Caught SIGUSR1 but we weren't started in --udev mode, ignoring"); |
| 105 | should_exit = 1; | ||
| 106 | } | 110 | } |
| 107 | } | 111 | } |
| 108 | } | 112 | } |
| @@ -115,6 +119,7 @@ void set_signal_handlers(void) | |||
| 115 | sigaction(SIGINT, &sa, NULL); | 119 | sigaction(SIGINT, &sa, NULL); |
| 116 | sigaction(SIGQUIT, &sa, NULL); | 120 | sigaction(SIGQUIT, &sa, NULL); |
| 117 | sigaction(SIGTERM, &sa, NULL); | 121 | sigaction(SIGTERM, &sa, NULL); |
| 122 | sigaction(SIGUSR1, &sa, NULL); | ||
| 118 | } | 123 | } |
| 119 | 124 | ||
| 120 | int main_loop(int listenfd) | 125 | int main_loop(int listenfd) |
| @@ -241,9 +246,10 @@ static void usage() | |||
| 241 | printf("\t-u|--user[=USER] Change to this user after startup (needs usb privileges).\n"); | 246 | printf("\t-u|--user[=USER] Change to this user after startup (needs usb privileges).\n"); |
| 242 | printf("\t If USER is not specified, defaults to usbmux.\n"); | 247 | printf("\t If USER is not specified, defaults to usbmux.\n"); |
| 243 | printf("\t-d|--udev Run in udev operation mode.\n"); | 248 | printf("\t-d|--udev Run in udev operation mode.\n"); |
| 244 | printf("\t-x|--exit Tell a running instance to exit.\n"); | 249 | printf("\t-x|--exit Tell a running instance to exit if there are no devices\n"); |
| 245 | printf("\t-X|--force-exit Tell a running instance to exit, even if\n"); | 250 | printf("\t connected (must be in udev mode).\n"); |
| 246 | printf("\t there are still devices connected.\n"); | 251 | printf("\t-X|--force-exit Tell a running instance to exit, even if there are still\n"); |
| 252 | printf("\t devices connected (always works).\n"); | ||
| 247 | printf("\n"); | 253 | printf("\n"); |
| 248 | } | 254 | } |
| 249 | 255 | ||
| @@ -287,7 +293,7 @@ static void parse_opts(int argc, char **argv) | |||
| 287 | break; | 293 | break; |
| 288 | case 'x': | 294 | case 'x': |
| 289 | opt_exit = 1; | 295 | opt_exit = 1; |
| 290 | exit_signal = SIGQUIT; | 296 | exit_signal = SIGUSR1; |
| 291 | break; | 297 | break; |
| 292 | case 'X': | 298 | case 'X': |
| 293 | opt_exit = 1; | 299 | opt_exit = 1; |
| @@ -298,8 +304,6 @@ static void parse_opts(int argc, char **argv) | |||
| 298 | exit(2); | 304 | exit(2); |
| 299 | } | 305 | } |
| 300 | } | 306 | } |
| 301 | if (opt_udev) | ||
| 302 | foreground = 0; | ||
| 303 | } | 307 | } |
| 304 | 308 | ||
| 305 | int main(int argc, char *argv[]) | 309 | int main(int argc, char *argv[]) |
