,---- [ man blkid ] | RETURN CODE | If the specified token was found, or if any tags were shown from (specified) devices, 0 is returned. | If the specified token was not found, or no (specified) devices could be identified, an exit code of 2 is returned. | For usage or other errors, an exit code of 4 is returned. | If the ambivalent low-level probing result was detected, an exit code of 8 is returned. `---- The code doesn't seem to work like described in the (first part of the) second sentence. The exit code is only 2 if *no* tokens was identified, 0 if tokens was found but none matched the filter. This changes the code so that the exit code is 2 if the *specified* tag is not found, as described in the manpage. Reported-by: Michael Prokop <mika@xxxxxxxxxx> Addresses: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=772846 --- misc-utils/blkid.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) WARNING: This is a behaviour change. Maybe it's safer to just change the manpage to document the actual behaviour instead of changing it. Please review carefully and decide if this patch is safe (and correct since it's only been very lightly tested). Further work: The mixed usage of 'tokens' and 'tag(s)' in the manpage confuses me and unless I'm mistaken is sometimes also wrong. Eg. you specify a tag with "-s <tag>", there's no way "specified token" is possible, et.al. It would be welcome if anyone wants to review and improve the manpage to be easier to understand. diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c index 1bd8646..e605df2 100644 --- a/misc-utils/blkid.c +++ b/misc-utils/blkid.c @@ -320,7 +320,7 @@ static void print_value(int output, int num, const char *devname, } } -static void print_tags(blkid_dev dev, char *show[], int output) +static int print_tags(blkid_dev dev, char *show[], int output) { blkid_tag_iterate iter; const char *type, *value, *devname; @@ -328,18 +328,18 @@ static void print_tags(blkid_dev dev, char *show[], int output) static int first = 1; if (!dev) - return; + return 0; if (output & OUTPUT_PRETTY_LIST) { pretty_print_dev(dev); - return; + return 0; } devname = blkid_dev_devname(dev); if (output & OUTPUT_DEVICE_ONLY) { printf("%s\n", devname); - return; + return 0; } iter = blkid_tag_iterate_begin(dev); @@ -362,6 +362,10 @@ static void print_tags(blkid_dev dev, char *show[], int output) printf("\n"); first = 0; } + + if (num > 1) + return 0; + return BLKID_EXIT_NOTFOUND; } @@ -903,8 +907,7 @@ int main(int argc, char **argv) if ((dev = blkid_find_dev_with_tag(cache, search_type, search_value))) { - print_tags(dev, show, output_format); - err = 0; + err = print_tags(dev, show, output_format); } /* If we didn't specify a single device, show all available devices */ } else if (!numdev) { @@ -916,11 +919,14 @@ int main(int argc, char **argv) iter = blkid_dev_iterate_begin(cache); blkid_dev_set_search(iter, search_type, search_value); while (blkid_dev_next(iter, &dev) == 0) { + int tagerr; + dev = blkid_verify(cache, dev); if (!dev) continue; - print_tags(dev, show, output_format); - err = 0; + tagerr = print_tags(dev, show, output_format); + if (err != 0) + err = tagerr; } blkid_dev_iterate_end(iter); /* Add all specified devices to cache (optionally display tags) */ @@ -929,12 +935,15 @@ int main(int argc, char **argv) BLKID_DEV_NORMAL); if (dev) { + int tagerr; + if (search_type && !blkid_dev_has_tag(dev, search_type, search_value)) continue; - print_tags(dev, show, output_format); - err = 0; + tagerr = print_tags(dev, show, output_format); + if (err != 0) + err = tagerr; } } -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html