All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sami Kerola <kerolasa@iki.fi>
To: util-linux@vger.kernel.org, Karel Zak <kzak@redhat.com>
Cc: kerolasa@iki.fi
Subject: Re: [PATCH 01/10] findfs: use symbolic exit values, and tell about them in manual
Date: Thu, 13 Mar 2014 16:49:06 +0000	[thread overview]
Message-ID: <1394729346-2440-1-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1394397023-7050-1-git-send-email-kerolasa@iki.fi> <20140312103712.GK9303@x2.net.home>

On 12 March 2014 10:37, Karel Zak <kzak@redhat.com> wrote:
>  Do we really need to add findfs exit codes to exitcodes.h? The
>  codes are specific to findfs and no shared anywhere.
>
>  It would be also better to use FINDFS_EX_{SUCCESS,NOTFOUND,USAGE}.

Hi Karel,

Oh, I see.  I misunderstood exitcodes.h, the modified change adds a hint
to the file how to use it.

BTW I am 98.5% certain the findfs was the last utility to use none binary
exit values and have them as numbers in source.  Getting rid of such
magic was the original reason of the change.

--->8----
From: Sami Kerola <kerolasa@iki.fi>
Date: Sun, 9 Mar 2014 10:49:44 -0500
Subject: [PATCH] findfs: use symbolic exit values, and tell about them in manual
Organization: lastminute.com

And mention the exitcodes.h is meant to be used when same exit codes are
used in multiple utilities.  See reference for advice about this.

Reference: http://www.spinics.net/lists/util-linux-ng/msg08970.html
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 include/exitcodes.h |  1 +
 misc-utils/findfs.8 | 30 ++++++++++++++++++++++++++----
 misc-utils/findfs.c | 17 +++++++++++------
 3 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/include/exitcodes.h b/include/exitcodes.h
index 24ee123..b7f37cd 100644
--- a/include/exitcodes.h
+++ b/include/exitcodes.h
@@ -3,6 +3,7 @@
 /*
  * BE CAREFUL
  *
+ * Exit codes in this file are shared in multiple utilities.
  * These exit codes are part of the official interface for mount,
  * fsck, mkfs, etc. wrappers.
  */
diff --git a/misc-utils/findfs.8 b/misc-utils/findfs.8
index 8a6bca1..1469df2 100644
--- a/misc-utils/findfs.8
+++ b/misc-utils/findfs.8
@@ -2,7 +2,7 @@
 .\" Copyright 1993, 1994, 1995 by Theodore Ts'o.  All Rights Reserved.
 .\" This file may be copied under the terms of the GNU Public License.
 .\"
-.TH FINDFS 8 "February 2009" "util-linux" "System Administration"
+.TH FINDFS 8 "March 2014" "util-linux" "System Administration"
 .SH NAME
 findfs \- find a filesystem by label or UUID
 .SH SYNOPSIS
@@ -21,10 +21,30 @@ or a UUID equal to
 If the filesystem is found, the device name for the filesystem will
 be printed on stdout.
 .PP
+.SH "EXIT STATUS"
+.RS
+.PD 0
+.TP
+.B 0
+success
+.TP
+.B 1
+label or uuid cannot be found
+.TP
+.B 2
+usage error, wrong number of arguments or unknown option
+.PD
+.RE
 .SH AUTHOR
 .B findfs
-was originally written by Theodore Ts'o (tytso@mit.edu) and re-written for
-the util-linux package by Karel Zak (kzak@redhat.com).
+was originally written by
+.MT tytso@mit.edu
+Theodore Ts'o
+.ME
+and re-written for the util-linux package by
+.MT kzak@redhat.com
+Karel Zak
+.ME .
 .SH ENVIRONMENT
 .IP LIBBLKID_DEBUG=0xffff
 enables debug output.
@@ -33,4 +53,6 @@ enables debug output.
 .BR fsck (8)
 .SH AVAILABILITY
 The findfs command is part of the util-linux package and is available from
-ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
+.UR ftp://\:ftp.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
+Linux Kernel Archive
+.UE .
diff --git a/misc-utils/findfs.c b/misc-utils/findfs.c
index bc4a843..5c834cc 100644
--- a/misc-utils/findfs.c
+++ b/misc-utils/findfs.c
@@ -14,6 +14,11 @@
 #include "nls.h"
 #include "closestream.h"
 #include "c.h"
