public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kconfig: handle SIGINT in menuconfig
@ 2011-08-20 20:50 Davidlohr Bueso
  2011-08-20 22:12 ` Arnaud Lacombe
  0 siblings, 1 reply; 3+ messages in thread
From: Davidlohr Bueso @ 2011-08-20 20:50 UTC (permalink / raw)
  To: Michal Marek; +Cc: lkml, linux-kbuild

From: Davidlohr Bueso <dave@gnu.org>

I recently got bitten in the ass when pressing Ctrl-C and lost all my current configuration changes. This patch captures SIGINT and allows the user to save any changes.
Some code refactoring was made in order to handle the exit behavior.

CC: Roman Zippel <zippel@linux-m68k.org>
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 scripts/kconfig/mconf.c |   76 ++++++++++++++++++++++++++++++++---------------
 1 files changed, 52 insertions(+), 24 deletions(-)

diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 820d2b6..7ca3bb7 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -6,6 +6,7 @@
  * 2002-11-06 Petr Baudis <pasky@ucw.cz>
  *
  * i18n, 2005, Arnaldo Carvalho de Melo <acme@conectiva.com.br>
+ * Handle SIGINT (Ctrl-C), 2011, Davidlohr Bueso <dave@gnu.org>
  */
 
 #include <ctype.h>
@@ -15,6 +16,7 @@
 #include <stdarg.h>
 #include <stdlib.h>
 #include <string.h>
+#include <signal.h>
 #include <unistd.h>
 #include <locale.h>
 
@@ -272,6 +274,7 @@ static struct menu *current_menu;
 static int child_count;
 static int single_menu_mode;
 static int show_all_options;
+static int saved_x, saved_y;
 
 static void conf(struct menu *menu);
 static void conf_choice(struct menu *menu);
@@ -792,9 +795,54 @@ static void conf_save(void)
 	}
 }
 
+static int handle_exit(int res)
+{
+	switch (res) {
+	case 0:
+		if (conf_write(filename)) {
+			fprintf(stderr, _("\n\n"
+					  "Error while writing of the configuration.\n"
+					  "Your configuration changes were NOT saved."
+					  "\n\n"));
+			return 1;
+		}
+		/* fall through */
+	case -1:
+		printf(_("\n\n"
+			 "*** End of the configuration.\n"
+			 "*** Execute 'make' to start the build or try 'make help'."
+			 "\n\n"));
+		break;
+	default:
+		fprintf(stderr, _("\n\n"
+				  "Your configuration changes were NOT saved."
+				  "\n\n"));
+	}
+
+	return 0;
+}
+
+static void sig_handler(int signo __attribute__((__unused__)))
+{
+	int res;
+	
+	do {
+		dialog_clear();
+		if (conf_get_changed())
+			res = dialog_yesno(NULL,
+					   _("Do you wish to save your "
+					     "new configuration?\n"),
+					   6, 60);
+		else
+			res = -1;
+	} while (res == KEY_ESC);
+
+	end_dialog(saved_x, saved_y);
+	exit(handle_exit(res));
+}
+
 int main(int ac, char **av)
 {
-	int saved_x, saved_y;
 	char *mode;
 	int res;
 
@@ -802,6 +850,8 @@ int main(int ac, char **av)
 	bindtextdomain(PACKAGE, LOCALEDIR);
 	textdomain(PACKAGE);
 
+	signal(SIGINT, sig_handler);
+
 	conf_parse(av[1]);
 	conf_read(NULL);
 
@@ -835,28 +885,6 @@ int main(int ac, char **av)
 	} while (res == KEY_ESC);
 	end_dialog(saved_x, saved_y);
 
-	switch (res) {
-	case 0:
-		if (conf_write(filename)) {
-			fprintf(stderr, _("\n\n"
-				"Error while writing of the configuration.\n"
-				"Your configuration changes were NOT saved."
-				"\n\n"));
-			return 1;
-		}
-		/* fall through */
-	case -1:
-		printf(_("\n\n"
-			"*** End of the configuration.\n"
-			"*** Execute 'make' to start the build or try 'make help'."
-			"\n\n"));
-		break;
-	default:
-		fprintf(stderr, _("\n\n"
-			"Your configuration changes were NOT saved."
-			"\n\n"));
-	}
-
-	return 0;
+	return handle_exit(res);
 }
 
-- 
1.7.4.1




^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-21 22:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-20 20:50 [PATCH] kconfig: handle SIGINT in menuconfig Davidlohr Bueso
2011-08-20 22:12 ` Arnaud Lacombe
2011-08-21 22:48   ` Davidlohr Bueso

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox