All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: eranian@google.com, Ian Rogers <irogers@google.com>
Subject: [PATCH 2/3] tools perf: Prefer exit(EXIT_*) over exit(0|1)
Date: Wed, 28 Jul 2021 23:24:50 -0700	[thread overview]
Message-ID: <20210729062451.1349566-3-irogers@google.com> (raw)
In-Reply-To: <20210729062451.1349566-1-irogers@google.com>

Change exit code to be more intention revealing, replacing exit(0) with
exit(EXIT_SUCCESS) and exit(1) with exit(EXIT_FAILURE).

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/arch/x86/tests/bp-modify.c | 4 ++--
 tools/perf/bench/inject-buildid.c     | 8 ++++----
 tools/perf/bench/numa.c               | 2 +-
 tools/perf/bench/sched-messaging.c    | 6 +++---
 tools/perf/bench/sched-pipe.c         | 4 ++--
 tools/perf/bench/syscall.c            | 2 +-
 tools/perf/builtin-c2c.c              | 2 +-
 tools/perf/builtin-ftrace.c           | 2 +-
 tools/perf/builtin-mem.c              | 2 +-
 tools/perf/builtin-script.c           | 4 ++--
 tools/perf/perf.c                     | 8 ++++----
 tools/perf/ui/tui/setup.c             | 4 ++--
 tools/perf/util/dlfilter.c            | 2 +-
 tools/perf/util/help-unknown-cmd.c    | 2 +-
 14 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/tools/perf/arch/x86/tests/bp-modify.c b/tools/perf/arch/x86/tests/bp-modify.c
index dffcf9b52153..9cf1036d0480 100644
--- a/tools/perf/arch/x86/tests/bp-modify.c
+++ b/tools/perf/arch/x86/tests/bp-modify.c
@@ -41,12 +41,12 @@ static int spawn_child(void)
 
 		if (err) {
 			pr_debug("failed to PTRACE_TRACEME\n");
-			exit(1);
+			exit(EXIT_FAILURE);
 		}
 
 		raise(SIGCONT);
 		bp_1();
-		exit(0);
+		exit(EXIT_SUCCESS);
 	}
 
 	return child;
diff --git a/tools/perf/bench/inject-buildid.c b/tools/perf/bench/inject-buildid.c
index 55d373b75791..8fd1ec0d371e 100644
--- a/tools/perf/bench/inject-buildid.c
+++ b/tools/perf/bench/inject-buildid.c
@@ -106,7 +106,7 @@ static void collect_dso(void)
 	dsos = calloc(nr_mmaps * DSO_MMAP_RATIO, sizeof(*dsos));
 	if (dsos == NULL) {
 		printf("  Memory allocation failed\n");
-		exit(1);
+		exit(EXIT_FAILURE);
 	}
 
 	if (nftw("/usr/lib/", add_dso, 10, FTW_PHYS) < 0)
@@ -305,7 +305,7 @@ static int setup_injection(struct bench_data *data, bool build_id_all)
 
 		dev_null_fd = open("/dev/null", O_WRONLY);
 		if (dev_null_fd < 0)
-			exit(1);
+			exit(EXIT_FAILURE);
 
 		dup2(dev_null_fd, STDERR_FILENO);
 
@@ -314,7 +314,7 @@ static int setup_injection(struct bench_data *data, bool build_id_all)
 
 		inject_argv = calloc(inject_argc + 1, sizeof(*inject_argv));
 		if (inject_argv == NULL)
-			exit(1);
+			exit(EXIT_FAILURE);
 
 		inject_argv[0] = strdup("inject");
 		inject_argv[1] = strdup("-b");
@@ -326,7 +326,7 @@ static int setup_injection(struct bench_data *data, bool build_id_all)
 
 		cmd_inject(inject_argc, inject_argv);
 
-		exit(0);
+		exit(EXIT_SUCCESS);
 	}
 
 	pthread_create(&data->th, NULL, data_reader, data);
diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index f2640179ada9..a2ee96180444 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -1551,7 +1551,7 @@ static int __bench_numa(const char *name)
 			/* Child process: */
 			worker_process(i);
 
