diff options
author | Karel Zak | 2017-08-24 15:37:16 +0200 |
---|---|---|
committer | Karel Zak | 2017-08-24 15:48:46 +0200 |
commit | c1154128db5f2359d7825d048134ac262af10b6b (patch) | |
tree | dd4bdcdb683cf78a9cfa4b4fe93f33bfe72a7c87 /disk-utils/fdisk-menu.c | |
parent | fdisk: handle SIGINT in dialogs as cancel (diff) | |
download | kernel-qcow2-util-linux-c1154128db5f2359d7825d048134ac262af10b6b.tar.gz kernel-qcow2-util-linux-c1154128db5f2359d7825d048134ac262af10b6b.tar.xz kernel-qcow2-util-linux-c1154128db5f2359d7825d048134ac262af10b6b.zip |
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 <kzak@redhat.com>
Diffstat (limited to 'disk-utils/fdisk-menu.c')
-rw-r--r-- | disk-utils/fdisk-menu.c | 19 |
1 files changed, 16 insertions, 3 deletions
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); |