All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bernhard Voelker <mail@bernhard-voelker.de>
To: "Karel Zak" <kzak@redhat.com>, "Pádraig Brady" <P@draigBrady.com>
Cc: "util-linux@vger.kernel.org" <util-linux@vger.kernel.org>
Subject: Re: fallocate: --punch option parsing error diagnostics irritating
Date: Thu, 26 Jun 2014 14:14:01 +0200	[thread overview]
Message-ID: <53AC0E89.4020300@bernhard-voelker.de> (raw)
In-Reply-To: <20140626110702.GA750@x2.net.home>

On 06/26/2014 01:07 PM, Karel Zak wrote:
>   Applied, thanks.

Thanks!

Now, the optind check is too late in those 2 invalid cases:

   $ ./fallocate
   fallocate: no length argument specified

   $ ./fallocate file1 file2
   fallocate: no length argument specified

The patch below fixes it.

BTW: I think fallocate(1) shouldn't open(...,O_CREAT)
with -d, -p, and maybe with -z, should it?

Have a nice day,
Berny

 From d4b880a188517e12aead021bcee01630e2893e03 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <mail@bernhard-voelker.de>
Date: Thu, 26 Jun 2014 14:09:47 +0200
Subject: [PATCH] fallocate: fix check of number of arguments

Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
---
  sys-utils/fallocate.c | 18 +++++++++---------
  1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c
index 91dee41..5abe3eb 100644
--- a/sys-utils/fallocate.c
+++ b/sys-utils/fallocate.c
@@ -339,6 +339,15 @@ int main(int argc, char **argv)
  			break;
  		}
  	}
+
+	if (optind == argc)
+		errx(EXIT_FAILURE, _("no filename specified"));
+
+	filename = argv[optind++];
+
+	if (optind != argc)
+		errx(EXIT_FAILURE, _("unexpected number of arguments"));
+
  	if (dig) {
  		/* for --dig-holes the default is analyze all file */
  		if (length == -2LL)
@@ -354,15 +363,6 @@ int main(int argc, char **argv)
  	}
  	if (offset < 0)
  		errx(EXIT_FAILURE, _("invalid offset value specified"));
-	if (optind == argc)
-		errx(EXIT_FAILURE, _("no filename specified."));
-
-	filename = argv[optind++];
-
-	if (optind != argc) {
-		warnx(_("unexpected number of arguments"));
-		usage(stderr);
-	}

  	fd = open(filename, O_RDWR|O_CREAT, 0644);
  	if (fd < 0)
-- 
1.8.4.2

  reply	other threads:[~2014-06-26 12:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-25 20:16 fallocate: --punch option parsing error diagnostics irritating Bernhard Voelker
2014-06-25 20:35 ` Dale R. Worley
2014-06-26 10:10 ` Karel Zak
2014-06-26 10:52   ` Pádraig Brady
2014-06-26 11:07     ` Karel Zak
2014-06-26 12:14       ` Bernhard Voelker [this message]
2014-06-26 12:49         ` 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=53AC0E89.4020300@bernhard-voelker.de \
    --to=mail@bernhard-voelker.de \
    --cc=P@draigBrady.com \
    --cc=kzak@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.