kconfig: handle SIGINT in menuconfig
PATCH 1/1 kconfig: handle SIGINT in menuconfig
From: Davidlohr Bueso <[email protected]>
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.
--- scripts/kconfig/mconf.c | 76 ++++++++++++++++++++++++++++++++--------------- 1 files changed, 52 insertions(+), 24 deletions(-)
scripts/kconfig/mconf.c +52 -24
@@ -6,6 +6,7 @@* 2002-11-06 Petr Baudis <[email protected]> * * i18n, 2005, Arnaldo Carvalho de Melo <[email protected]> +* Handle SIGINT (Ctrl-C), 2011, Davidlohr Bueso <[email protected]> */ #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); }
Signature · 1 line
1.7.4.1
Hi,
Quoted 3 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
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.
Pretty much all front-ends have that behavior.
Quoted 2 lines
Some code refactoring was made in order to handle the exit behavior.
beside a few nits, that look good.
- Arnaud
Quoted 1 line
CC Roman Zippel <[email protected]>
Roman has been reported MIA for more than 2 years now, I do not think this is needed anylonger.
Quoted 10 lines
Signed-off-by Davidlohr Bueso <[email protected]>---
scripts/kconfig/mconf.c | 76 ++++++++++++++++++++++++++++++++---------------1 files changed, 52 insertions(+), 24 deletions(-)scripts/kconfig/mconf.c +0
-0
scripts/kconfig/mconf.c line 11
Quoted 6 lines
scripts/kconfig/mconf.c +1
-0@@ -6,6 +6,7 @@* 2002-11-06 Petr Baudis <[email protected]> * * i18n, 2005, Arnaldo Carvalho de Melo <[email protected]> +* Handle SIGINT (Ctrl-C), 2011, Davidlohr Bueso <[email protected]> */
FWIW, I do not really see the point of that, if you are looking for code history git does a better job, as well as for who deserve copyright on the code.
Quoted 39 lines
scripts/kconfig/mconf.c +20
-0#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;
scripts/kconfig/mconf.c static void conf_save(void) · line 825
Quoted 10 lines
scripts/kconfig/mconf.c +10
-0+ default: + fprintf(stderr, _("\n\n" + "Your configuration changes were NOT saved." + "\n\n")); + } + + return 0; +} + +static void sig_handler (int signo __attribute__((__unused__)))
__attribute__(()) is useless here, it is not used once across the file and gcc will not warn unless you ask it to be really verbose, which we do not.
Quoted 4 lines
scripts/kconfig/mconf.c +4
-0+{ + int res; + + do {
scripts/kconfig/mconf.c static void conf_save(void) · line 839
Quoted 10 lines
scripts/kconfig/mconf.c +10
-0+ 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); +
I do not really see the point of the loop here.
I'd suggest to have a single termination handling path. How about the attached patch ?
The message displayed might need tweaking.
Thanks,
- Arnaud
Quoted 54 lines
scripts/kconfig/mconf.c +7
-25+ 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
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
scripts/kconfig/mconf.c +19 -27
@@ -795,8 +795,21 @@ static void conf_save(void) } } -static int handle_exit (int res) +static int handle_exit (int fatal) { +int res; + +dialog_clear (); +if (conf_get_changed ()) + res =dialog_yesno (NULL , +_ ("Do you wish to save your new configuration ?\n" +"<ESC><ESC> to continue." ), +6 ,60 ); +else + res =-1 ; + +end_dialog (saved_x, saved_y); +switch (res) {case 0 :if (conf_write (filename)) {
@@ -812,6 +825,7 @@ static int handle_exit(int res)"*** End of the configuration.\n" "*** Execute 'make' to start the build or try 'make help'." "\n\n")); + res =0 ;break ;default : fprintf(stderr, _("\n\n"
@@ -819,26 +833,13 @@ static int handle_exit(int res) "\n\n")); } -return 0 ; +return res; }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)); +exit (handle_exit (1 )); }int main (int ac,char **av)
@@ -873,18 +874,9 @@ int main(int ac, char **av)set_config_filename (conf_get_configname ());do {conf (&rootmenu); -dialog_clear (); -if (conf_get_changed ()) - res =dialog_yesno (NULL , -_ ("Do you wish to save your " -"new configuration?\n" -"<ESC><ESC> to continue." ), -6 ,60 ); -else - res =-1 ; + res =handle_exit (0 ); }while (res ==KEY_ESC ); -end_dialog (saved_x, saved_y); -return handle_exit (res); +return res; }
Quoted 11 lines · Arnaud Lacombe
Hi,
Quoted 3 lines · Davidlohr Bueso
From: Davidlohr Bueso <[email protected]>
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.
Pretty much all front-ends have that behavior.
Quoted 2 lines
Some code refactoring was made in order to handle the exit behavior.
beside a few nits, that look good.
Thanks for reviewing.
Quoted 80 lines
- Arnaud
Quoted 1 line
CC Roman Zippel <[email protected]>Roman has been reported MIA for more than 2 years now, I do not think this is needed anylonger.
Quoted 10 lines
Signed-off-by Davidlohr Bueso <[email protected]>--- scripts/kconfig/mconf.c | 76 ++++++++++++++++++++++++++++++++--------------- 1 files changed, 52 insertions(+), 24 deletions(-)scripts/kconfig/mconf.c +0
-0scripts/kconfig/mconf.c line 11
Quoted 6 lines
scripts/kconfig/mconf.c +1
-0@@ -6,6 +6,7 @@* 2002-11-06 Petr Baudis <[email protected]> * * i18n, 2005, Arnaldo Carvalho de Melo <[email protected]> +* Handle SIGINT (Ctrl-C), 2011, Davidlohr Bueso <[email protected]> */ FWIW, I do not really see the point of that, if you are looking for code history git does a better job, as well as for who deserve copyright on the code.
Quoted 39 lines
scripts/kconfig/mconf.c +20
-0#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 ;scripts/kconfig/mconf.c static void conf_save(void) · line 825
Quoted 10 lines
scripts/kconfig/mconf.c +10
-0+default : +fprintf (stderr,_ ("\n\n" +"Your configuration changes were NOT saved." +"\n\n" )); + } + +return 0 ; +} + +static void sig_handler (int signo __attribute__((__unused__)))__attribute__(()) is useless here, it is not used once across the file and gcc will not warn unless you ask it to be really verbose, which we do not.
Quoted 15 lines
Quoted 4 lines
scripts/kconfig/mconf.c +4
-0+{ +int res; + + do {scripts/kconfig/mconf.c static void conf_save(void) · line 810
Quoted 10 lines
scripts/kconfig/mconf.c +10
-0+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 ); +I do not really see the point of the loop here.
Because I didn't want to allow the user the ESC+ESC option when exiting with Ctrl-C.
Quoted 3 lines
I'd suggest to have a single termination handling path. How about the attached patch ?
Makes sense, no objections here. I'll send a new version of the patch with your changes.
Thanks,
Davidlohr