From: Andreas Henriksson <andreas@fatal.se>
To: util-linux@vger.kernel.org
Cc: Andreas Henriksson <andreas@fatal.se>
Subject: [PATCH] blkid: exit 2 when no specified tags match
Date: Thu, 1 Jan 2015 23:13:34 +0100 [thread overview]
Message-ID: <1420150414-7628-1-git-send-email-andreas@fatal.se> (raw)
,---- [ 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@debian.org>
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
next reply other threads:[~2015-01-01 22:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-01 22:13 Andreas Henriksson [this message]
2015-01-02 11:39 ` [PATCH] blkid: exit 2 when no specified tags match Andreas Henriksson
2015-01-07 9:52 ` Karel Zak
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420150414-7628-1-git-send-email-andreas@fatal.se \
--to=andreas@fatal.se \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).