util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/13] usage cleanup part 1
@ 2017-06-22  2:37 Ruediger Meier
  2017-06-22  2:37 ` [PATCH 01/13] uuidd: remove unused define Ruediger Meier
                   ` (13 more replies)
  0 siblings, 14 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

This is pull request #467 on github
https://github.com/karelzak/util-linux/pull/467

The major goal is to avoid printing usage/help messages on stderr.

This is the preparing first part of a bigger patch-set. There are
some minor bug fixes and finally we add --help options to all our
commands (just 5 commands were missing it).

The next completing patch-set (part 2) will be more invasive but
even more trivial.

Ruediger Meier (13):
  uuidd: remove unused define
  misc: remove superfluous null pointer checks for optarg
  misc: fix some broken exit codes
  blkid: use errtryhelp instead of errtryh
  dmesg: do not accept any non-option arguments
  setarch: print usage error if no argument given
  setarch: use errtryhelp()
  fsck: add --help and --version
  login: add --help and --version
  whereis: add --help and --version
  more: add --help and --version
  mkfs.cramfs: add --help and --version
  misc: no more errtryh()

 disk-utils/fsck.8        |  6 ++++++
 disk-utils/fsck.c        | 29 +++++++++++++++++++++--------
 disk-utils/fsck.cramfs.c |  2 +-
 disk-utils/mkfs.cramfs.8 |  8 ++++----
 disk-utils/mkfs.cramfs.c | 35 ++++++++++++++++++++++++-----------
 include/c.h              |  6 ------
 login-utils/chsh.c       |  2 --
 login-utils/login.1      |  5 ++++-
 login-utils/login.c      | 28 ++++++++++++++++++++++------
 login-utils/lslogins.c   | 15 ++++++---------
 misc-utils/blkid.c       |  8 ++++----
 misc-utils/findfs.c      |  4 ++--
 misc-utils/test_uuidd.c  | 25 ++++++++++++++-----------
 misc-utils/uuidd.c       |  6 ------
 misc-utils/whereis.1     |  6 ++++++
 misc-utils/whereis.c     | 48 +++++++++++++++++++++++++++++++++++-------------
 sys-utils/dmesg.c        |  4 +---
 sys-utils/setarch.c      | 22 ++++++----------------
 text-utils/hexdump.c     |  2 +-
 text-utils/more.1        |  6 ++++++
 text-utils/more.c        | 29 ++++++++++++++++++++++-------
 21 files changed, 185 insertions(+), 111 deletions(-)

-- 
1.8.5.6


^ permalink raw reply	[flat|nested] 22+ messages in thread

* [PATCH 01/13] uuidd: remove unused define
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 02/13] misc: remove superfluous null pointer checks for optarg Ruediger Meier
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 misc-utils/uuidd.c | 6 ------
 1 file changed, 6 deletions(-)

diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c
index 313a4af..371975d 100644
--- a/misc-utils/uuidd.c
+++ b/misc-utils/uuidd.c
@@ -41,12 +41,6 @@
 
 #include "nls.h"
 
-#ifdef __GNUC__
-#define CODE_ATTR(x) __attribute__(x)
-#else
-#define CODE_ATTR(x)
-#endif
-
 /* length of textual representation of UUID, including trailing \0 */
 #define UUID_STR_LEN	37
 
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 02/13] misc: remove superfluous null pointer checks for optarg
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
  2017-06-22  2:37 ` [PATCH 01/13] uuidd: remove unused define Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 03/13] misc: fix some broken exit codes Ruediger Meier
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

This is only needed for optional arguments.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 login-utils/chsh.c     |  2 --
 login-utils/lslogins.c | 15 ++++++---------
 text-utils/hexdump.c   |  2 +-
 3 files changed, 7 insertions(+), 12 deletions(-)

diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index 3bea971..10b0bdc 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -235,8 +235,6 @@ static void parse_argv(int argc, char **argv, struct sinfo *pinfo)
 			print_shells();
 			exit(EXIT_SUCCESS);
 		case 's':
-			if (!optarg)
-				usage(stderr);
 			pinfo->shell = optarg;
 			break;
 		default:
diff --git a/login-utils/lslogins.c b/login-utils/lslogins.c
index ab04c10..1e89d27 100644
--- a/login-utils/lslogins.c
+++ b/login-utils/lslogins.c
@@ -1381,15 +1381,12 @@ int main(int argc, char *argv[])
 			outmode = OUT_NEWLINE;
 			break;
 		case 'o':
-			if (optarg) {
-				if (*optarg == '=')
-					optarg++;
-				ncolumns = string_to_idarray(optarg,
-						columns, ARRAY_SIZE(columns),
-						column_name_to_id);
-				if (ncolumns < 0)
-					return EXIT_FAILURE;
-			}
+			if (*optarg == '=')
+				optarg++;
+			ncolumns = string_to_idarray(optarg, columns,
+					ARRAY_SIZE(columns), column_name_to_id);
+			if (ncolumns < 0)
+				return EXIT_FAILURE;
 			opt_o = 1;
 			break;
 		case 'r':
diff --git a/text-utils/hexdump.c b/text-utils/hexdump.c
index 125734d..bf06316 100644
--- a/text-utils/hexdump.c
+++ b/text-utils/hexdump.c
@@ -107,7 +107,7 @@ parse_args(int argc, char **argv, struct hexdump *hex)
 		case 'f':
 			addfile(optarg, hex);
 			break;
-                case 'L':
+		case 'L':
 			colormode = UL_COLORMODE_AUTO;
 			if (optarg)
 				colormode = colormode_or_err(optarg,
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 03/13] misc: fix some broken exit codes
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
  2017-06-22  2:37 ` [PATCH 01/13] uuidd: remove unused define Ruediger Meier
  2017-06-22  2:37 ` [PATCH 02/13] misc: remove superfluous null pointer checks for optarg Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22 20:49   ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 04/13] blkid: use errtryhelp instead of errtryh Ruediger Meier
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

These tools have special exit codes. They got changed mistakenly.

See:
  findfs       0e1fa6b6
  fsck         658c0891
  fsck.cramfs  922ec175
  mkfs.cramfs  16154b1f

FIXME: STRTOXX_EXIT_CODE doesn't work as it should.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 disk-utils/fsck.c        | 2 +-
 disk-utils/fsck.cramfs.c | 2 +-
 disk-utils/mkfs.cramfs.c | 2 +-
 misc-utils/findfs.c      | 4 ++--
 4 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c
index cb1b212..5a418fc 100644
--- a/disk-utils/fsck.c
+++ b/disk-utils/fsck.c
@@ -55,7 +55,7 @@
 #include "fileutils.h"
 #include "monotonic.h"
 
-#define STRTOXX_EXIT_CODE	FSCK_EX_ERROR
+#define STRTOXX_EXIT_CODE	FSCK_EX_USAGE
 #include "strutils.h"
 
 #define XALLOC_EXIT_CODE	FSCK_EX_ERROR
diff --git a/disk-utils/fsck.cramfs.c b/disk-utils/fsck.cramfs.c
index 63033d6..952f153 100644
--- a/disk-utils/fsck.cramfs.c
+++ b/disk-utils/fsck.cramfs.c
@@ -671,7 +671,7 @@ int main(int argc, char **argv)
 			break;
 		case 'V':
 			printf(UTIL_LINUX_VERSION);
-			return EXIT_SUCCESS;
+			return FSCK_EX_OK;
 		case 'x':
 			opt_extract = 1;
 			if(optarg)
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index 77b4467..041c6d7 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -910,5 +910,5 @@ int main(int argc, char **argv)
 	    (warn_namelen|warn_skip|warn_size|warn_uid|warn_gid|warn_dev))
 		exit(MKFS_EX_ERROR);
 
-	return EXIT_SUCCESS;
+	return MKFS_EX_OK;
 }
diff --git a/misc-utils/findfs.c b/misc-utils/findfs.c
index 7935232..7d2d803 100644
--- a/misc-utils/findfs.c
+++ b/misc-utils/findfs.c
@@ -63,11 +63,11 @@ int main(int argc, char **argv)
 		switch (c) {
 		case 'V':
 			printf(UTIL_LINUX_VERSION);
-			return EXIT_SUCCESS;
+			return FINDFS_SUCCESS;
 		case 'h':
 			usage(FINDFS_SUCCESS);
 		default:
-			errtryhelp(EXIT_FAILURE);
+			errtryhelp(FINDFS_USAGE_ERROR);
 		}
 
 	dev = blkid_evaluate_tag(argv[1], NULL, NULL);
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 04/13] blkid: use errtryhelp instead of errtryh
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (2 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 03/13] misc: fix some broken exit codes Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 05/13] dmesg: do not accept any non-option arguments Ruediger Meier
                   ` (9 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

We have a --help option and this is preferred.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 misc-utils/blkid.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 1dc8f40..f95f673 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -762,7 +762,7 @@ int main(int argc, char **argv)
 		case 's':
 			if (numtag + 1 >= sizeof(ctl.show) / sizeof(*ctl.show)) {
 				warnx(_("Too many tags specified"));
-				errtryh(err);
+				errtryhelp(err);
 			}
 			ctl.show[numtag++] = optarg;
 			break;
@@ -773,13 +773,13 @@ int main(int argc, char **argv)
 			if (search_type) {
 				warnx(_("Can only search for "
 					"one NAME=value pair"));
-				errtryh(err);
+				errtryhelp(err);
 			}
 			if (blkid_parse_tag_string(optarg,
 						   &search_type,
 						   &search_value)) {
 				warnx(_("-t needs NAME=value pair"));
-				errtryh(err);
+				errtryhelp(err);
 			}
 			break;
 		case 'V':
@@ -794,7 +794,7 @@ int main(int argc, char **argv)
 			usage(0);
 			break;
 		default:
-			errtryh(EXIT_FAILURE);
+			errtryhelp(EXIT_FAILURE);
 		}
 	}
 
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 05/13] dmesg: do not accept any non-option arguments
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (3 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 04/13] blkid: use errtryhelp instead of errtryh Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 06/13] setarch: print usage error if no argument given Ruediger Meier
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

'dmesg foo' is no valid syntax and gives an error now.
BTW we avoid the "dead increment of argc and argv.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 sys-utils/dmesg.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/sys-utils/dmesg.c b/sys-utils/dmesg.c
index b83cfb1..5be4ff6 100644
--- a/sys-utils/dmesg.c
+++ b/sys-utils/dmesg.c
@@ -1486,10 +1486,8 @@ int main(int argc, char *argv[])
 			errtryhelp(EXIT_FAILURE);
 		}
 	}
-	argc -= optind;
-	argv += optind;
 
-	if (argc > 1)
+	if (argc != optind)
 		usage(stderr);
 
 	if ((is_timefmt(&ctl, RELTIME) ||
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 06/13] setarch: print usage error if no argument given
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (4 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 05/13] dmesg: do not accept any non-option arguments Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  8:38   ` Karel Zak
  2017-06-22  2:37 ` [PATCH 07/13] setarch: use errtryhelp() Ruediger Meier
                   ` (7 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

This looks more likely as intended.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 sys-utils/setarch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index eb9cf21..6481eb2 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -301,7 +301,7 @@ int main(int argc, char *argv[])
 	textdomain(PACKAGE);
 	atexit(close_stdout);
 
-	if (argc < 1)
+	if (argc < 2)
 		show_usage(_("Not enough arguments"));
 
 	archwrapper = strcmp(program_invocation_short_name, "setarch") != 0;
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 07/13] setarch: use errtryhelp()
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (5 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 06/13] setarch: print usage error if no argument given Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 08/13] fsck: add --help and --version Ruediger Meier
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 sys-utils/setarch.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
index 6481eb2..9aec34f 100644
--- a/sys-utils/setarch.c
+++ b/sys-utils/setarch.c
@@ -84,7 +84,7 @@
 
 static int archwrapper;
 
-static void __attribute__((__noreturn__)) show_help(void)
+static void __attribute__((__noreturn__)) usage(void)
 {
 	fputs(USAGE_HEADER, stdout);
 	if (!archwrapper)
@@ -121,17 +121,6 @@ static void __attribute__((__noreturn__)) show_help(void)
 	exit(EXIT_SUCCESS);
 }
 
-static void __attribute__((__noreturn__)) show_usage(const char *s)
-{
-	if (s)
-		errx(EXIT_FAILURE,
-		     _("%s\nTry `%s --help' for more information."), s,
-		     program_invocation_short_name);
-	else
-		errx(EXIT_FAILURE, _("Try `%s --help' for more information."),
-		     program_invocation_short_name);
-}
-
 static void __attribute__((__noreturn__))
     show_version(void)
 {
@@ -301,9 +290,10 @@ int main(int argc, char *argv[])
 	textdomain(PACKAGE);
 	atexit(close_stdout);
 
-	if (argc < 2)
-		show_usage(_("Not enough arguments"));
-
+	if (argc < 2) {
+		warnx(_("Not enough arguments"));
+		errtryhelp(EXIT_FAILURE);
+	}
 	archwrapper = strcmp(program_invocation_short_name, "setarch") != 0;
 	if (archwrapper)
 		arch = program_invocation_short_name;	/* symlinks to setarch */
@@ -328,7 +318,7 @@ int main(int argc, char *argv[])
 	while ((c = getopt_long(argc, argv, "+hVv3BFILRSTXZ", longopts, NULL)) != -1) {
 		switch (c) {
 		case 'h':
-			show_help();
+			usage();
 			break;
 		case 'V':
 			show_version();
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 08/13] fsck: add --help and --version
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (6 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 07/13] setarch: use errtryhelp() Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 09/13] login: " Ruediger Meier
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Also cleanup usage() function, never write usage to stderr.

FIXME:
 - currently strtou32_or_err() exits with wrong exit code.
 - option -C does not use a safe strto*_err function

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 disk-utils/fsck.8 |  6 ++++++
 disk-utils/fsck.c | 27 ++++++++++++++++++++-------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/disk-utils/fsck.8 b/disk-utils/fsck.8
index 3148e42..b3096be 100644
--- a/disk-utils/fsck.8
+++ b/disk-utils/fsck.8
@@ -309,6 +309,12 @@ Don't show the title on startup.
 .B \-V
 Produce verbose output, including all filesystem-specific commands
 that are executed.
+.TP
+\fB\-?\fR, \fB\-\-help\fR
+Display help text and exit.
+.TP
+\fB\-\-version\fR
+Display version information and exit.
 .SH FILESYSTEM SPECIFIC OPTIONS
 .B Options which are not understood by fsck are passed to the filesystem-specific checker! 
 .PP
diff --git a/disk-utils/fsck.c b/disk-utils/fsck.c
index 5a418fc..6b8d551 100644
--- a/disk-utils/fsck.c
+++ b/disk-utils/fsck.c
@@ -1369,8 +1369,9 @@ static int check_all(void)
 	return status;
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+	FILE *out = stdout;
 	fputs(USAGE_HEADER, out);
 	fprintf(out, _(" %s [options] -- [fs-options] [<filesystem> ...]\n"),
 			 program_invocation_short_name);
@@ -1393,13 +1394,14 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 	fputs(_(" -t <type>  specify filesystem types to be checked;\n"
 		"            <type> is allowed to be a comma-separated list\n"), out);
 	fputs(_(" -V         explain what is being done\n"), out);
-	fputs(_(" -?         display this help and exit\n"), out);
 
 	fputs(USAGE_SEPARATOR, out);
+	fputs(_(" -?, --help     display this help and exit\n"), out);
+	fputs(_("     --version  output version information and exit\n"), out);
+	fputs(USAGE_SEPARATOR, out);
 	fputs(_("See the specific fsck.* commands for available fs-options."), out);
 	fprintf(out, USAGE_MAN_TAIL("fsck(8)"));
-
-	exit(out == stderr ? FSCK_EX_USAGE : FSCK_EX_OK);
+	exit(FSCK_EX_OK);
 }
 
 static void signal_cancel(int sig __attribute__((__unused__)))
@@ -1433,6 +1435,15 @@ static void parse_argv(int argc, char *argv[])
 		arg = argv[i];
 		if (!arg)
 			continue;
+
+		/* the only two longopts to satisfy UL standards */
+		if (!opts_for_fsck && !strcmp(arg, "--help"))
+			usage();
+		if (!opts_for_fsck && !strcmp(arg, "--version")) {
+			printf(UTIL_LINUX_VERSION);
+			exit(FSCK_EX_OK);
+		}
+
 		if ((arg[0] == '/' && !opts_for_fsck) || strchr(arg, '=')) {
 			if (num_devices >= MAX_DEVICES)
 				errx(FSCK_EX_ERROR, _("too many devices"));
@@ -1536,13 +1547,15 @@ static void parse_argv(int argc, char *argv[])
 			case 't':
 				tmp = NULL;
 				if (fstype)
-					usage(stderr);
+					errx(FSCK_EX_USAGE,
+						_("option '%s' may be specified only once"), "-t");
 				if (arg[j+1])
 					tmp = arg+j+1;
 				else if ((i+1) < argc)
 					tmp = argv[++i];
 				else
-					usage(stderr);
+					errx(FSCK_EX_USAGE,
+						_("option '%s' requires an argument"), "-t");
 				fstype = xstrdup(tmp);
 				compile_fs_type(fstype, &fs_type_compiled);
 				goto next_arg;
@@ -1550,7 +1563,7 @@ static void parse_argv(int argc, char *argv[])
 				opts_for_fsck++;
 				break;
 			case '?':
-				usage(stdout);
+				usage();
 				break;
 			default:
 				options[++opt] = arg[j];
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 09/13] login: add --help and --version
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (7 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 08/13] fsck: add --help and --version Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  8:42   ` Karel Zak
  2017-06-22  2:37 ` [PATCH 10/13] whereis: " Ruediger Meier
                   ` (4 subsequent siblings)
  13 siblings, 1 reply; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Also we don't print the usage text on stderr anymore.

Note, the usage text could be improved, currently it
does not describe any options. I have only added a
pointer to the man page.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 login-utils/login.1 |  5 ++++-
 login-utils/login.c | 28 ++++++++++++++++++++++------
 2 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/login-utils/login.1 b/login-utils/login.1
index 2fc7a50..5d43fdc 100644
--- a/login-utils/login.1
+++ b/login-utils/login.1
@@ -131,7 +131,10 @@ to tell
 .B login
 that printing the hostname should be suppressed in the login: prompt.
 .TP
-.B \-V
+\fB\-\-help\fR
+Display help text and exit.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
 Display version information and exit.
 .SH CONFIG FILE ITEMS
 .B login
diff --git a/login-utils/login.c b/login-utils/login.c
index 37553ef..ee06d03 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -1095,6 +1095,16 @@ static void init_remote_info(struct login_context *cxt, char *remotehost)
 	}
 }
 
+static void __attribute__((__noreturn__)) usage(void)
+{
+	fputs(USAGE_HEADER, stdout);
+	printf(_(" %s [-p] [-h <host>] [-H] [[-f] <username>]\n"), program_invocation_short_name);
+	fputs(USAGE_SEPARATOR, stdout);
+	fputs(_("Begin a session on the system.\n"), stdout);
+	printf(USAGE_MAN_TAIL("login(1)"));
+	exit(EXIT_SUCCESS);
+}
+
 int main(int argc, char **argv)
 {
 	int c;
@@ -1119,6 +1129,14 @@ int main(int argc, char **argv)
 
 	};
 
+	/* the only two longopts to satisfy UL standards */
+	enum { HELP_OPTION = CHAR_MAX + 1 };
+	static const struct option longopts[] = {
+		{"help", no_argument, NULL, HELP_OPTION},
+		{"version", no_argument, NULL, 'V'},
+		{NULL, 0, NULL, 0}
+	};
+
 	timeout = (unsigned int)getlogindefs_num("LOGIN_TIMEOUT", LOGIN_TIMEOUT);
 
 	signal(SIGALRM, timedout);
@@ -1142,7 +1160,7 @@ int main(int argc, char **argv)
 	 * -h is used by other servers to pass the name of the remote
 	 *    host to login so that it may be placed in utmp and wtmp
 	 */
-	while ((c = getopt(argc, argv, "fHh:pV")) != -1)
+	while ((c = getopt_long(argc, argv, "fHh:pV", longopts, NULL)) != -1)
 		switch (c) {
 		case 'f':
 			cxt.noauth = 1;
@@ -1168,12 +1186,10 @@ int main(int argc, char **argv)
 		case 'V':
 			printf(UTIL_LINUX_VERSION);
 			return EXIT_SUCCESS;
-		case '?':
+		case HELP_OPTION:
+			usage();
 		default:
-			fprintf(stderr, _("Usage: login [-p] [-h <host>] [-H] [[-f] <username>]\n"));
-			fputs(USAGE_SEPARATOR, stderr);
-			fputs(_("Begin a session on the system.\n"), stderr);
-			exit(EXIT_FAILURE);
+			errtryhelp(EXIT_FAILURE);
 		}
 	argc -= optind;
 	argv += optind;
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 10/13] whereis: add --help and --version
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (8 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 09/13] login: " Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 11/13] more: " Ruediger Meier
                   ` (3 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

We can use errtryhelp() now and never print usage to stderr.
One may improve all these "bad usage" messages.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 misc-utils/whereis.1 |  6 ++++++
 misc-utils/whereis.c | 48 +++++++++++++++++++++++++++++++++++-------------
 2 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/misc-utils/whereis.1 b/misc-utils/whereis.1
index 6461f26..0d2cbe7 100644
--- a/misc-utils/whereis.1
+++ b/misc-utils/whereis.1
@@ -125,6 +125,12 @@ or
 .BR \-S
 is specified, the option will output the hard-coded paths
 that the command was able to find on the system.
+.TP
+\fB\-h\fR, \fB\-\-help\fR
+Display help text and exit.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Display version information and exit.
 .SH EXAMPLE
 To find all files in
 .I /usr/\:bin
diff --git a/misc-utils/whereis.c b/misc-utils/whereis.c
index b5b35f5..897a7a2 100644
--- a/misc-utils/whereis.c
+++ b/misc-utils/whereis.c
@@ -183,8 +183,10 @@ static const char *whereis_type_to_name(int type)
 	}
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+	FILE *out = stdout;
+
 	fputs(USAGE_HEADER, out);
 	fprintf(out, _(" %s [options] [-BMS <dir>... -f] <name>\n"), program_invocation_short_name);
 
@@ -201,9 +203,12 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 	fputs(_(" -f         terminate <dirs> argument list\n"), out);
 	fputs(_(" -u         search for unusual entries\n"), out);
 	fputs(_(" -l         output effective lookup paths\n"), out);
-	fprintf(out, USAGE_MAN_TAIL("whereis(1)"));
 
-	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+	fputs(USAGE_SEPARATOR, out);
+	fputs(USAGE_HELP, out);
+	fputs(USAGE_VERSION, out);
+	fprintf(out, USAGE_MAN_TAIL("whereis(1)"));
+	exit(EXIT_SUCCESS);
 }
 
 static void dirlist_add_dir(struct wh_dirlist **ls0, int type, const char *dir)
@@ -502,8 +507,18 @@ int main(int argc, char **argv)
 	textdomain(PACKAGE);
 	atexit(close_stdout);
 
-	if (argc == 1)
-		usage(stderr);
+	if (argc <= 1) {
+		warnx(_("not enough arguments"));
+		errtryhelp(EXIT_FAILURE);
+	} else {
+		/* first arg may be one of our standard longopts */
+		if (!strcmp(argv[1], "--help"))
+			usage();
+		if (!strcmp(argv[1], "--version")) {
+			printf(UTIL_LINUX_VERSION);
+			exit(EXIT_SUCCESS);
+		}
+	}
 
 	whereis_init_debug();
 
@@ -547,8 +562,10 @@ int main(int argc, char **argv)
 				opt_f_missing = 0;
 				break;
 			case 'B':
-				if (*(arg + 1))
-					usage(stderr);
+				if (*(arg + 1)) {
+					warnx(_("bad usage"));
+					errtryhelp(EXIT_FAILURE);
+				}
 				i++;
 				free_dirlist(&ls, BIN_DIR);
 				construct_dirlist_from_argv(
@@ -556,8 +573,10 @@ int main(int argc, char **argv)
 				opt_f_missing = 1;
 				break;
 			case 'M':
-				if (*(arg + 1))
-					usage(stderr);
+				if (*(arg + 1)) {
+					warnx(_("bad usage"));
+					errtryhelp(EXIT_FAILURE);
+				}
 				i++;
 				free_dirlist(&ls, MAN_DIR);
 				construct_dirlist_from_argv(
@@ -565,8 +584,10 @@ int main(int argc, char **argv)
 				opt_f_missing = 1;
 				break;
 			case 'S':
-				if (*(arg + 1))
-					usage(stderr);
+				if (*(arg + 1)) {
+					warnx(_("bad usage"));
+					errtryhelp(EXIT_FAILURE);
+				}
 				i++;
 				free_dirlist(&ls, SRC_DIR);
 				construct_dirlist_from_argv(
@@ -604,9 +625,10 @@ int main(int argc, char **argv)
 				printf(UTIL_LINUX_VERSION);
 				return EXIT_SUCCESS;
 			case 'h':
-				usage(stdout);
+				usage();
 			default:
-				usage(stderr);
+				warnx(_("bad usage"));
+				errtryhelp(EXIT_FAILURE);
 			}
 
 			if (arg_i < i)		/* moved to the next argv[] item */
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 11/13] more: add --help and --version
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (9 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 10/13] whereis: " Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 12/13] mkfs.cramfs: " Ruediger Meier
                   ` (2 subsequent siblings)
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 text-utils/more.1 |  6 ++++++
 text-utils/more.c | 29 ++++++++++++++++++++++-------
 2 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/text-utils/more.1 b/text-utils/more.1
index 428fdec..c4420e0 100644
--- a/text-utils/more.1
+++ b/text-utils/more.1
@@ -98,6 +98,12 @@ Start displaying each file at line
 The
 .I string
 to be searched in each file before starting to display it.
+.TP
+\fB\-\-help\fR
+Display help text and exit.
+.TP
+\fB\-V\fR, \fB\-\-version\fR
+Display version information and exit.
 .SH COMMANDS
 Interactive commands for
 .B more
diff --git a/text-utils/more.c b/text-utils/more.c
index 7c197b2..3578656 100644
--- a/text-utils/more.c
+++ b/text-utils/more.c
@@ -225,8 +225,9 @@ static void putstring(char *s)
 	tputs(s, fileno(stdout), putchar);	/* putp(s); */
 }
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
+	FILE *out = stdout;
 	fputs(USAGE_HEADER, out);
 	fprintf(out, _(" %s [options] <file>...\n"), program_invocation_short_name);
 
@@ -244,9 +245,12 @@ static void __attribute__((__noreturn__)) usage(FILE *out)
 	fputs(_(" -<number>   the number of lines per screenful\n"), out);
 	fputs(_(" +<number>   display file beginning from line number\n"), out);
 	fputs(_(" +/<string>  display file beginning from search string match\n"), out);
-	fputs(_(" -V          display version information and exit\n"), out);
+
+	fputs(USAGE_SEPARATOR, out);
+	fputs(_("     --help     display this help and exit\n"), out);
+	fputs(_(" -V, --version  output version information and exit\n"), out);
 	fprintf(out, USAGE_MAN_TAIL("more(1)"));
-	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+	exit(EXIT_SUCCESS);
 }
 
 int main(int argc, char **argv)
@@ -267,6 +271,16 @@ int main(int argc, char **argv)
 	textdomain(PACKAGE);
 	atexit(close_stdout);
 
+	if (argc > 1) {
+		/* first arg may be one of our standard longopts */
+		if (!strcmp(argv[1], "--help"))
+			usage();
+		if (!strcmp(argv[1], "--version")) {
+			printf(UTIL_LINUX_VERSION);
+			exit(EXIT_SUCCESS);
+		}
+	}
+
 	nfiles = argc;
 	fnames = argv;
 	setlocale(LC_ALL, "");
@@ -319,9 +333,10 @@ int main(int argc, char **argv)
 	left = dlines;
 	if (nfiles > 1)
 		prnames++;
-	if (!no_intty && nfiles == 0)
-		usage(stderr);
-	else
+	if (!no_intty && nfiles == 0) {
+		warnx(_("bad usage"));
+		errtryhelp(EXIT_FAILURE);
+	} else
 		f = stdin;
 	if (!no_tty) {
 		signal(SIGQUIT, onquit);
@@ -488,7 +503,7 @@ void argscan(char *s)
 			break;
 		default:
 			warnx(_("unknown option -%s"), s);
-			usage(stderr);
+			errtryhelp(EXIT_FAILURE);
 			break;
 		}
 		s++;
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 12/13] mkfs.cramfs: add --help and --version
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (10 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 11/13] more: " Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-22  2:37 ` [PATCH 13/13] misc: no more errtryh() Ruediger Meier
  2017-06-26 13:04 ` [PATCH 00/13] usage cleanup part 1 Rüdiger Meier
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Note, we were already using errtryhelp() without providing
a --help option.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 disk-utils/mkfs.cramfs.8 |  8 ++++----
 disk-utils/mkfs.cramfs.c | 33 +++++++++++++++++++++++----------
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/disk-utils/mkfs.cramfs.8 b/disk-utils/mkfs.cramfs.8
index c2e843a..9701e10 100644
--- a/disk-utils/mkfs.cramfs.8
+++ b/disk-utils/mkfs.cramfs.8
@@ -64,11 +64,11 @@ sorting.
 \fB\-z\fR
 Make explicit holes.  Use of this option will require 2.3.39 kernel, or newer.
 .TP
-\fB\-V\fR
-Display version information and exit.
+\fB\-h\fR, \fB\-\-help\fR
+Display help text and exit.
 .TP
-\fB\-h\fR
-Display help and exit.
+\fB\-V\fR, \fB\-\-version\fR
+Display version information and exit.
 .SH "EXIT STATUS"
 .RS
 .PD 0
diff --git a/disk-utils/mkfs.cramfs.c b/disk-utils/mkfs.cramfs.c
index 041c6d7..ed4b927 100644
--- a/disk-utils/mkfs.cramfs.c
+++ b/disk-utils/mkfs.cramfs.c
@@ -122,12 +122,9 @@ struct entry {
 #define CRAMFS_GID_WIDTH 8
 #define CRAMFS_OFFSET_WIDTH 26
 
-/* Input status of 0 to print help and exit without an error. */
-static void __attribute__((__noreturn__))
-usage(int status) {
-	FILE *stream = status ? stderr : stdout;
-
-	fprintf(stream,
+static void __attribute__((__noreturn__)) usage(void)
+{
+	printf(
 		_("usage: %s [-h] [-v] [-b blksize] [-e edition] [-N endian] [-i file] "
 		  "[-n name] dirname outfile\n"
 		  " -h         print this help\n"
@@ -147,7 +144,11 @@ usage(int status) {
 		  " outfile    output file\n"),
 		program_invocation_short_name, PAD_SIZE);
 
-	exit(status);
+	fputs(USAGE_SEPARATOR, stdout);
+	fputs(USAGE_HELP, stdout);
+	fputs(USAGE_VERSION, stdout);
+	printf(USAGE_MAN_TAIL("mkfs.cramfs(8)"));
+	exit(MKFS_EX_OK);
 }
 
 static char *
@@ -717,11 +718,21 @@ int main(int argc, char **argv)
 	textdomain(PACKAGE);
 	atexit(close_stdout);
 
+	if (argc > 1) {
+		/* first arg may be one of our standard longopts */
+		if (!strcmp(argv[1], "--help"))
+			usage();
+		if (!strcmp(argv[1], "--version")) {
+			printf(UTIL_LINUX_VERSION);
+			exit(EXIT_SUCCESS);
+		}
+	}
+
 	/* command line options */
 	while ((c = getopt(argc, argv, "hb:Ee:i:n:N:psVvz")) != EOF) {
 		switch (c) {
 		case 'h':
-			usage(MKFS_EX_OK);
+			usage();
 		case 'b':
 			blksize = strtou32_or_err(optarg, _("invalid blocksize argument"));
 			break;
@@ -773,8 +784,10 @@ int main(int argc, char **argv)
 		}
 	}
 
-	if ((argc - optind) != 2)
-		usage(MKFS_EX_USAGE);
+	if ((argc - optind) != 2) {
+		warnx(_("bad usage"));
+		errtryhelp(MKFS_EX_USAGE);
+	}
 	dirname = argv[optind];
 	outfile = argv[optind + 1];
 
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* [PATCH 13/13] misc: no more errtryh()
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (11 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 12/13] mkfs.cramfs: " Ruediger Meier
@ 2017-06-22  2:37 ` Ruediger Meier
  2017-06-26 13:04 ` [PATCH 00/13] usage cleanup part 1 Rüdiger Meier
  13 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  2:37 UTC (permalink / raw)
  To: util-linux

From: Ruediger Meier <ruediger.meier@ga-group.nl>

Nowadays all our regular commands have --help options.
test_uuidd does not use translations anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
---
 include/c.h             |  6 ------
 misc-utils/test_uuidd.c | 25 ++++++++++++++-----------
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/include/c.h b/include/c.h
index 2bcdcea..8cf54cb 100644
--- a/include/c.h
+++ b/include/c.h
@@ -216,12 +216,6 @@ errmsg(char doexit, int excode, char adderr, const char *fmt, ...)
 	exit(eval); \
 })
 
-#define errtryh(eval) __extension__ ({ \
-	fprintf(stderr, _("Try '%s -h' for more information.\n"), \
-			program_invocation_short_name); \
-	exit(eval); \
-})
-
 
 static inline __attribute__((const)) int is_power_of_2(unsigned long num)
 {
diff --git a/misc-utils/test_uuidd.c b/misc-utils/test_uuidd.c
index 26751a4..7bbd3a9 100644
--- a/misc-utils/test_uuidd.c
+++ b/misc-utils/test_uuidd.c
@@ -73,17 +73,17 @@ static int shmem_id;
 static object_t *objects;
 
 
-static void __attribute__((__noreturn__)) usage(FILE *out)
+static void __attribute__((__noreturn__)) usage(void)
 {
-	fprintf(out, "\n %s [options]\n", program_invocation_short_name);
+	printf("\n %s [options]\n", program_invocation_short_name);
 
-	fprintf(out, "  -p <num>     number of nprocesses (default:%zu)\n", nprocesses);
-	fprintf(out, "  -t <num>     number of nthreads (default:%zu)\n", nthreads);
-	fprintf(out, "  -o <num>     number of nobjects (default:%zu)\n", nobjects);
-	fprintf(out, "  -l <level>   log level (default:%zu)\n", loglev);
-	fprintf(out, "  -h           display help\n");
+	printf("  -p <num>     number of nprocesses (default:%zu)\n", nprocesses);
+	printf("  -t <num>     number of nthreads (default:%zu)\n", nthreads);
+	printf("  -o <num>     number of nobjects (default:%zu)\n", nobjects);
+	printf("  -l <level>   log level (default:%zu)\n", loglev);
+	printf("  -h           display help\n");
 
-	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+	exit(EXIT_SUCCESS);
 }
 
 static void allocate_segment(int *id, void **address, size_t number, size_t size)
@@ -260,6 +260,8 @@ static void object_dump(size_t idx, object_t *obj)
 	fprintf(stderr, "}\n");
 }
 
+#define MSG_TRY_HELP "Try '-h' for help."
+
 int main(int argc, char *argv[])
 {
 	size_t i, nfailed = 0, nignored = 0;
@@ -280,15 +282,16 @@ int main(int argc, char *argv[])
 			loglev = strtou32_or_err(optarg, "invalid log level argument");
 			break;
 		case 'h':
-			usage(stdout);
+			usage();
 			break;
 		default:
-			errtryh(EXIT_FAILURE);
+			fprintf(stderr, MSG_TRY_HELP);
+			exit(EXIT_FAILURE);
 		}
 	}
 
 	if (optind != argc)
-		usage(stderr);
+		errx(EXIT_FAILURE, "bad usage\n" MSG_TRY_HELP);
 
 	if (loglev == 1)
 		fprintf(stderr, "requested: %zu processes, %zu threads, %zu objects per thread (%zu objects = %zu bytes)\n",
-- 
1.8.5.6


^ permalink raw reply related	[flat|nested] 22+ messages in thread

* Re: [PATCH 06/13] setarch: print usage error if no argument given
  2017-06-22  2:37 ` [PATCH 06/13] setarch: print usage error if no argument given Ruediger Meier
@ 2017-06-22  8:38   ` Karel Zak
  2017-06-22  8:44     ` Ruediger Meier
  0 siblings, 1 reply; 22+ messages in thread
From: Karel Zak @ 2017-06-22  8:38 UTC (permalink / raw)
  To: Ruediger Meier; +Cc: util-linux

On Thu, Jun 22, 2017 at 04:37:39AM +0200, Ruediger Meier wrote:
> From: Ruediger Meier <ruediger.meier@ga-group.nl>
> 
> This looks more likely as intended.
> 
> Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
> ---
>  sys-utils/setarch.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
> index eb9cf21..6481eb2 100644
> --- a/sys-utils/setarch.c
> +++ b/sys-utils/setarch.c
> @@ -301,7 +301,7 @@ int main(int argc, char *argv[])
>  	textdomain(PACKAGE);
>  	atexit(close_stdout);
>  
> -	if (argc < 1)
> +	if (argc < 2)
>  		show_usage(_("Not enough arguments"));

I don't think so. 

We use setarch by symlinks (i386, uname26 linux32 linux64, ...) and in
this case it's executed without argument. The symlink name is good
enough.

The right solutions is to remove this entire if() block. 

Later in the code we have "no architecture argument specified".


    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 09/13] login: add --help and --version
  2017-06-22  2:37 ` [PATCH 09/13] login: " Ruediger Meier
@ 2017-06-22  8:42   ` Karel Zak
  0 siblings, 0 replies; 22+ messages in thread
From: Karel Zak @ 2017-06-22  8:42 UTC (permalink / raw)
  To: Ruediger Meier; +Cc: util-linux

On Thu, Jun 22, 2017 at 04:37:42AM +0200, Ruediger Meier wrote:
> From: Ruediger Meier <ruediger.meier@ga-group.nl>
> Note, the usage text could be improved, currently it
> does not describe any options.

+1

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 06/13] setarch: print usage error if no argument given
  2017-06-22  8:38   ` Karel Zak
@ 2017-06-22  8:44     ` Ruediger Meier
  0 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22  8:44 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

On Thursday 22 June 2017, Karel Zak wrote:
> On Thu, Jun 22, 2017 at 04:37:39AM +0200, Ruediger Meier wrote:
> > From: Ruediger Meier <ruediger.meier@ga-group.nl>
> >
> > This looks more likely as intended.
> >
> > Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
> > ---
> >  sys-utils/setarch.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/sys-utils/setarch.c b/sys-utils/setarch.c
> > index eb9cf21..6481eb2 100644
> > --- a/sys-utils/setarch.c
> > +++ b/sys-utils/setarch.c
> > @@ -301,7 +301,7 @@ int main(int argc, char *argv[])
> >  	textdomain(PACKAGE);
> >  	atexit(close_stdout);
> >
> > -	if (argc < 1)
> > +	if (argc < 2)
> >  		show_usage(_("Not enough arguments"));
>
> I don't think so.
>
> We use setarch by symlinks (i386, uname26 linux32 linux64, ...) and
> in this case it's executed without argument. The symlink name is good
> enough.
>
> The right solutions is to remove this entire if() block.

Maybe argc can be 0 when not invoked from a sane shell
https://stackoverflow.com/questions/2794150/when-can-argv0-have-null

Just skip this patch, I will update this on github later.


> Later in the code we have "no architecture argument specified".
>
>
>     Karel

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 03/13] misc: fix some broken exit codes
  2017-06-22  2:37 ` [PATCH 03/13] misc: fix some broken exit codes Ruediger Meier
@ 2017-06-22 20:49   ` Ruediger Meier
  0 siblings, 0 replies; 22+ messages in thread
From: Ruediger Meier @ 2017-06-22 20:49 UTC (permalink / raw)
  To: util-linux

On Thursday 22 June 2017, Ruediger Meier wrote:
> From: Ruediger Meier <ruediger.meier@ga-group.nl>
>
> These tools have special exit codes. They got changed mistakenly.

I've moved this patch to my other "exit-code" pull request.
Updated on github.
 
Both patch-sets are independent and rebased on master
branch

cu,
Rudi

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 00/13] usage cleanup part 1
  2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
                   ` (12 preceding siblings ...)
  2017-06-22  2:37 ` [PATCH 13/13] misc: no more errtryh() Ruediger Meier
@ 2017-06-26 13:04 ` Rüdiger Meier
  2017-06-26 14:07   ` Karel Zak
  13 siblings, 1 reply; 22+ messages in thread
From: Rüdiger Meier @ 2017-06-26 13:04 UTC (permalink / raw)
  To: util-linux