+#include "exitcodes.h"
+
+#define FINDFS_EX_SUCCESS	0	/* no errors */
+#define FINDFS_EX_NOTFOUND	1	/* label or uuid cannot be found */
+#define FINDFS_EX_USAGE		2	/* user did something unexpected */
 
 static void __attribute__((__noreturn__)) usage(int rc)
 {
@@ -41,7 +46,7 @@ int main(int argc, char **argv)
 	if (argc != 2)
 		/* we return '2' for backward compatibility
 		 * with version from e2fsprogs */
-		usage(2);
+		usage(FINDFS_EX_USAGE);
 
 	if (!strncmp(argv[1], "LABEL=", 6)) {
 		tk = "LABEL";
@@ -52,18 +57,18 @@ int main(int argc, char **argv)
 	} else if (strcmp(argv[1], "-V") == 0 ||
 		   strcmp(argv[1], "--version") == 0) {
 		printf(UTIL_LINUX_VERSION);
-		return EXIT_SUCCESS;
+		return FINDFS_EX_SUCCESS;
 	} else if (strcmp(argv[1], "-h") == 0 ||
 		   strcmp(argv[1], "--help") == 0) {
-		usage(EXIT_SUCCESS);
+		usage(FINDFS_EX_SUCCESS);
 	} else
-		usage(2);
+		usage(FINDFS_EX_USAGE);
 
 	dev = blkid_evaluate_tag(tk, vl, NULL);
 	if (!dev)
-		errx(EXIT_FAILURE, _("unable to resolve '%s'"),	argv[1]);
+		errx(FINDFS_EX_NOTFOUND, _("unable to resolve '%s'"), argv[1]);
 
 	puts(dev);
-	exit(EXIT_SUCCESS);
+	return FINDFS_EX_SUCCESS;
 }
 
-- 
1.9.0


  parent reply	other threads:[~2014-03-13 16:49 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-09 20:30 [PATCH 01/10] findfs: use symbolic exit values, and tell about them in manual Sami Kerola
2014-03-09 20:30 ` [PATCH 02/10] kill: fix coding style Sami Kerola
2014-04-07  9:36   ` Karel Zak
2014-04-07 14:09     ` Sami Kerola
2014-03-09 20:30 ` [PATCH 03/10] kill: flip all comparions to be in smaller - greater order Sami Kerola
2014-03-19 12:32   ` Benno Schulenberg
2014-03-19 19:35     ` Sami Kerola
2014-03-19 20:30       ` Benno Schulenberg
2014-03-09 20:30 ` [PATCH 04/10] kill: move magic numbers in beginning of the file Sami Kerola
2014-03-09 20:30 ` [PATCH 05/10] kill: make usage() not to return Sami Kerola
2014-03-19 12:37   ` Benno Schulenberg
2014-03-19 19:02     ` Sami Kerola
2014-03-09 20:30 ` [PATCH 06/10] kill: leeway deprecation of --pid invocation as command name Sami Kerola
2014-03-11  7:21   ` Bernhard Voelker
2014-03-11 12:13     ` Sami Kerola
2014-04-07  8:30   ` Karel Zak
2014-03-09 20:30 ` [PATCH 07/10] kill: use control structure to pass user input to functions Sami Kerola
2014-04-07  9:28   ` Karel Zak
2014-03-09 20:30 ` [PATCH 08/10] kill: tell what is wrong rather than output usage() Sami Kerola
2014-03-09 20:30 ` [PATCH 09/10] kill: add parse_arguments() function Sami Kerola
2014-03-09 20:30 ` [PATCH 10/10] kill: move sigqueue inputs to control struct Sami Kerola
2014-03-12 10:37 ` [PATCH 01/10] findfs: use symbolic exit values, and tell about them in manual Karel Zak
2014-03-13 16:49 ` Sami Kerola [this message]
2014-03-26 11:19 ` 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=1394729346-2440-1-git-send-email-kerolasa@iki.fi \
    --to=kerolasa@iki.fi \
    --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.