0713020
From 0d5a11f41afe14f779908fbc366c492b818a0864 Mon Sep 17 00:00:00 2001
0713020
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
0713020
Date: Wed, 6 Mar 2013 11:32:32 +0100
0713020
Subject: [PATCH 3/4] Correct quotasync exit code
0713020
MIME-Version: 1.0
0713020
Content-Type: text/plain; charset=UTF-8
0713020
Content-Transfer-Encoding: 8bit
0713020
0713020
This fixes `quotasync -h' exit code as well as it uses more portable
0713020
EXIT_SUCCESS/EXIT_FAILURE values.
0713020
0713020
Signed-off-by: Petr Písař <ppisar@redhat.com>
0713020
Signed-off-by: Jan Kara <jack@suse.cz>
0713020
---
0713020
 quotasync.c | 23 +++++++++++++----------
0713020
 1 file changed, 13 insertions(+), 10 deletions(-)
0713020
0713020
diff --git a/quotasync.c b/quotasync.c
0713020
index cab9015..cfc3f2d 100644
0713020
--- a/quotasync.c
0713020
+++ b/quotasync.c
0713020
@@ -20,7 +20,7 @@ static char **mnt;
0713020
 static int mntcnt;
0713020
 char *progname;
0713020
 
0713020
-static void usage(void)
0713020
+static void usage(int status)
0713020
 {
0713020
 	printf(_(
0713020
 "%1$s: Utility for syncing quotas.\n"
0713020
@@ -39,7 +39,7 @@ static void usage(void)
0713020
 "\n"
0713020
 		));
0713020
 	printf(_("Report bugs to <%s>.\n"), MY_EMAIL);
0713020
-	exit(1);
0713020
+	exit(status);
0713020
 }
0713020
 
0713020
 static void parse_options(int argcnt, char **argstr)
0713020
@@ -57,11 +57,12 @@ static void parse_options(int argcnt, char **argstr)
0713020
 	while ((ret = getopt_long(argcnt, argstr, "ahugV", long_opts, NULL)) != -1) {
0713020
 		switch (ret) {
0713020
 			case '?':
0713020
+				usage(EXIT_FAILURE);
0713020
 			case 'h':
0713020
-				usage();
0713020
+				usage(EXIT_SUCCESS);
0713020
 			case 'V':
0713020
 				version();
0713020
-				exit(0);
0713020
+				exit(EXIT_SUCCESS);
0713020
 			case 'u':
0713020
 				flags |= FL_USER;
0713020
 				break;
0713020
@@ -77,7 +78,7 @@ static void parse_options(int argcnt, char **argstr)
0713020
 	if ((flags & FL_ALL && optind != argcnt) ||
0713020
 	    (!(flags & FL_ALL) && optind == argcnt)) {
0713020
 		fputs(_("Bad number of arguments.\n"), stderr);
0713020
-		usage();
0713020
+		usage(EXIT_FAILURE);
0713020
 	}
0713020
 	if (!(flags & FL_ALL)) {
0713020
 		mnt = argstr + optind;
0713020
@@ -100,10 +101,12 @@ static int syncquotas(int type)
0713020
 	int i, ret = 0;
0713020
 
0713020
 	if (flags & FL_ALL) {
0713020
-		if (sync_one(type, NULL) < 0)
0713020
+		if (sync_one(type, NULL) < 0) {
0713020
 			errstr(_("%s quota sync failed: %s\n"), _(type2name(type)),
0713020
 					strerror(errno));
0713020
-		return -1;
0713020
+			ret = -1;
0713020
+		}
0713020
+		return ret;
0713020
 	}
0713020
 
0713020
 	handles = create_handle_list(mntcnt, mnt, type, fmt,
0713020
@@ -124,7 +127,7 @@ static int syncquotas(int type)
0713020
 
0713020
 int main(int argc, char **argv)
0713020
 {
0713020
-	int ret = 0;
0713020
+	int ret = EXIT_SUCCESS;
0713020
 
0713020
 	gettexton();
0713020
 	progname = basename(argv[0]);
0713020
@@ -134,9 +137,9 @@ int main(int argc, char **argv)
0713020
 
0713020
 	if (flags & FL_USER)
0713020
 		if (syncquotas(USRQUOTA))
0713020
-			ret = 1;
0713020
+			ret = EXIT_FAILURE;
0713020
 	if (flags & FL_GROUP)
0713020
 		if (syncquotas(GRPQUOTA))
0713020
-			ret = 1;
0713020
+			ret = EXIT_FAILURE;
0713020
 	return ret;
0713020
 }
0713020
-- 
0713020
1.8.1.4
0713020