summaryrefslogtreecommitdiffstats
path: root/fdisks/fdisk-menu.c
diff options
context:
space:
mode:
authorKarel Zak2013-05-17 14:11:51 +0200
committerKarel Zak2013-09-16 16:46:55 +0200
commit3b4f9f16446895de513b6655a48d2e8074aec9b9 (patch)
treed6be5a13932fa16b640b437b49d6f6c50db422a2 /fdisks/fdisk-menu.c
parentfdisk: add sun menu (diff)
downloadkernel-qcow2-util-linux-3b4f9f16446895de513b6655a48d2e8074aec9b9.tar.gz
kernel-qcow2-util-linux-3b4f9f16446895de513b6655a48d2e8074aec9b9.tar.xz
kernel-qcow2-util-linux-3b4f9f16446895de513b6655a48d2e8074aec9b9.zip
fdisk: detect menu entries collisions in debug mode
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'fdisks/fdisk-menu.c')
-rw-r--r--fdisks/fdisk-menu.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/fdisks/fdisk-menu.c b/fdisks/fdisk-menu.c
index 7cbf83b74..09d5ff0c4 100644
--- a/fdisks/fdisk-menu.c
+++ b/fdisks/fdisk-menu.c
@@ -178,11 +178,61 @@ static const struct menu_entry *next_menu_entry(
return NULL;
}
+/* returns @menu and menu entry for then @key */
+static const struct menu_entry *get_fdisk_menu_entry(
+ struct fdisk_context *cxt,
+ int key,
+ const struct menu **menu)
+{
+ struct menu_context mc = MENU_CXT_EMPTY;
+ const struct menu_entry *e;
+
+ while ((e = next_menu_entry(cxt, &mc))) {
+ if (IS_MENU_SEP(e) || e->key != key)
+ continue;
+
+ if (menu)
+ *menu = menus[mc.menu_idx];
+ return e;
+ }
+
+ return NULL;
+}
+
+static int menu_detect_collisions(struct fdisk_context *cxt)
+{
+ struct menu_context mc = MENU_CXT_EMPTY;
+ const struct menu_entry *e, *r;
+
+ while ((e = next_menu_entry(cxt, &mc))) {
+ if (IS_MENU_SEP(e))
+ continue;
+
+ r = get_fdisk_menu_entry(cxt, e->key, NULL);
+ if (!r) {
+ DBG(CONTEXT, dbgprint("warning: not found "
+ "entry for %c", e->key));
+ return -1;
+ }
+ if (r != e) {
+ DBG(CONTEXT, dbgprint("warning: duplicate key '%c'",
+ e->key));
+ DBG(CONTEXT, dbgprint(" %s", e->title));
+ DBG(CONTEXT, dbgprint(" %s", r->title));
+ abort();
+ }
+ }
+
+ return 0;
+}
+
static int print_fdisk_menu(struct fdisk_context *cxt)
{
struct menu_context mc = MENU_CXT_EMPTY;
const struct menu_entry *e;
+ ON_DBG(CONTEXT, menu_detect_collisions(cxt));
+
if (fdisk_context_display_details(cxt))
printf(_("\nExpert commands:\n"));
else