* [PATCH v2] kconfig: handle SIGINT in menuconfig
@ 2011-08-22 1:04 Davidlohr Bueso
2011-08-22 6:03 ` Arnaud Lacombe
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Davidlohr Bueso @ 2011-08-22 1:04 UTC (permalink / raw)
To: Michal Marek, Arnaud Lacombe; +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.
Signed-off-by: Davidlohr Bueso <dave@gnu.org>
Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
---
scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++++++++------------------
1 files changed, 52 insertions(+), 34 deletions(-)
diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
index 820d2b6..19e200d 100644
--- a/scripts/kconfig/mconf.c
+++ b/scripts/kconfig/mconf.c
@@ -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,9 +794,54 @@ static void conf_save(void)
}
}
+static int handle_exit(void)
+{
+ 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)) {
+ 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"));
+ res = 0;
+ break;
+ default:
+ fprintf(stderr, _("\n\n"
+ "Your configuration changes were NOT saved."
+ "\n\n"));
+ }
+
+ return res;
+}
+
+static void sig_handler(int signo)
+{
+ exit(handle_exit());
+}
+
int main(int ac, char **av)
{
- int saved_x, saved_y;
char *mode;
int res;
@@ -802,6 +849,8 @@ int main(int ac, char **av)
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
+ signal(SIGINT, sig_handler);
+
conf_parse(av[1]);
conf_read(NULL);
@@ -823,40 +872,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();
} 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 res;
}
--
1.7.4.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kconfig: handle SIGINT in menuconfig
2011-08-22 1:04 [PATCH v2] kconfig: handle SIGINT in menuconfig Davidlohr Bueso
@ 2011-08-22 6:03 ` Arnaud Lacombe
2011-08-30 1:55 ` Arnaud Lacombe
2011-09-07 13:30 ` Davidlohr Bueso
2 siblings, 0 replies; 7+ messages in thread
From: Arnaud Lacombe @ 2011-08-22 6:03 UTC (permalink / raw)
To: dave; +Cc: Michal Marek, lkml, linux-kbuild
Hi,
On Sun, Aug 21, 2011 at 9:04 PM, Davidlohr Bueso <dave@gnu.org> wrote:
> 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.
>
Looks mostly good, I'll give it a try to see if we did not miss corner-case.
> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
I never S.O.B. anything explicitly, please do not add my signature
without my consent. That said, here it is:
Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
:-)
Thanks,
- Arnaud
> ---
> scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++++++++------------------
> 1 files changed, 52 insertions(+), 34 deletions(-)
>
> diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
> index 820d2b6..19e200d 100644
> --- a/scripts/kconfig/mconf.c
> +++ b/scripts/kconfig/mconf.c
> @@ -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,9 +794,54 @@ static void conf_save(void)
> }
> }
>
> +static int handle_exit(void)
> +{
> + 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)) {
> + 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"));
> + res = 0;
> + break;
> + default:
> + fprintf(stderr, _("\n\n"
> + "Your configuration changes were NOT saved."
> + "\n\n"));
> + }
> +
> + return res;
> +}
> +
> +static void sig_handler(int signo)
> +{
> + exit(handle_exit());
> +}
> +
> int main(int ac, char **av)
> {
> - int saved_x, saved_y;
> char *mode;
> int res;
>
> @@ -802,6 +849,8 @@ int main(int ac, char **av)
> bindtextdomain(PACKAGE, LOCALEDIR);
> textdomain(PACKAGE);
>
> + signal(SIGINT, sig_handler);
> +
> conf_parse(av[1]);
> conf_read(NULL);
>
> @@ -823,40 +872,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();
> } 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 res;
> }
>
> --
> 1.7.4.1
>
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kconfig: handle SIGINT in menuconfig
2011-08-22 1:04 [PATCH v2] kconfig: handle SIGINT in menuconfig Davidlohr Bueso
2011-08-22 6:03 ` Arnaud Lacombe
@ 2011-08-30 1:55 ` Arnaud Lacombe
2011-08-30 2:12 ` Arnaud Lacombe
2011-09-07 13:30 ` Davidlohr Bueso
2 siblings, 1 reply; 7+ messages in thread
From: Arnaud Lacombe @ 2011-08-30 1:55 UTC (permalink / raw)
To: dave; +Cc: Michal Marek, lkml, linux-kbuild
Hi,
On Sun, Aug 21, 2011 at 9:04 PM, Davidlohr Bueso <dave@gnu.org> wrote:
> 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.
>
> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
> ---
> scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++++++++------------------
> 1 files changed, 52 insertions(+), 34 deletions(-)
>
> diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
> index 820d2b6..19e200d 100644
> --- a/scripts/kconfig/mconf.c
> +++ b/scripts/kconfig/mconf.c
> @@ -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,9 +794,54 @@ static void conf_save(void)
> }
> }
>
> +static int handle_exit(void)
> +{
> + 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)) {
> + 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"));
> + res = 0;
> + break;
> + default:
> + fprintf(stderr, _("\n\n"
> + "Your configuration changes were NOT saved."
> + "\n\n"));
> + }
> +
> + return res;
> +}
> +
> +static void sig_handler(int signo)
> +{
> + exit(handle_exit());
> +}
> +
Actually, no matter what handle_exit() returns, the process will
return error code 130 and make will abort. I'd suggest to get rid of
the call to exit(), and only keep handle_exit().
any objection ?
- Arnaud
> int main(int ac, char **av)
> {
> - int saved_x, saved_y;
> char *mode;
> int res;
>
> @@ -802,6 +849,8 @@ int main(int ac, char **av)
> bindtextdomain(PACKAGE, LOCALEDIR);
> textdomain(PACKAGE);
>
> + signal(SIGINT, sig_handler);
> +
> conf_parse(av[1]);
> conf_read(NULL);
>
> @@ -823,40 +872,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();
> } 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 res;
> }
>
> --
> 1.7.4.1
>
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kconfig: handle SIGINT in menuconfig
2011-08-30 1:55 ` Arnaud Lacombe
@ 2011-08-30 2:12 ` Arnaud Lacombe
2011-09-06 12:33 ` Davidlohr Bueso
0 siblings, 1 reply; 7+ messages in thread
From: Arnaud Lacombe @ 2011-08-30 2:12 UTC (permalink / raw)
To: dave; +Cc: Michal Marek, lkml, linux-kbuild
Hi,
On Mon, Aug 29, 2011 at 9:55 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> Hi,
>
> On Sun, Aug 21, 2011 at 9:04 PM, Davidlohr Bueso <dave@gnu.org> wrote:
>> 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.
>>
>> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
>> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
>> ---
>> scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++++++++------------------
>> 1 files changed, 52 insertions(+), 34 deletions(-)
>>
>> diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
>> index 820d2b6..19e200d 100644
>> --- a/scripts/kconfig/mconf.c
>> +++ b/scripts/kconfig/mconf.c
>> @@ -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,9 +794,54 @@ static void conf_save(void)
>> }
>> }
>>
>> +static int handle_exit(void)
>> +{
>> + 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)) {
>> + 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"));
>> + res = 0;
>> + break;
>> + default:
>> + fprintf(stderr, _("\n\n"
>> + "Your configuration changes were NOT saved."
>> + "\n\n"));
>> + }
>> +
>> + return res;
>> +}
>> +
>> +static void sig_handler(int signo)
>> +{
>> + exit(handle_exit());
>> +}
>> +
> Actually, no matter what handle_exit() returns, the process will
> return error code 130 and make will abort. I'd suggest to get rid of
> the call to exit(), and only keep handle_exit().
>
> any objection ?
>
stupid me... we need the call to exit(2), but its argument do not seem
to be used.
- Arnaud
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kconfig: handle SIGINT in menuconfig
2011-08-30 2:12 ` Arnaud Lacombe
@ 2011-09-06 12:33 ` Davidlohr Bueso
0 siblings, 0 replies; 7+ messages in thread
From: Davidlohr Bueso @ 2011-09-06 12:33 UTC (permalink / raw)
To: Arnaud Lacombe; +Cc: Michal Marek, lkml, linux-kbuild
On Mon, 2011-08-29 at 22:12 -0400, Arnaud Lacombe wrote:
> Hi,
>
> On Mon, Aug 29, 2011 at 9:55 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
> > Hi,
> >
> > On Sun, Aug 21, 2011 at 9:04 PM, Davidlohr Bueso <dave@gnu.org> wrote:
> >> 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.
> >>
> >> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> >> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
> >> ---
> >> scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++++++++------------------
> >> 1 files changed, 52 insertions(+), 34 deletions(-)
> >>
> >> diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
> >> index 820d2b6..19e200d 100644
> >> --- a/scripts/kconfig/mconf.c
> >> +++ b/scripts/kconfig/mconf.c
> >> @@ -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,9 +794,54 @@ static void conf_save(void)
> >> }
> >> }
> >>
> >> +static int handle_exit(void)
> >> +{
> >> + 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)) {
> >> + 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"));
> >> + res = 0;
> >> + break;
> >> + default:
> >> + fprintf(stderr, _("\n\n"
> >> + "Your configuration changes were NOT saved."
> >> + "\n\n"));
> >> + }
> >> +
> >> + return res;
> >> +}
> >> +
> >> +static void sig_handler(int signo)
> >> +{
> >> + exit(handle_exit());
> >> +}
> >> +
> > Actually, no matter what handle_exit() returns, the process will
> > return error code 130 and make will abort. I'd suggest to get rid of
> > the call to exit(), and only keep handle_exit().
> >
> > any objection ?
> >
> stupid me... we need the call to exit(2), but its argument do not seem
> to be used.
Right otherwise we can't quit the program. The 130 exit code occurs
because we're aborting the make process, nothing we can do about that, I
think.
Thanks,
Davidlohr
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kconfig: handle SIGINT in menuconfig
2011-08-22 1:04 [PATCH v2] kconfig: handle SIGINT in menuconfig Davidlohr Bueso
2011-08-22 6:03 ` Arnaud Lacombe
2011-08-30 1:55 ` Arnaud Lacombe
@ 2011-09-07 13:30 ` Davidlohr Bueso
2011-09-07 14:18 ` Arnaud Lacombe
2 siblings, 1 reply; 7+ messages in thread
From: Davidlohr Bueso @ 2011-09-07 13:30 UTC (permalink / raw)
To: Michal Marek; +Cc: Arnaud Lacombe, lkml, linux-kbuild
Hi Michal
If you have no objections, can you pick this one up?
Thanks.
Davidlohr
On Sun, 2011-08-21 at 22:04 -0300, Davidlohr Bueso wrote:
> 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.
>
> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
> ---
> scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++++++++------------------
> 1 files changed, 52 insertions(+), 34 deletions(-)
>
> diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
> index 820d2b6..19e200d 100644
> --- a/scripts/kconfig/mconf.c
> +++ b/scripts/kconfig/mconf.c
> @@ -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,9 +794,54 @@ static void conf_save(void)
> }
> }
>
> +static int handle_exit(void)
> +{
> + 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)) {
> + 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"));
> + res = 0;
> + break;
> + default:
> + fprintf(stderr, _("\n\n"
> + "Your configuration changes were NOT saved."
> + "\n\n"));
> + }
> +
> + return res;
> +}
> +
> +static void sig_handler(int signo)
> +{
> + exit(handle_exit());
> +}
> +
> int main(int ac, char **av)
> {
> - int saved_x, saved_y;
> char *mode;
> int res;
>
> @@ -802,6 +849,8 @@ int main(int ac, char **av)
> bindtextdomain(PACKAGE, LOCALEDIR);
> textdomain(PACKAGE);
>
> + signal(SIGINT, sig_handler);
> +
> conf_parse(av[1]);
> conf_read(NULL);
>
> @@ -823,40 +872,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();
> } 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 res;
> }
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2] kconfig: handle SIGINT in menuconfig
2011-09-07 13:30 ` Davidlohr Bueso
@ 2011-09-07 14:18 ` Arnaud Lacombe
0 siblings, 0 replies; 7+ messages in thread
From: Arnaud Lacombe @ 2011-09-07 14:18 UTC (permalink / raw)
To: dave; +Cc: Michal Marek, lkml, linux-kbuild
Hi,
On Wed, Sep 7, 2011 at 9:30 AM, Davidlohr Bueso <dave@gnu.org> wrote:
> Hi Michal
>
> If you have no objections, can you pick this one up?
>
I picked up in my tree while Michal was in vacation, he then merged
that in his tree. I should have notified you.
- Arnaud
> Thanks.
> Davidlohr
>
> On Sun, 2011-08-21 at 22:04 -0300, Davidlohr Bueso wrote:
>> 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.
>>
>> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
>> Signed-off-by: Arnaud Lacombe <lacombar@gmail.com>
>> ---
>> scripts/kconfig/mconf.c | 86 ++++++++++++++++++++++++++++------------------
>> 1 files changed, 52 insertions(+), 34 deletions(-)
>>
>> diff --git a/scripts/kconfig/mconf.c b/scripts/kconfig/mconf.c
>> index 820d2b6..19e200d 100644
>> --- a/scripts/kconfig/mconf.c
>> +++ b/scripts/kconfig/mconf.c
>> @@ -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,9 +794,54 @@ static void conf_save(void)
>> }
>> }
>>
>> +static int handle_exit(void)
>> +{
>> + 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)) {
>> + 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"));
>> + res = 0;
>> + break;
>> + default:
>> + fprintf(stderr, _("\n\n"
>> + "Your configuration changes were NOT saved."
>> + "\n\n"));
>> + }
>> +
>> + return res;
>> +}
>> +
>> +static void sig_handler(int signo)
>> +{
>> + exit(handle_exit());
>> +}
>> +
>> int main(int ac, char **av)
>> {
>> - int saved_x, saved_y;
>> char *mode;
>> int res;
>>
>> @@ -802,6 +849,8 @@ int main(int ac, char **av)
>> bindtextdomain(PACKAGE, LOCALEDIR);
>> textdomain(PACKAGE);
>>
>> + signal(SIGINT, sig_handler);
>> +
>> conf_parse(av[1]);
>> conf_read(NULL);
>>
>> @@ -823,40 +872,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();
>> } 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 res;
>> }
>>
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2011-09-07 17:44 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-22 1:04 [PATCH v2] kconfig: handle SIGINT in menuconfig Davidlohr Bueso
2011-08-22 6:03 ` Arnaud Lacombe
2011-08-30 1:55 ` Arnaud Lacombe
2011-08-30 2:12 ` Arnaud Lacombe
2011-09-06 12:33 ` Davidlohr Bueso
2011-09-07 13:30 ` Davidlohr Bueso
2011-09-07 14:18 ` Arnaud Lacombe
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox