Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

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

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
Loading
Loading
Loading
Loading
+52 −34
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <locale.h>

@@ -272,6 +273,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,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;

	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();
	if (conf_get_changed())
		res = dialog_yesno(NULL,
					   _("Do you wish to save your "
					     "new configuration?\n"
				   _("Do you wish to save your new configuration ?\n"
				     "<ESC><ESC> to continue."),
				   6, 60);
	else
		res = -1;
	} while (res == KEY_ESC);

	end_dialog(saved_x, saved_y);

	switch (res) {
@@ -850,6 +824,7 @@ int main(int ac, char **av)
			 "*** 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"
@@ -857,6 +832,49 @@ int main(int ac, char **av)
				  "\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;
}