Commit 564899f9 authored by Davidlohr Bueso's avatar Davidlohr Bueso Committed by Arnaud Lacombe

kconfig: handle SIGINT in menuconfig

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.
Signed-off-by: default avatarDavidlohr Bueso <dave@gnu.org>
Signed-off-by: default avatarArnaud Lacombe <lacombar@gmail.com>
parent 953742c8
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h>
#include <unistd.h> #include <unistd.h>
#include <locale.h> #include <locale.h>
...@@ -272,6 +273,7 @@ static struct menu *current_menu; ...@@ -272,6 +273,7 @@ static struct menu *current_menu;
static int child_count; static int child_count;
static int single_menu_mode; static int single_menu_mode;
static int show_all_options; static int show_all_options;
static int saved_x, saved_y;
static void conf(struct menu *menu); static void conf(struct menu *menu);
static void conf_choice(struct menu *menu); static void conf_choice(struct menu *menu);
...@@ -792,47 +794,19 @@ static void conf_save(void) ...@@ -792,47 +794,19 @@ static void conf_save(void)
} }
} }
int main(int ac, char **av) static int handle_exit(void)
{ {
int saved_x, saved_y;
char *mode;
int res; int res;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
conf_parse(av[1]);
conf_read(NULL);
mode = getenv("MENUCONFIG_MODE");
if (mode) {
if (!strcasecmp(mode, "single_menu"))
single_menu_mode = 1;
}
initscr();
getyx(stdscr, saved_y, saved_x);
if (init_dialog(NULL)) {
fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
return 1;
}
set_config_filename(conf_get_configname());
do {
conf(&rootmenu);
dialog_clear(); dialog_clear();
if (conf_get_changed()) if (conf_get_changed())
res = dialog_yesno(NULL, res = dialog_yesno(NULL,
_("Do you wish to save your " _("Do you wish to save your new configuration ?\n"
"new configuration?\n"
"<ESC><ESC> to continue."), "<ESC><ESC> to continue."),
6, 60); 6, 60);
else else
res = -1; res = -1;
} while (res == KEY_ESC);
end_dialog(saved_x, saved_y); end_dialog(saved_x, saved_y);
switch (res) { switch (res) {
...@@ -850,6 +824,7 @@ int main(int ac, char **av) ...@@ -850,6 +824,7 @@ int main(int ac, char **av)
"*** End of the configuration.\n" "*** End of the configuration.\n"
"*** Execute 'make' to start the build or try 'make help'." "*** Execute 'make' to start the build or try 'make help'."
"\n\n")); "\n\n"));
res = 0;
break; break;
default: default:
fprintf(stderr, _("\n\n" fprintf(stderr, _("\n\n"
...@@ -857,6 +832,49 @@ int main(int ac, char **av) ...@@ -857,6 +832,49 @@ int main(int ac, char **av)
"\n\n")); "\n\n"));
} }
return 0; return res;
}
static void sig_handler(int signo)
{
exit(handle_exit());
}
int main(int ac, char **av)
{
char *mode;
int res;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
signal(SIGINT, sig_handler);
conf_parse(av[1]);
conf_read(NULL);
mode = getenv("MENUCONFIG_MODE");
if (mode) {
if (!strcasecmp(mode, "single_menu"))
single_menu_mode = 1;
}
initscr();
getyx(stdscr, saved_y, saved_x);
if (init_dialog(NULL)) {
fprintf(stderr, N_("Your display is too small to run Menuconfig!\n"));
fprintf(stderr, N_("It must be at least 19 lines by 80 columns.\n"));
return 1;
}
set_config_filename(conf_get_configname());
do {
conf(&rootmenu);
res = handle_exit();
} while (res == KEY_ESC);
return res;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment