From 20c5341dabcce677d71a9ad9ee34d325bc3fe16f Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Tue, 20 Sep 2016 20:08:03 +0800 Subject: [PATCH] Force exit program for the second ^C --- src/server.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/server.c b/src/server.c index d1d0b35..8022a05 100644 --- a/src/server.c +++ b/src/server.c @@ -93,11 +93,15 @@ tty_server_new(int argc, char **argv) { void sig_handler(int sig) { + if (force_exit) + exit(EXIT_FAILURE); + char sig_name[20]; get_sig_name(sig, sig_name); - lwsl_notice("received signal: %s (%d)\n", sig_name, sig); + lwsl_notice("received signal: %s (%d), exiting...\n", sig_name, sig); force_exit = true; lws_cancel_service(context); + lwsl_notice("send ^C to force exit.\n"); } int @@ -266,7 +270,8 @@ main(int argc, char **argv) { #endif } - signal(SIGINT, sig_handler); + signal(SIGINT, sig_handler); // ^C + signal(SIGTERM, sig_handler); // kill context = lws_create_context(&info); if (context == NULL) { -- 2.43.4