From c1154128db5f2359d7825d048134ac262af10b6b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 24 Aug 2017 15:37:16 +0200 Subject: fdisk: fix readline interaction with signals The high-level readline API is crazy to use with signals. Fortunately the library provides low-level rl_callback_* API. In this case we can use poll() to wait for input and control all signals, etc. This patch also a little changes fdisk behavior on CTRL+C and CTRL+D. The signals does not kill fdisk, but forces fdisk to return to the main menu, if already in the main menu then exit. If the disk layout has been modified than ask "Do you really want to exit...". Signed-off-by: Karel Zak --- disk-utils/fdisk-menu.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'disk-utils/fdisk-menu.c') diff --git a/disk-utils/fdisk-menu.c b/disk-utils/fdisk-menu.c index 8ad0fc1a5..94e00b3fa 100644 --- a/disk-utils/fdisk-menu.c +++ b/disk-utils/fdisk-menu.c @@ -423,11 +423,24 @@ int process_fdisk_menu(struct fdisk_context **cxt0) prompt = _("Command (m for help): "); fputc('\n',stdout); - rc = get_user_reply(cxt, prompt, buf, sizeof(buf)); - if (rc) + rc = get_user_reply(prompt, buf, sizeof(buf)); + + if (rc == -ECANCELED) { + /* Map ^C and ^D in main menu to 'q' */ + if (is_interactive + && fdisk_label_is_changed(fdisk_get_label(cxt, NULL))) { + rc = get_user_reply( + _("\nDo you really want to quit? "), + buf, sizeof(buf)); + if (rc || !rpmatch(buf)) + return 0; + } + key = 'q'; + } else if (rc) { return rc; + } else + key = buf[0]; - key = buf[0]; ent = get_fdisk_menu_entry(cxt, key, &menu); if (!ent) { fdisk_warnx(cxt, _("%c: unknown command"), key); -- cgit v1.2.3-55-g7522