From 4ce48a971d322cc1f690dd036f906fc54261c657 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 14 May 2009 18:04:55 +0200 Subject: [PATCH] blkid: fix "hangs forever with partition type mdraid" > #:> blkid /dev/sda7 > /dev/sda7: UUID="c193d159-1fd4-1a4b-4037-f3433e016f3d" TYPE="mdraid" > > The blkid binary build from the util-linux-ng sources just hangs > forever with 100% cpu load with the same command. Reported-by: Juergen Daubert Signed-off-by: Karel Zak --- shlibs/blkid/src/probe.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c index 0e4745ac..b0c0be80 100644 --- a/shlibs/blkid/src/probe.c +++ b/shlibs/blkid/src/probe.c @@ -160,6 +160,11 @@ static void blkid_probe_reset_vals(blkid_probe pr) pr->nvals = 0; } +static void blkid_probe_reset_idx(blkid_probe pr) +{ + pr->idx = -1; +} + void blkid_reset_probe(blkid_probe pr) { if (!pr) @@ -169,14 +174,13 @@ void blkid_reset_probe(blkid_probe pr) memset(pr->buf, 0, pr->buf_max); pr->buf_off = 0; pr->buf_len = 0; - pr->idx = 0; if (pr->sbbuf) memset(pr->sbbuf, 0, BLKID_SB_BUFSIZ); pr->sbbuf_len = 0; blkid_probe_reset_vals(pr); + blkid_probe_reset_idx(pr); } - /* * Note that we have two offsets: * @@ -263,7 +267,6 @@ int blkid_probe_set_device(blkid_probe pr, int fd, pr->fd = fd; pr->off = off; pr->size = 0; - pr->idx = 0; if (size) pr->size = size; @@ -307,7 +310,7 @@ int blkid_probe_reset_filter(blkid_probe pr) return -1; if (pr->fltr) memset(pr->fltr, 0, BLKID_FLTR_SIZE * sizeof(unsigned long)); - pr->idx = 0; + blkid_probe_reset_idx(pr); return 0; } @@ -324,9 +327,10 @@ int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[]) if (!pr || !names) return -1; - if (!pr->fltr) + if (!pr->fltr) { pr->fltr = calloc(BLKID_FLTR_SIZE, sizeof(unsigned long)); - else + blkid_probe_reset_idx(pr); + } else blkid_probe_reset_filter(pr); if (!pr->fltr) @@ -355,7 +359,6 @@ int blkid_probe_filter_types(blkid_probe pr, int flag, char *names[]) } } DBG(DEBUG_LOWPROBE, printf("a new probing type-filter initialized\n")); - pr->idx = 0; return 0; } @@ -375,9 +378,10 @@ int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage) if (!pr || !usage) return -1; - if (!pr->fltr) + if (!pr->fltr) { pr->fltr = calloc(BLKID_FLTR_SIZE, sizeof(unsigned long)); - else + blkid_probe_reset_idx(pr); + } else blkid_probe_reset_filter(pr); if (!pr->fltr) @@ -393,7 +397,6 @@ int blkid_probe_filter_usage(blkid_probe pr, int flag, int usage) blkid_bmp_set_item(pr->fltr, i); } DBG(DEBUG_LOWPROBE, printf("a new probing usage-filter initialized\n")); - pr->idx = 0; return 0; } @@ -407,8 +410,8 @@ int blkid_probe_invert_filter(blkid_probe pr) for (i = 0; i < BLKID_FLTR_SIZE; i++) pr->fltr[i] = ~pr->fltr[i]; + blkid_probe_reset_idx(pr); DBG(DEBUG_LOWPROBE, printf("probing filter inverted\n")); - pr->idx = 0; return 0; } @@ -455,8 +458,7 @@ int blkid_do_probe(blkid_probe pr) blkid_probe_reset_vals(pr); - if (pr->idx) - i = pr->idx + 1; + i = pr->idx + 1; if (i < 0 && i >= ARRAY_SIZE(idinfos)) return -1; -- 2.39.5