diff options
| author | 2009-05-19 16:44:39 +0200 | |
|---|---|---|
| committer | 2009-05-19 16:44:39 +0200 | |
| commit | 0c55afdb315f12b0f2a37f37a3ec711c75507c0d (patch) | |
| tree | 35ed260cae35d9a4744491452becbc0b3531e576 /src/main.c | |
| parent | 5d34c2e7c70de039c75c7a39933b98d14a659176 (diff) | |
| download | usbmuxd-0c55afdb315f12b0f2a37f37a3ec711c75507c0d.tar.gz usbmuxd-0c55afdb315f12b0f2a37f37a3ec711c75507c0d.tar.bz2 | |
Let the daemon terminate only when no more device is attached
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 45 |
1 files changed, 30 insertions, 15 deletions
| @@ -1006,18 +1006,6 @@ static int daemonize() | |||
| 1006 | return 0; | 1006 | return 0; |
| 1007 | } | 1007 | } |
| 1008 | 1008 | ||
| 1009 | /** | ||
| 1010 | * signal handler function for cleaning up properly | ||
| 1011 | */ | ||
| 1012 | static void clean_exit(int sig) | ||
| 1013 | { | ||
| 1014 | if (sig == SIGINT) { | ||
| 1015 | if (verbose >= 1) | ||
| 1016 | fprintf(stderr, "CTRL+C pressed\n"); | ||
| 1017 | } | ||
| 1018 | quit_flag = 1; | ||
| 1019 | } | ||
| 1020 | |||
| 1021 | static void usage() | 1009 | static void usage() |
| 1022 | { | 1010 | { |
| 1023 | printf("usage: usbmuxd [options]\n"); | 1011 | printf("usage: usbmuxd [options]\n"); |
| @@ -1093,6 +1081,33 @@ static int devices_attached() | |||
| 1093 | } | 1081 | } |
| 1094 | 1082 | ||
| 1095 | /** | 1083 | /** |
| 1084 | * signal handler function for cleaning up properly | ||
| 1085 | */ | ||
| 1086 | static void handle_signal(int sig) | ||
| 1087 | { | ||
| 1088 | if (sig == SIGTERM) { | ||
| 1089 | quit_flag = 1; | ||
| 1090 | } else { | ||
| 1091 | if (sig == SIGINT) { | ||
| 1092 | if (verbose >= 1) | ||
| 1093 | fprintf(stderr, "CTRL+C pressed\n"); | ||
| 1094 | } | ||
| 1095 | |||
| 1096 | if (verbose >= 1) | ||
| 1097 | fprintf(stderr, "Checking if we can terminate (no more devices attached)...\n"); | ||
| 1098 | |||
| 1099 | if (devices_attached() > 0) { | ||
| 1100 | // we can't quit, there are still devices attached. | ||
| 1101 | if (verbose >= 1) | ||
| 1102 | fprintf(stderr, "Refusing to terminate, there are still devices attached. Kill me with signal 15 (TERM) to force quit.\n"); | ||
| 1103 | } else { | ||
| 1104 | // it's safe to quit | ||
| 1105 | quit_flag = 1; | ||
| 1106 | } | ||
| 1107 | } | ||
| 1108 | } | ||
| 1109 | |||
| 1110 | /** | ||
| 1096 | * main function. Initializes all stuff and then loops waiting in accept. | 1111 | * main function. Initializes all stuff and then loops waiting in accept. |
| 1097 | */ | 1112 | */ |
| 1098 | int main(int argc, char **argv) | 1113 | int main(int argc, char **argv) |
| @@ -1121,9 +1136,9 @@ int main(int argc, char **argv) | |||
| 1121 | logmsg(LOG_NOTICE, "starting"); | 1136 | logmsg(LOG_NOTICE, "starting"); |
| 1122 | 1137 | ||
| 1123 | // signal(SIGHUP, reload_conf); // none yet | 1138 | // signal(SIGHUP, reload_conf); // none yet |
| 1124 | signal(SIGINT, clean_exit); | 1139 | signal(SIGINT, handle_signal); |
| 1125 | signal(SIGQUIT, clean_exit); | 1140 | signal(SIGQUIT, handle_signal); |
| 1126 | signal(SIGTERM, clean_exit); | 1141 | signal(SIGTERM, handle_signal); |
| 1127 | signal(SIGPIPE, SIG_IGN); | 1142 | signal(SIGPIPE, SIG_IGN); |
| 1128 | 1143 | ||
| 1129 | // check for other running instance | 1144 | // check for other running instance |
