Skip to content

Commit 564899f

Browse files
Davidlohr Buesolacombar
authored andcommitted
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: Davidlohr Bueso <dave@gnu.org> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
1 parent 953742c commit 564899f

1 file changed

Lines changed: 52 additions & 34 deletions

File tree

‎scripts/kconfig/mconf.c‎

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdarg.h>
1616
#include <stdlib.h>
1717
#include <string.h>
18+
#include <signal.h>
1819
#include <unistd.h>
1920
#include <locale.h>
2021

@@ -272,6 +273,7 @@ static struct menu *current_menu;
272273
static int child_count;
273274
static int single_menu_mode;
274275
static int show_all_options;
276+
static int saved_x, saved_y;
275277

276278
static void conf(struct menu *menu);
277279
static void conf_choice(struct menu *menu);
@@ -792,16 +794,63 @@ static void conf_save(void)
792794
}
793795
}
794796

797+
static int handle_exit(void)
798+
{
799+
int res;
800+
801+
dialog_clear();
802+
if (conf_get_changed())
803+
res = dialog_yesno(NULL,
804+
_("Do you wish to save your new configuration ?\n"
805+
"<ESC><ESC> to continue."),
806+
6, 60);
807+
else
808+
res = -1;
809+
810+
end_dialog(saved_x, saved_y);
811+
812+
switch (res) {
813+
case 0:
814+
if (conf_write(filename)) {
815+
fprintf(stderr, _("\n\n"
816+
"Error while writing of the configuration.\n"
817+
"Your configuration changes were NOT saved."
818+
"\n\n"));
819+
return 1;
820+
}
821+
/* fall through */
822+
case -1:
823+
printf(_("\n\n"
824+
"*** End of the configuration.\n"
825+
"*** Execute 'make' to start the build or try 'make help'."
826+
"\n\n"));
827+
res = 0;
828+
break;
829+
default:
830+
fprintf(stderr, _("\n\n"
831+
"Your configuration changes were NOT saved."
832+
"\n\n"));
833+
}
834+
835+
return res;
836+
}
837+
838+
static void sig_handler(int signo)
839+
{
840+
exit(handle_exit());
841+
}
842+
795843
int main(int ac, char **av)
796844
{
797-
int saved_x, saved_y;
798845
char *mode;
799846
int res;
800847

801848
setlocale(LC_ALL, "");
802849
bindtextdomain(PACKAGE, LOCALEDIR);
803850
textdomain(PACKAGE);
804851

852+
signal(SIGINT, sig_handler);
853+
805854
conf_parse(av[1]);
806855
conf_read(NULL);
807856

@@ -823,40 +872,9 @@ int main(int ac, char **av)
823872
set_config_filename(conf_get_configname());
824873
do {
825874
conf(&rootmenu);
826-
dialog_clear();
827-
if (conf_get_changed())
828-
res = dialog_yesno(NULL,
829-
_("Do you wish to save your "
830-
"new configuration?\n"
831-
"<ESC><ESC> to continue."),
832-
6, 60);
833-
else
834-
res = -1;
875+
res = handle_exit();
835876
} while (res == KEY_ESC);
836-
end_dialog(saved_x, saved_y);
837-
838-
switch (res) {
839-
case 0:
840-
if (conf_write(filename)) {
841-
fprintf(stderr, _("\n\n"
842-
"Error while writing of the configuration.\n"
843-
"Your configuration changes were NOT saved."
844-
"\n\n"));
845-
return 1;
846-
}
847-
/* fall through */
848-
case -1:
849-
printf(_("\n\n"
850-
"*** End of the configuration.\n"
851-
"*** Execute 'make' to start the build or try 'make help'."
852-
"\n\n"));
853-
break;
854-
default:
855-
fprintf(stderr, _("\n\n"
856-
"Your configuration changes were NOT saved."
857-
"\n\n"));
858-
}
859877

860-
return 0;
878+
return res;
861879
}
862880

0 commit comments

Comments
 (0)