summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/src/mobile/main.c
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2013-01-07 10:39:59 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2013-01-07 10:39:59 +0100
commit25c5e8221d94a7a5885d3bcd38d35da86bf17313 (patch)
tree9066ba3693795a5815f3504eb2c7c7ed9f3cb9a6 /src/host/layer23/src/mobile/main.c
parentee7fbbda22aedcdd8b6e3a5828fbdafd84571d72 (diff)
mobile: Improved exit of mobile process, reset phone
If mobile phone has started, it is reset after shutdown. This ensures that the phone is not transmitting anymore, especially while shutting down in dedicated mode. Using CTRL+c: The first signal causes initiating of shutdown with detach procedure. The second signal causes initiating of shutdown without detach procedure. The third signal will exit process immidiately. (in case it hangs) Using CTRL+z: The first signal causes initiating of shutdown without detach procedure. A subsequent CTRL+c would exit process immidiately.
Diffstat (limited to 'src/host/layer23/src/mobile/main.c')
-rw-r--r--src/host/layer23/src/mobile/main.c47
1 files changed, 35 insertions, 12 deletions
diff --git a/src/host/layer23/src/mobile/main.c b/src/host/layer23/src/mobile/main.c
index 312bcd66..8bcecba3 100644
--- a/src/host/layer23/src/mobile/main.c
+++ b/src/host/layer23/src/mobile/main.c
@@ -153,25 +153,38 @@ static void handle_options(int argc, char **argv)
void sighandler(int sigset)
{
+ static uint8_t _quit = 1, count_int = 0;
+
if (sigset == SIGHUP || sigset == SIGPIPE)
return;
- fprintf(stderr, "Signal %d received.\n", sigset);
+ fprintf(stderr, "\nSignal %d received.\n", sigset);
switch (sigset) {
case SIGINT:
- /* If another signal is received afterwards, the program
- * is terminated without finishing shutdown process.
+ /* The first signal causes initiating of shutdown with detach
+ * procedure. The second signal causes initiating of shutdown
+ * without detach procedure. The third signal will exit process
+ * immidiately. (in case it hangs)
*/
- signal(SIGINT, SIG_DFL);
- signal(SIGHUP, SIG_DFL);
- signal(SIGTERM, SIG_DFL);
- signal(SIGPIPE, SIG_DFL);
- signal(SIGABRT, SIG_DFL);
- signal(SIGUSR1, SIG_DFL);
- signal(SIGUSR2, SIG_DFL);
-
- osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, NULL);
+ if (count_int == 0) {
+ fprintf(stderr, "Performing shutdown with clean "
+ "detach, if possible...\n");
+ osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN,
+ NULL);
+ count_int = 1;
+ break;
+ }
+ if (count_int == 2) {
+ fprintf(stderr, "Unclean exit, please turn off phone "
+ "to be sure it is not transmitting!\n");
+ exit(0);
+ }
+ /* fall through */
+ case SIGTSTP:
+ count_int = 2;
+ fprintf(stderr, "Performing shutdown without detach...\n");
+ osmo_signal_dispatch(SS_GLOBAL, S_GLOBAL_SHUTDOWN, &_quit);
break;
case SIGABRT:
/* in case of abort, we want to obtain a talloc report
@@ -240,6 +253,7 @@ int main(int argc, char **argv)
exit(rc);
signal(SIGINT, sighandler);
+ signal(SIGTSTP, sighandler);
signal(SIGHUP, sighandler);
signal(SIGTERM, sighandler);
signal(SIGPIPE, sighandler);
@@ -267,5 +281,14 @@ int main(int argc, char **argv)
talloc_free(config_dir);
talloc_report_full(l23_ctx, stderr);
+ signal(SIGINT, SIG_DFL);
+ signal(SIGTSTP, SIG_DFL);
+ signal(SIGHUP, SIG_DFL);
+ signal(SIGTERM, SIG_DFL);
+ signal(SIGPIPE, SIG_DFL);
+ signal(SIGABRT, SIG_DFL);
+ signal(SIGUSR1, SIG_DFL);
+ signal(SIGUSR2, SIG_DFL);
+
return 0;
}