Blob Blame Raw
From 0d5a11f41afe14f779908fbc366c492b818a0864 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Wed, 6 Mar 2013 11:32:32 +0100
Subject: [PATCH 3/4] Correct quotasync exit code
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This fixes `quotasync -h' exit code as well as it uses more portable
EXIT_SUCCESS/EXIT_FAILURE values.

Signed-off-by: Petr Písař <ppisar@redhat.com>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 quotasync.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/quotasync.c b/quotasync.c
index cab9015..cfc3f2d 100644
--- a/quotasync.c
+++ b/quotasync.c
@@ -20,7 +20,7 @@ static char **mnt;
 static int mntcnt;
 char *progname;
 
-static void usage(void)
+static void usage(int status)
 {
 	printf(_(
 "%1$s: Utility for syncing quotas.\n"
@@ -39,7 +39,7 @@ static void usage(void)
 "\n"
 		));
 	printf(_("Report bugs to <%s>.\n"), MY_EMAIL);
-	exit(1);
+	exit(status);
 }
 
 static void parse_options(int argcnt, char **argstr)
@@ -57,11 +57,12 @@ static void parse_options(int argcnt, char **argstr)
 	while ((ret = getopt_long(argcnt, argstr, "ahugV", long_opts, NULL)) != -1) {
 		switch (ret) {
 			case '?':
+				usage(EXIT_FAILURE);
 			case 'h':
-				usage();
+				usage(EXIT_SUCCESS);
 			case 'V':
 				version();
-				exit(0);
+				exit(EXIT_SUCCESS);
 			case 'u':
 				flags |= FL_USER;
 				break;
@@ -77,7 +78,7 @@ static void parse_options(int argcnt, char **argstr)
 	if ((flags & FL_ALL && optind != argcnt) ||
 	    (!(flags & FL_ALL) && optind == argcnt)) {
 		fputs(_("Bad number of arguments.\n"), stderr);
-		usage();
+		usage(EXIT_FAILURE);
 	}
 	if (!(flags & FL_ALL)) {
 		mnt = argstr + optind;
@@ -100,10 +101,12 @@ static int syncquotas(int type)
 	int i, ret = 0;
 
 	if (flags & FL_ALL) {
-		if (sync_one(type, NULL) < 0)
+		if (sync_one(type, NULL) < 0) {
 			errstr(_("%s quota sync failed: %s\n"), _(type2name(type)),
 					strerror(errno));
-		return -1;
+			ret = -1;
+		}
+		return ret;
 	}
 
 	handles = create_handle_list(mntcnt, mnt, type, fmt,
@@ -124,7 +127,7 @@ static int syncquotas(int type)
 
 int main(int argc, char **argv)
 {
-	int ret = 0;
+	int ret = EXIT_SUCCESS;
 
 	gettexton();
 	progname = basename(argv[0]);
@@ -134,9 +137,9 @@ int main(int argc, char **argv)
 
 	if (flags & FL_USER)
 		if (syncquotas(USRQUOTA))
-			ret = 1;
+			ret = EXIT_FAILURE;
 	if (flags & FL_GROUP)
 		if (syncquotas(GRPQUOTA))
-			ret = 1;
+			ret = EXIT_FAILURE;
 	return ret;
 }
-- 
1.8.1.4