On 06/22/2017 04:37 AM, Ruediger Meier wrote:
> From: Ruediger Meier <ruediger.meier@ga-group.nl>
> 
> This is pull request #467 on github
> https://github.com/karelzak/util-linux/pull/467

> The major goal is to avoid printing usage/help messages on stderr.
> 
> This is the preparing first part of a bigger patch-set. There are
> some minor bug fixes and finally we add --help options to all our
> commands (just 5 commands were missing it).
> 
> The next completing patch-set (part 2) will be more invasive but
> even more trivial.

Thanks for merging.

FYI I've PR'ed the second part on github only because it's almost
trivial but invasive.
    https://github.com/karelzak/util-linux/pull/471

> Ruediger Meier (13):
>    uuidd: remove unused define
>    misc: remove superfluous null pointer checks for optarg
>    misc: fix some broken exit codes
>    blkid: use errtryhelp instead of errtryh
>    dmesg: do not accept any non-option arguments
>    setarch: print usage error if no argument given
>    setarch: use errtryhelp()
>    fsck: add --help and --version
>    login: add --help and --version
>    whereis: add --help and --version
>    more: add --help and --version
>    mkfs.cramfs: add --help and --version
>    misc: no more errtryh()
> 
>   disk-utils/fsck.8        |  6 ++++++
>   disk-utils/fsck.c        | 29 +++++++++++++++++++++--------
>   disk-utils/fsck.cramfs.c |  2 +-
>   disk-utils/mkfs.cramfs.8 |  8 ++++----
>   disk-utils/mkfs.cramfs.c | 35 ++++++++++++++++++++++++-----------
>   include/c.h              |  6 ------
>   login-utils/chsh.c       |  2 --
>   login-utils/login.1      |  5 ++++-
>   login-utils/login.c      | 28 ++++++++++++++++++++++------
>   login-utils/lslogins.c   | 15 ++++++---------
>   misc-utils/blkid.c       |  8 ++++----
>   misc-utils/findfs.c      |  4 ++--
>   misc-utils/test_uuidd.c  | 25 ++++++++++++++-----------
>   misc-utils/uuidd.c       |  6 ------
>   misc-utils/whereis.1     |  6 ++++++
>   misc-utils/whereis.c     | 48 +++++++++++++++++++++++++++++++++++-------------
>   sys-utils/dmesg.c        |  4 +---
>   sys-utils/setarch.c      | 22 ++++++----------------
>   text-utils/hexdump.c     |  2 +-
>   text-utils/more.1        |  6 ++++++
>   text-utils/more.c        | 29 ++++++++++++++++++++++-------
>   21 files changed, 185 insertions(+), 111 deletions(-)
> 

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 00/13] usage cleanup part 1
  2017-06-26 13:04 ` [PATCH 00/13] usage cleanup part 1 Rüdiger Meier
@ 2017-06-26 14:07   ` Karel Zak
  2017-06-26 14:44     ` Rüdiger Meier
  0 siblings, 1 reply; 22+ messages in thread
From: Karel Zak @ 2017-06-26 14:07 UTC (permalink / raw)
  To: Rüdiger Meier; +Cc: util-linux

On Mon, Jun 26, 2017 at 03:04:30PM +0200, Rüdiger Meier wrote:
> On 06/22/2017 04:37 AM, Ruediger Meier wrote:
> > From: Ruediger Meier <ruediger.meier@ga-group.nl>
> > 
> > This is pull request #467 on github
> > https://github.com/karelzak/util-linux/pull/467
> 
> > The major goal is to avoid printing usage/help messages on stderr.
> > 
> > This is the preparing first part of a bigger patch-set. There are
> > some minor bug fixes and finally we add --help options to all our
> > commands (just 5 commands were missing it).
> > 
> > The next completing patch-set (part 2) will be more invasive but
> > even more trivial.
> 
> Thanks for merging.
> 
> FYI I've PR'ed the second part on github only because it's almost
> trivial but invasive.
>    https://github.com/karelzak/util-linux/pull/471

Merged, thanks!

It seems we have many places with "not enough arguments" or "device no
specified" or "bad usage". What about to create some inline function
for these things?

static inline err_usage(int eval, char *msg)
{
    warnx(msg);
    errtryhelp(eval);
}

#define errnoargs(x)    err_usage(x, _("not enough arguments"))
#define errnodevice(x)  err_usage(x, _("no device specified"))
#define errbadusage(x)  err_usage(x, _("bad usage"))


Maybe it seems like over-engineering, but it's pretty common in the
code and some consolidation to avoid creativity would be nice. The current 
solution requires

    if (argv < 2) {
        warnx(_("not enough arguments")));
        errtryhelp(EXIT_FAILURE);
    }

I think

   if (argv < 2)
       errnoargs(EXIT_FAILURE);

is shorter, seems better and provides control on the messages
(errtryhelp() call, etc).

Comments?

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 00/13] usage cleanup part 1
  2017-06-26 14:07   ` Karel Zak
@ 2017-06-26 14:44     ` Rüdiger Meier
  2017-06-26 20:37       ` Karel Zak
  0 siblings, 1 reply; 22+ messages in thread
From: Rüdiger Meier @ 2017-06-26 14:44 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux



On 06/26/2017 04:07 PM, Karel Zak wrote:
> On Mon, Jun 26, 2017 at 03:04:30PM +0200, Rüdiger Meier wrote:
>> On 06/22/2017 04:37 AM, Ruediger Meier wrote:
>>> From: Ruediger Meier <ruediger.meier@ga-group.nl>
>>>
>>> This is pull request #467 on github
>>> https://github.com/karelzak/util-linux/pull/467
>>
>>> The major goal is to avoid printing usage/help messages on stderr.
>>>
>>> This is the preparing first part of a bigger patch-set. There are
>>> some minor bug fixes and finally we add --help options to all our
>>> commands (just 5 commands were missing it).
>>>
>>> The next completing patch-set (part 2) will be more invasive but
>>> even more trivial.
>>
>> Thanks for merging.
>>
>> FYI I've PR'ed the second part on github only because it's almost
>> trivial but invasive.
>>     https://github.com/karelzak/util-linux/pull/471
> 
> Merged, thanks!
> 
> It seems we have many places with "not enough arguments" or "device no
> specified" or "bad usage". What about to create some inline function
> for these things?
> 
> static inline err_usage(int eval, char *msg)
> {
>      warnx(msg);
>      errtryhelp(eval);
> }
> 
> #define errnoargs(x)    err_usage(x, _("not enough arguments"))
> #define errnodevice(x)  err_usage(x, _("no device specified"))
> #define errbadusage(x)  err_usage(x, _("bad usage"))

> 
> Maybe it seems like over-engineering, but it's pretty common in the
> code and some consolidation to avoid creativity would be nice. The current
> solution requires
> 
>      if (argv < 2) {
>          warnx(_("not enough arguments")));
>          errtryhelp(EXIT_FAILURE);
>      }
> 
> I think
> 
>     if (argv < 2)
>         errnoargs(EXIT_FAILURE);
> 
> is shorter, seems better and provides control on the messages
> (errtryhelp() call, etc).
> 
> Comments?

