util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Uzel <petr.uzel@suse.cz>
To: util-linux <util-linux@vger.kernel.org>
Subject: [PATCH 2/2] blkid: introduce symbolic names for different blkid exit codes
Date: Wed, 16 May 2012 10:38:32 +0200	[thread overview]
Message-ID: <1337157512-31920-2-git-send-email-petr.uzel@suse.cz> (raw)
In-Reply-To: <1337157512-31920-1-git-send-email-petr.uzel@suse.cz>


Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
---
 misc-utils/blkid.c |   32 ++++++++++++++++++--------------
 1 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 4f7050f..52b2a4b 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -34,11 +34,15 @@ extern int optind;
 #define LOWPROBE_TOPOLOGY	(1 << 1)
 #define LOWPROBE_SUPERBLOCKS	(1 << 2)
 
+#define BLKID_EXIT_NOTFOUND	2	/* token or device not found */
+#define BLKID_EXIT_OTHER	4	/* bad usage or other error */
+#define BLKID_EXIT_AMBIVAL	8	/* ambivalent low-level probing detected */
+
 #include <blkid.h>
 
 #include "ismounted.h"
 
-#define STRTOXX_EXIT_CODE	4		/* strtoxx_or_err() */
+#define STRTOXX_EXIT_CODE	BLKID_EXIT_OTHER	/* strtoxx_or_err() */
 #include "strutils.h"
 #include "closestream.h"
 #include "ttyutils.h"
@@ -484,7 +488,7 @@ static int lowprobe_device(blkid_probe pr, const char *devname,
 	fd = open(devname, O_RDONLY);
 	if (fd < 0) {
 		fprintf(stderr, "error: %s: %m\n", devname);
-		return 2;
+		return BLKID_EXIT_NOTFOUND;
 	}
 	if (blkid_probe_set_device(pr, fd, offset, size))
 		goto done;
@@ -551,9 +555,9 @@ done:
 	close(fd);
 
 	if (rc == -2)
-		return 8;	/* ambivalent probing result */
+		return BLKID_EXIT_AMBIVAL;	/* ambivalent probing result */
 	if (!nvals)
-		return 2;	/* nothing detected */
+		return BLKID_EXIT_NOTFOUND;	/* nothing detected */
 
 	return 0;		/* success */
 }
@@ -591,7 +595,7 @@ err:
 	*flag = 0;
 	fprintf(stderr, "unknown kerword in -u <list> argument: '%s'\n",
 			word ? word : list);
-	exit(4);
+	exit(BLKID_EXIT_OTHER);
 }
 
 /* converts comma separated list to types[] */
@@ -633,7 +637,7 @@ err_mem:
 err:
 	*flag = 0;
 	free(res);
-	exit(4);
+	exit(BLKID_EXIT_OTHER);
 }
 
 static void free_types_list(char *list[])
@@ -659,7 +663,7 @@ int main(int argc, char **argv)
 	int fltr_flag = BLKID_FLTR_ONLYIN;
 	unsigned int numdev = 0, numtag = 0;
 	int version = 0;
-	int err = 4;
+	int err = BLKID_EXIT_OTHER;
 	unsigned int i;
 	int output_format = 0;
 	int lookup = 0, gc = 0, lowprobe = 0, eval = 0;
@@ -688,14 +692,14 @@ int main(int argc, char **argv)
 		case 'n':
 			if (fltr_usage) {
 				fprintf(stderr, "error: -u and -n options are mutually exclusive\n");
-				exit(4);
+				exit(BLKID_EXIT_OTHER);
 			}
 			fltr_type = list_to_types(optarg, &fltr_flag);
 			break;
 		case 'u':
 			if (fltr_type) {
 				fprintf(stderr, "error: -u and -n options are mutually exclusive\n");
-				exit(4);
+				exit(BLKID_EXIT_OTHER);
 			}
 			fltr_usage = list_to_usage(optarg, &fltr_flag);
 			break;
@@ -739,7 +743,7 @@ int main(int argc, char **argv)
 				fprintf(stderr, "Invalid output format %s. "
 					"Choose from value,\n\t"
 					"device, list, udev or full\n", optarg);
-				exit(4);
+				exit(BLKID_EXIT_OTHER);
 			}
 			break;
 		case 'O':
@@ -818,13 +822,13 @@ int main(int argc, char **argv)
 		err = 0;
 		goto exit;
 	}
-	err = 2;
+	err = BLKID_EXIT_NOTFOUND;
 
 	if (eval == 0 && (output_format & OUTPUT_PRETTY_LIST)) {
 		if (lowprobe) {
 			fprintf(stderr, "The low-level probing mode does not "
 					"support 'list' output format\n");
-			exit(4);
+			exit(BLKID_EXIT_OTHER);
 		}
 		pretty_print_dev(NULL);
 	}
@@ -838,7 +842,7 @@ int main(int argc, char **argv)
 		if (!numdev) {
 			fprintf(stderr, "The low-level probing mode "
 					"requires a device\n");
-			exit(4);
+			exit(BLKID_EXIT_OTHER);
 		}
 
 		/* automatically enable 'export' format for I/O Limits */
@@ -888,7 +892,7 @@ int main(int argc, char **argv)
 		if (!search_type) {
 			fprintf(stderr, "The lookup option requires a "
 				"search type specified using -t\n");
-			exit(4);
+			exit(BLKID_EXIT_OTHER);
 		}
 		/* Load any additional devices not in the cache */
 		for (i = 0; i < numdev; i++)
-- 
1.7.7


  reply	other threads:[~2012-05-16  8:38 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-16  8:38 [PATCH 1/2] blkid: use symbolic exit code Petr Uzel
2012-05-16  8:38 ` Petr Uzel [this message]
2012-05-16  8:52   ` [PATCH 2/2] blkid: introduce symbolic names for different blkid exit codes Voelker, Bernhard
2012-05-16  9:24     ` Petr Uzel
2012-05-16 10:13       ` Karel Zak
2012-05-16 11:18         ` Voelker, Bernhard
2012-05-17  7:37         ` [PATCH] blkid: stop device probing if error is detected Petr Uzel
2012-05-23  7:46           ` Karel Zak
2012-05-23  7:46   ` [PATCH 2/2] blkid: introduce symbolic names for different blkid exit codes Karel Zak
2012-05-23  7:45 ` [PATCH 1/2] blkid: use symbolic exit code 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=1337157512-31920-2-git-send-email-petr.uzel@suse.cz \
    --to=petr.uzel@suse.cz \
    --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).