static struct cfdisk_menu *menu_pop(struct cfdisk *cf);
static void menu_refresh_size(struct cfdisk *cf);
+static int ui_end(void);
static int ui_refresh(struct cfdisk *cf);
static void ui_warnx(const char *fmt, ...);
static void ui_warn(const char *fmt, ...);
uintmax_t low, uintmax_t up, int *expsize);
static int ui_enabled;
-static int sig_resize;
+static volatile sig_atomic_t sig_resize;
+static volatile sig_atomic_t sig_die;
/* ncurses LINES and COLS may be actual variables or *macros*, but we need
* something portable and writable */
return fdisk_label_get_fields_ids(NULL, cf->cxt, &cf->fields, &cf->nfields);
}
+static void die_on_signal(void)
+{
+ DBG(MISC, ul_debug("die on signal."));
+ ui_end();
+ exit(EXIT_FAILURE);
+}
+
static void resize(void)
{
struct winsize ws;
refresh();
/* wait for keys */
- do {
+ while (!sig_die) {
key = getch();
+ if (sig_die)
+ break;
if (sig_resize)
ui_menu_resize(cf);
if (ui_menu_move(cf, key) == 0)
free(cm);
return 0;
}
- } while (1);
+ }
+
+ if (sig_die)
+ die_on_signal();
menu_pop(cf);
free(cm);
clrtoeol();
}
-static void die_on_signal(int dummy __attribute__((__unused__)))
+
+static void sig_handler_die(int dummy __attribute__((__unused__)))
{
- DBG(MISC, ul_debug("die on signal."));
- ui_end();
- exit(EXIT_FAILURE);
+ sig_die = 1;
}
static void sig_handler_resize(int dummy __attribute__((__unused__)))
{
- DBG(MISC, ul_debug("resize on signal."));
sig_resize = 1;
}
/* setup SIGCHLD handler */
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
- sa.sa_handler = die_on_signal;
+ sa.sa_handler = sig_handler_die;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
curs_set(1);
- while (1) {
+ while (!sig_die) {
wint_t c; /* we have fallback in widechar.h */
move(ln, cl);
#else
if ((c = getch()) == (wint_t) ERR) {
#endif
+ if (sig_die)
+ break;
if (sig_resize) {
resize();
continue;
beep();
}
+ if (sig_die)
+ die_on_signal();
+
rc = strlen(edit->buf); /* success */
done:
move(ln, 0);
ui_draw_menu(cf);
refresh();
- do {
+ while (!sig_die) {
int key = getch();
+ if (sig_die)
+ break;
if (sig_resize)
ui_menu_resize(cf);
if (ui_menu_move(cf, key) == 0)
case 'Q':
goto done;
}
- } while (1);
+ }
+ if (sig_die)
+ die_on_signal();
done:
menu_pop(cf);
if (codetypes) {
ui_info(_("Device does not contain a recognized partition table."));
- do {
+ while (!sig_die) {
int key;
if (refresh_menu) {
key = getch();
+ if (sig_die)
+ break;
if (sig_resize)
ui_menu_resize(cf);
if (ui_menu_move(cf, key) == 0)
refresh_menu = 1;
break;
}
- } while (1);
+ }
+ if (sig_die)
+ die_on_signal();
done:
menu_pop(cf);
free(cm);
ui_info(_("Press a key to continue."));
getch();
+
+ if (sig_die)
+ die_on_signal();
return 0;
}
else if (cf->wrong_order)
ui_info(_("Note that partition table entries are not in disk order now."));
- do {
+ while (!sig_die) {
int key = getch();
rc = 0;
+
+ if (sig_die)
+ break;
if (sig_resize)
/* Note that ncurses getch() returns ERR when interrupted
* by signal, but SLang does not interrupt at all. */
if (rc == 1)
break; /* quit */
- } while (1);
+ }
menu_pop(cf);