-			exit(0);
+			exit(EXIT_SUCCESS);
 		}
 		pids[i] = pid;
 
diff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c
index 488f6e6ba1a5..d03248837777 100644
--- a/tools/perf/bench/sched-messaging.c
+++ b/tools/perf/bench/sched-messaging.c
@@ -149,7 +149,7 @@ static pthread_t create_worker(void *ctx, void *(*func)(void *))
 			break;
 		case 0:
 			(*func) (ctx);
-			exit(0);
+			exit(EXIT_SUCCESS);
 			break;
 		default:
 			break;
@@ -182,7 +182,7 @@ static void reap_worker(pthread_t id)
 		/* process mode */
 		wait(&proc_status);
 		if (!WIFEXITED(proc_status))
-			exit(1);
+			exit(EXIT_FAILURE);
 	} else {
 		pthread_join(id, &thread_status);
 	}
@@ -319,7 +319,7 @@ int bench_sched_messaging(int argc, const char **argv)
 	default:
 		/* reaching here is something disaster */
 		fprintf(stderr, "Unknown format:%d\n", bench_format);
-		exit(1);
+		exit(EXIT_FAILURE);
 		break;
 	}
 
diff --git a/tools/perf/bench/sched-pipe.c b/tools/perf/bench/sched-pipe.c
index a960e7a93aec..0f5c00a29199 100644
--- a/tools/perf/bench/sched-pipe.c
+++ b/tools/perf/bench/sched-pipe.c
@@ -135,7 +135,7 @@ int bench_sched_pipe(int argc, const char **argv)
 
 		if (!pid) {
 			worker_thread(threads + 0);
-			exit(0);
+			exit(EXIT_SUCCESS);
 		} else {
 			worker_thread(threads + 1);
 		}
@@ -175,7 +175,7 @@ int bench_sched_pipe(int argc, const char **argv)
 	default:
 		/* reaching here is something disaster */
 		fprintf(stderr, "Unknown format:%d\n", bench_format);
-		exit(1);
+		exit(EXIT_FAILURE);
 		break;
 	}
 
diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c
index 9b751016f4b6..abd49c45ce3b 100644
--- a/tools/perf/bench/syscall.c
+++ b/tools/perf/bench/syscall.c
@@ -73,7 +73,7 @@ int bench_syscall_basic(int argc, const char **argv)
 	default:
 		/* reaching here is something disaster */
 		fprintf(stderr, "Unknown format:%d\n", bench_format);
-		exit(1);
+		exit(EXIT_FAILURE);
 		break;
 	}
 
diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
index 6dea37f141b2..21ef021b8bbf 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -2889,7 +2889,7 @@ static int parse_record_events(const struct option *opt,
 
 	if (!strcmp(str, "list")) {
 		perf_mem_events__list();
-		exit(0);
+		exit(EXIT_SUCCESS);
 	}
 	if (perf_mem_events__parse(str))
 		exit(-1);
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 87cb11a7a3ee..2411aa4443e0 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -750,7 +750,7 @@ static int opt_list_avail_functions(const struct option *opt __maybe_unused,
 	if (ret < 0)
 		return ret;
 
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
 
 static int parse_filter_func(const struct option *opt, const char *str,
diff --git a/tools/perf/builtin-mem.c b/tools/perf/builtin-mem.c
index 0fd2a74dbaca..5d96b6e15992 100644
--- a/tools/perf/builtin-mem.c
+++ b/tools/perf/builtin-mem.c
@@ -45,7 +45,7 @@ static int parse_record_events(const struct option *opt,
 
 	if (!strcmp(str, "list")) {
 		perf_mem_events__list();
-		exit(0);
+		exit(EXIT_SUCCESS);
 	}
 	if (perf_mem_events__parse(str))
 		exit(-1);
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 8c03a9862872..f4763830c7a4 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -2774,7 +2774,7 @@ static int parse_scriptname(const struct option *opt __maybe_unused,
 
 	if (strcmp(str, "lang") == 0) {
 		list_available_languages();
-		exit(0);
+		exit(EXIT_SUCCESS);
 	}
 
 	script = strchr(str, ':');
@@ -3175,7 +3175,7 @@ static int list_available_scripts(const struct option *opt __maybe_unused,
 			desc->half_liner ? desc->half_liner : "");
 	}
 
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
 
 static int add_dlarg(const struct option *opt __maybe_unused,
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 2f6b67189b42..ec45dd645030 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -214,11 +214,11 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 				set_argv_exec_path(cmd + 1);
 			else {
 				puts(get_argv_exec_path());
-				exit(0);
+				exit(EXIT_SUCCESS);
 			}
 		} else if (!strcmp(cmd, "--html-path")) {
 			puts(system_path(PERF_HTML_PATH));
-			exit(0);
+			exit(EXIT_SUCCESS);
 		} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
 			use_pager = 1;
 		} else if (!strcmp(cmd, "--no-pager")) {
@@ -258,7 +258,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 				printf("%s ", p->cmd);
 			}
 			putchar('\n');
-			exit(0);
+			exit(EXIT_SUCCESS);
 		} else if (!strcmp(cmd, "--list-opts")) {
 			unsigned int i;
 
@@ -267,7 +267,7 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
 				printf("--%s ", p->long_name);
 			}
 			putchar('\n');
-			exit(0);
+			exit(EXIT_SUCCESS);
 		} else if (!strcmp(cmd, "--debug")) {
 			if (*argc < 2) {
 				fprintf(stderr, "No variable specified for --debug.\n");
diff --git a/tools/perf/ui/tui/setup.c b/tools/perf/ui/tui/setup.c
index e9bfe856a5de..867c128d1f22 100644
--- a/tools/perf/ui/tui/setup.c
+++ b/tools/perf/ui/tui/setup.c
@@ -109,7 +109,7 @@ static void ui__signal_backtrace(int sig)
 	size = backtrace(stackdump, ARRAY_SIZE(stackdump));
 	backtrace_symbols_fd(stackdump, size, STDOUT_FILENO);
 
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
 #else
 # define ui__signal_backtrace  ui__signal
@@ -119,7 +119,7 @@ static void ui__signal(int sig)
 {
 	ui__exit(false);
 	psignal(sig, "perf");
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
 
 int ui__init(void)
diff --git a/tools/perf/util/dlfilter.c b/tools/perf/util/dlfilter.c
index ca33fbc5efde..11cf84ef30b1 100644
--- a/tools/perf/util/dlfilter.c
+++ b/tools/perf/util/dlfilter.c
@@ -611,5 +611,5 @@ int list_available_dlfilters(const struct option *opt __maybe_unused,
 
 	free(exec_path);
 out:
-	exit(0);
+	exit(EXIT_SUCCESS);
 }
diff --git a/tools/perf/util/help-unknown-cmd.c b/tools/perf/util/help-unknown-cmd.c
index ab9e16123626..fac794d75b14 100644
--- a/tools/perf/util/help-unknown-cmd.c
+++ b/tools/perf/util/help-unknown-cmd.c
@@ -114,5 +114,5 @@ const char *help_unknown_cmd(const char *cmd)
 			fprintf(stderr, "\t%s\n", main_cmds.names[i]->name);
 	}
 end:
-	exit(1);
+	exit(EXIT_FAILURE);
 }
-- 
2.32.0.432.gabb21c7263-goog


  parent reply	other threads:[~2021-07-29  6:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-29  6:24 [PATCH 0/3] Some exit code tidying Ian Rogers
2021-07-29  6:24 ` [PATCH 1/3] libperf: Prefer exit(EXIT_SUCCESS) over exit(0) Ian Rogers
2021-07-29  6:24 ` Ian Rogers [this message]
2021-07-29  6:24 ` [PATCH 3/3] perf test: Be more consistent in use of TEST_* Ian Rogers
2021-07-29 13:39   ` Riccardo Mancini
2021-07-29 18:24     ` Ian Rogers

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=20210729062451.1349566-3-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.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.