summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c45
-rw-r--r--udev/85-usbmuxd.rules.in2
2 files changed, 31 insertions, 16 deletions
diff --git a/src/main.c b/src/main.c
index b4b5283..3617e14 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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 */
1012static 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
1021static void usage() 1009static 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 */
1086static 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 */
1098int main(int argc, char **argv) 1113int 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
diff --git a/udev/85-usbmuxd.rules.in b/udev/85-usbmuxd.rules.in
index e661ccd..7820a36 100644
--- a/udev/85-usbmuxd.rules.in
+++ b/udev/85-usbmuxd.rules.in
@@ -31,7 +31,7 @@ ACTION=="add", SUBSYSTEM=="usb_endpoint", KERNEL=="usbdev*_ep85", SYMLINK+="usbm
31 31
32# Start and stop 'usbmuxd' as required. 32# Start and stop 'usbmuxd' as required.
33ACTION=="add", SUBSYSTEM=="usb_endpoint", KERNEL=="usbdev*_ep85", RUN+="/sbin/start-stop-daemon --start --oknodo --exec @prefix@/sbin/usbmuxd" 33ACTION=="add", SUBSYSTEM=="usb_endpoint", KERNEL=="usbdev*_ep85", RUN+="/sbin/start-stop-daemon --start --oknodo --exec @prefix@/sbin/usbmuxd"
34ACTION=="remove", SUBSYSTEM=="usb_endpoint", KERNEL=="usbdev*_ep85", RUN+="/sbin/start-stop-daemon --stop --signal 2 --exec @prefix@/sbin/usbmuxd" 34ACTION=="remove", SUBSYSTEM=="usb_endpoint", KERNEL=="usbdev*_ep85", RUN+="/sbin/start-stop-daemon --stop --signal 3 --exec @prefix@/sbin/usbmuxd"
35 35
36# skip 36# skip
37LABEL="usbmuxd_rules_end" 37LABEL="usbmuxd_rules_end"