I was already playing around with something like this

#define werrtryhelp(eval, s...) __extension__ ({ \
     warnx(s); \
     errtryhelp(eval); \
})

This would make things 1simple in about 100 cases, for example

   -       if (argc > 0) {
   -               warnx(_("%d too many arguments given"), argc);
   -               errtryhelp(EXIT_FAILURE);
   -       }
   +       if (argc > 0)
   +               werrtryhelp(EXIT_FAILURE, _("%d too many arguments given"), argc);


For the standard errors we would only need defines like:


#define ERR_MSG_NOARGS _("not enough arguments"))

   if (argv < 2)
       errtryhelp(EXIT_FAILURE, ERR_MSG_NOARGS);


Funny, I've had already deleted my werrtryhelp branch because I got
already tired of this cleanup. I just got it back from git-reflog
and safe it for later ;)

cu,
Rudi

^ permalink raw reply	[flat|nested] 22+ messages in thread

* Re: [PATCH 00/13] usage cleanup part 1
  2017-06-26 14:44     ` Rüdiger Meier
@ 2017-06-26 20:37       ` Karel Zak
  0 siblings, 0 replies; 22+ messages in thread
From: Karel Zak @ 2017-06-26 20:37 UTC (permalink / raw)
  To: Rüdiger Meier; +Cc: util-linux

On Mon, Jun 26, 2017 at 04:44:59PM +0200, Rüdiger Meier wrote:
> 
> 
> On 06/26/2017 04:07 PM, Karel Zak wrote:
> > On Mon, Jun 26, 2017 at 03:04:30PM +0200, Rüdiger Meier wrote:
> > > On 06/22/2017 04:37 AM, Ruediger Meier wrote:
> > > > From: Ruediger Meier <ruediger.meier@ga-group.nl>
> > > > 
> > > > This is pull request #467 on github
> > > > https://github.com/karelzak/util-linux/pull/467
> > > 
> > > > The major goal is to avoid printing usage/help messages on stderr.
> > > > 
> > > > This is the preparing first part of a bigger patch-set. There are
> > > > some minor bug fixes and finally we add --help options to all our
> > > > commands (just 5 commands were missing it).
> > > > 
> > > > The next completing patch-set (part 2) will be more invasive but
> > > > even more trivial.
> > > 
> > > Thanks for merging.
> > > 
> > > FYI I've PR'ed the second part on github only because it's almost
> > > trivial but invasive.
> > >     https://github.com/karelzak/util-linux/pull/471
> > 
> > Merged, thanks!
> > 
> > It seems we have many places with "not enough arguments" or "device no
> > specified" or "bad usage". What about to create some inline function
> > for these things?
> > 
> > static inline err_usage(int eval, char *msg)
> > {
> >      warnx(msg);
> >      errtryhelp(eval);
> > }
> > 
> > #define errnoargs(x)    err_usage(x, _("not enough arguments"))
> > #define errnodevice(x)  err_usage(x, _("no device specified"))
> > #define errbadusage(x)  err_usage(x, _("bad usage"))
> 
> > 
> > Maybe it seems like over-engineering, but it's pretty common in the
> > code and some consolidation to avoid creativity would be nice. The current
> > solution requires
> > 
> >      if (argv < 2) {
> >          warnx(_("not enough arguments")));
> >          errtryhelp(EXIT_FAILURE);
> >      }
> > 
> > I think
> > 
> >     if (argv < 2)
> >         errnoargs(EXIT_FAILURE);
> > 
> > is shorter, seems better and provides control on the messages
> > (errtryhelp() call, etc).
> > 
> > Comments?
> 
> I was already playing around with something like this
> 
> #define werrtryhelp(eval, s...) __extension__ ({ \
>     warnx(s); \
>     errtryhelp(eval); \
> })
> 
> This would make things 1simple in about 100 cases, for example
> 
>   -       if (argc > 0) {
>   -               warnx(_("%d too many arguments given"), argc);
>   -               errtryhelp(EXIT_FAILURE);
>   -       }
>   +       if (argc > 0)
>   +               werrtryhelp(EXIT_FAILURE, _("%d too many arguments given"), argc);
> 
> 
> For the standard errors we would only need defines like:
> 
> 
> #define ERR_MSG_NOARGS _("not enough arguments"))
> 
>   if (argv < 2)
>       errtryhelp(EXIT_FAILURE, ERR_MSG_NOARGS);

 I'd like to avoid things like ERR_MSG_NOARGS in the standard code 
 for basic messages. 

    if (argv < 2)
        errnoargs(EXIT_FAILURE);

 seems as a way how to keep it simple and stupid. It's fine to have
 ERR_MSG_* somewhere in the header files, but details for standard
 things should be hidden by errxxxxx() macros.
 
> Funny, I've had already deleted my werrtryhelp branch because I got
> already tired of this cleanup. I just got it back from git-reflog
> and safe it for later ;)

 I understand :-) It's nothing critical -- just idea.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2017-06-26 20:38 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-22  2:37 [PATCH 00/13] usage cleanup part 1 Ruediger Meier
2017-06-22  2:37 ` [PATCH 01/13] uuidd: remove unused define Ruediger Meier
2017-06-22  2:37 ` [PATCH 02/13] misc: remove superfluous null pointer checks for optarg Ruediger Meier
2017-06-22  2:37 ` [PATCH 03/13] misc: fix some broken exit codes Ruediger Meier
2017-06-22 20:49   ` Ruediger Meier
2017-06-22  2:37 ` [PATCH 04/13] blkid: use errtryhelp instead of errtryh Ruediger Meier
2017-06-22  2:37 ` [PATCH 05/13] dmesg: do not accept any non-option arguments Ruediger Meier
2017-06-22  2:37 ` [PATCH 06/13] setarch: print usage error if no argument given Ruediger Meier
2017-06-22  8:38   ` Karel Zak
2017-06-22  8:44     ` Ruediger Meier
2017-06-22  2:37 ` [PATCH 07/13] setarch: use errtryhelp() Ruediger Meier
2017-06-22  2:37 ` [PATCH 08/13] fsck: add --help and --version Ruediger Meier
2017-06-22  2:37 ` [PATCH 09/13] login: " Ruediger Meier
2017-06-22  8:42   ` Karel Zak
2017-06-22  2:37 ` [PATCH 10/13] whereis: " Ruediger Meier
2017-06-22  2:37 ` [PATCH 11/13] more: " Ruediger Meier
2017-06-22  2:37 ` [PATCH 12/13] mkfs.cramfs: " Ruediger Meier
2017-06-22  2:37 ` [PATCH 13/13] misc: no more errtryh() Ruediger Meier
2017-06-26 13:04 ` [PATCH 00/13] usage cleanup part 1 Rüdiger Meier
2017-06-26 14:07   ` Karel Zak
2017-06-26 14:44     ` Rüdiger Meier
2017-06-26 20:37       ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).