* [PATCH] blkid: exit 2 when no specified tags match
@ 2015-01-01 22:13 Andreas Henriksson
2015-01-02 11:39 ` Andreas Henriksson
2015-01-07 9:52 ` Karel Zak
0 siblings, 2 replies; 3+ messages in thread
From: Andreas Henriksson @ 2015-01-01 22:13 UTC (permalink / raw)
To: util-linux; +Cc: Andreas Henriksson
,---- [ 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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] blkid: exit 2 when no specified tags match
2015-01-01 22:13 [PATCH] blkid: exit 2 when no specified tags match Andreas Henriksson
@ 2015-01-02 11:39 ` Andreas Henriksson
2015-01-07 9:52 ` Karel Zak
1 sibling, 0 replies; 3+ messages in thread
From: Andreas Henriksson @ 2015-01-02 11:39 UTC (permalink / raw)
To: util-linux
Hello again!
Sorry, I forgot s-o-b. Added below.
On Thu, Jan 01, 2015 at 11:13:34PM +0100, Andreas Henriksson wrote:
> ,---- [ 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
Signed-off-by: Andreas Henriksson <andreas@fatal.se>
> ---
> 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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] blkid: exit 2 when no specified tags match
2015-01-01 22:13 [PATCH] blkid: exit 2 when no specified tags match Andreas Henriksson
2015-01-02 11:39 ` Andreas Henriksson
@ 2015-01-07 9:52 ` Karel Zak
1 sibling, 0 replies; 3+ messages in thread
From: Karel Zak @ 2015-01-07 9:52 UTC (permalink / raw)
To: Andreas Henriksson; +Cc: util-linux
On Thu, Jan 01, 2015 at 11:13:34PM +0100, Andreas Henriksson wrote:
> ,---- [ 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.
IMHO it works as expected
$ blkid -t TYPE=ext4 &> /dev/null; echo $?
0
$ blkid -t TYPE=foo &> /dev/null; echo $?
2
the return code is no affected by output tags, it means by -s <tag>
$ blkid -t TYPE=ext4 -s DUMMY; echo $?
0
$ blkid -t TYPE=ext4 -s LABEL; echo $?
/dev/sda2: LABEL="boot"
0
maybe we need to improve the man page to make the description more
precise, but code works as expected. It differentiates between device
identification and output stuff.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-01-07 9:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-01 22:13 [PATCH] blkid: exit 2 when no specified tags match Andreas Henriksson
2015-01-02 11:39 ` Andreas Henriksson
2015-01-07 9:52 ` Karel Zak
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).