public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org
Cc: kerolasa@iki.fi
Subject: [PATCH 05/13] fsfreeze: tell user when mandatory option is not specified
Date: Tue,  2 Apr 2013 20:42:49 +0100	[thread overview]
Message-ID: <1364931777-2645-6-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1364931777-2645-1-git-send-email-kerolasa@iki.fi>

This commit also removes use of internal magic values by replacing them
with a enum definition.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 sys-utils/fsfreeze.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/sys-utils/fsfreeze.c b/sys-utils/fsfreeze.c
index 122d95c..961f8c1 100644
--- a/sys-utils/fsfreeze.c
+++ b/sys-utils/fsfreeze.c
@@ -27,6 +27,12 @@
 #include "closestream.h"
 #include "optutils.h"
 
+enum fs_operation {
+	NOOP,
+	FREEZE,
+	UNFREEZE
+};
+
 static int freeze_f(int fd)
 {
 	return ioctl(fd, FIFREEZE, 0);
@@ -56,7 +62,7 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 int main(int argc, char **argv)
 {
 	int fd = -1, c;
-	int freeze = -1, rc = EXIT_FAILURE;
+	int action = NOOP, rc = EXIT_FAILURE;
 	char *path;
 	struct stat sb;
 
@@ -88,10 +94,10 @@ int main(int argc, char **argv)
 			usage(stdout);
 			break;
 		case 'f':
-			freeze = TRUE;
+			action = FREEZE;
 			break;
 		case 'u':
-			freeze = FALSE;
+			action = UNFREEZE;
 			break;
 		case 'V':
 			printf(UTIL_LINUX_VERSION);
@@ -102,8 +108,8 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if (freeze == -1)
-		usage(stderr);
+	if (action == NOOP)
+		errx(EXIT_FAILURE, _("neither --freeze or --unfreeze specified"));
 	if (optind == argc)
 		errx(EXIT_FAILURE, _("no filename specified"));
 	path = argv[optind++];
@@ -127,16 +133,21 @@ int main(int argc, char **argv)
 		goto done;
 	}
 
-	if (freeze) {
+	switch (action) {
+	case FREEZE:
 		if (freeze_f(fd)) {
 			warn(_("%s: freeze failed"), path);
 			goto done;
 		}
-	} else {
+		break;
+	case UNFREEZE:
 		if (unfreeze_f(fd)) {
 			warn(_("%s: unfreeze failed"), path);
 			goto done;
 		}
+		break;
+	default:
+		abort();
 	}
 
 	rc = EXIT_SUCCESS;
-- 
1.8.2


  parent reply	other threads:[~2013-04-02 19:43 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-02 19:42 [PATCH 00/13] pull: fixes in preparation to v2.23 release Sami Kerola
2013-04-02 19:42 ` [PATCH 01/13] docs: fix type in mkfs.8 Sami Kerola
2013-04-02 19:42 ` [PATCH 02/13] newgrp: use xstrdup to check allocation succeeded Sami Kerola
2013-04-02 19:42 ` [PATCH 03/13] agetty: the command does not have -h and -V options Sami Kerola
2013-04-02 19:42 ` [PATCH 04/13] dmesg: fix usage() output consistancy Sami Kerola
2013-04-02 19:42 ` Sami Kerola [this message]
2013-04-02 19:42 ` [PATCH 06/13] losetup: allow -j option argument to be relative path Sami Kerola
2013-04-02 19:42 ` [PATCH 07/13] lscpu: fix error message Sami Kerola
2013-04-02 19:42 ` [PATCH 08/13] partx: remove deprecated option from usage() Sami Kerola
2013-04-02 19:42 ` [PATCH 09/13] setarch: add option to list settable architectures Sami Kerola
2013-04-05 12:04   ` Karel Zak
2013-04-02 19:42 ` [PATCH 10/13] setterm: fix various color option argument lists Sami Kerola
2013-04-02 19:42 ` [PATCH 11/13] vipw: add usage() function Sami Kerola
2013-04-02 19:42 ` [PATCH 12/13] chrt: make command syntax easier to understand in usage() Sami Kerola
2013-04-02 19:42 ` [PATCH 13/13] logger: make local sockets to try both stream and datagram Sami Kerola
2013-04-05 12:10 ` [PATCH 00/13] pull: fixes in preparation to v2.23 release 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=1364931777-2645-6-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --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