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/10] kill: make usage() not to return
Date: Sun,  9 Mar 2014 15:30:18 -0500	[thread overview]
Message-ID: <1394397023-7050-5-git-send-email-kerolasa@iki.fi> (raw)
In-Reply-To: <1394397023-7050-1-git-send-email-kerolasa@iki.fi>

And change the function argument to be output stream.  Earlier the --help
made kill to exit with none zero value, that now is corrected.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
---
 misc-utils/kill.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/misc-utils/kill.c b/misc-utils/kill.c
index b95e03d..2fecda3 100644
--- a/misc-utils/kill.c
+++ b/misc-utils/kill.c
@@ -149,7 +149,7 @@ static int arg_to_signum(char *arg, int mask);
 static void nosig(char *name);
 static void printsig(int sig);
 static void printsignals(FILE *fp, int pretty);
-static int usage(int status);
+static void __attribute__((__noreturn__)) usage(FILE *out);
 static int kill_verbose(char *procname, int pid, int sig);
 
 #ifdef HAVE_SIGQUEUE
@@ -189,7 +189,7 @@ int main(int argc, char **argv)
 			return EXIT_SUCCESS;
 		}
 		if (!strcmp(arg, "-h") || !strcmp(arg, "--help"))
-			return usage(EXIT_FAILURE);
+			usage(stdout);
 
 		if (!strcmp(arg, "-a") || !strcmp(arg, "--all")) {
 			check_all++;
@@ -201,7 +201,7 @@ int main(int argc, char **argv)
 				return EXIT_SUCCESS;
 			}
 			if (2 < argc)
-				return usage(EXIT_FAILURE);
+				usage(stderr);
 			/* argc == 2, accept "kill -l $?" */
 			arg = argv[1];
 			if ((numsig = arg_to_signum(arg, 1)) < 0)
@@ -225,15 +225,15 @@ int main(int argc, char **argv)
 		if (!strcmp(arg, "-p") || !strcmp(arg, "--pid")) {
 			do_pid++;
 			if (do_kill)
-				return usage(EXIT_FAILURE);
+				usage(stderr);
 			continue;
 		}
 		if (!strcmp(arg, "-s") || !strcmp(arg, "--signal")) {
 			if (argc < 2)
-				return usage(EXIT_FAILURE);
+				usage(stderr);
 			do_kill++;
 			if (do_pid)
-				return usage(EXIT_FAILURE);
+				usage(stderr);
 			argc--, argv++;
 			arg = *argv;
 			if ((numsig = arg_to_signum(arg, 0)) < 0) {
@@ -244,7 +244,7 @@ int main(int argc, char **argv)
 		}
 		if (!strcmp(arg, "-q") || !strcmp(arg, "--queue")) {
 			if (argc < 2)
-				return usage(EXIT_FAILURE);
+				usage(stderr);
 			argc--, argv++;
 			arg = *argv;
 #ifdef HAVE_SIGQUEUE
@@ -266,14 +266,14 @@ int main(int argc, char **argv)
 			break;
 		arg++;
 		if ((numsig = arg_to_signum(arg, 0)) < 0)
-			return usage(EXIT_FAILURE);
+			usage(stderr);
 		do_kill++;
 		if (do_pid)
-			return usage(EXIT_FAILURE);
+			usage(stderr);
 		continue;
 	}
 	if (!*argv)
-		return usage(EXIT_FAILURE);
+		usage(stderr);
 	if (do_pid)
 		numsig = -1;
 
@@ -441,10 +441,8 @@ static void printsignals(FILE *fp, int pretty)
 	fputc('\n', fp);
 }
 
-static int usage(int status)
+static void __attribute__((__noreturn__)) usage(FILE *out)
 {
-	FILE *out = (status == 0 ? stdout : stderr);
-
 	fputs(USAGE_HEADER, out);
 	fprintf(out, _(" %s [options] <pid|name> [...]\n"), program_invocation_short_name);
 	fputs(USAGE_OPTIONS, out);
@@ -459,7 +457,7 @@ static int usage(int status)
 	fputs(USAGE_HELP, out);
 	fputs(USAGE_VERSION, out);
 	fprintf(out, USAGE_MAN_TAIL("kill(1)"));
-	return status;
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 static int kill_verbose(char *procname, pid_t pid, int sig)
-- 
1.9.0


  parent reply	other threads:[~2014-03-09 20:30 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 ` Sami Kerola [this message]
2014-03-19 12:37   ` [PATCH 05/10] kill: make usage() not to return 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
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=1394397023-7050-5-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