summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-17 16:25:06 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-05-19 08:02:29 +0200
commitfddad5f4a66a68682892e3fa7f22ec2689786d33 (patch)
treedfd8b2ff5409ef8cf24f4d8b8e5d4de8236bc4ef /src
parentd5dcd00ba23e13b29bf9b8ad296f164a962825b5 (diff)
downloadsystemd-fddad5f4a66a68682892e3fa7f22ec2689786d33.tar.gz
analyze: allow verbs to return positive failure
No functional change is intended. The verbs where it wasn't immediately clear if the success exit status is 0 or >= 0 are changed to explicitly return 0. (I think it's better to be explicit than to rely on some call stack always returning 0 on success.) Some other functions are cleaned up to be more idiomatic.
Diffstat (limited to 'src')
-rw-r--r--src/analyze/analyze-blame.c6
-rw-r--r--src/analyze/analyze-calendar.c14
-rw-r--r--src/analyze/analyze-capability.c6
-rw-r--r--src/analyze/analyze-cat-config.c2
-rw-r--r--src/analyze/analyze-condition.c8
-rw-r--r--src/analyze/analyze-critical-chain.c2
-rw-r--r--src/analyze/analyze-dump.c6
-rw-r--r--src/analyze/analyze-exit-status.c6
-rw-r--r--src/analyze/analyze-filesystems.c2
-rw-r--r--src/analyze/analyze-log-control.c6
-rw-r--r--src/analyze/analyze-plot.c2
-rw-r--r--src/analyze/analyze-service-watchdogs.c2
-rw-r--r--src/analyze/analyze-syscall-filter.c2
-rw-r--r--src/analyze/analyze-time.c2
-rw-r--r--src/analyze/analyze-timestamp.c14
-rw-r--r--src/analyze/analyze-unit-files.c2
-rw-r--r--src/analyze/analyze-unit-paths.c2
-rw-r--r--src/analyze/analyze.c2
-rw-r--r--src/shared/verb-log-control.c25
19 files changed, 68 insertions, 43 deletions
diff --git a/src/analyze/analyze-blame.c b/src/analyze/analyze-blame.c
index 6cd6846956..c9112685f8 100644
--- a/src/analyze/analyze-blame.c
+++ b/src/analyze/analyze-blame.c
@@ -61,5 +61,9 @@ int verb_blame(int argc, char *argv[], void *userdata) {
pager_open(arg_pager_flags);
- return table_print(table, NULL);
+ r = table_print(table, NULL);
+ if (r < 0)
+ return r;
+
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-calendar.c b/src/analyze/analyze-calendar.c
index 8f6517fa8e..952fe95c2c 100644
--- a/src/analyze/analyze-calendar.c
+++ b/src/analyze/analyze-calendar.c
@@ -123,7 +123,7 @@ static int test_calendar_one(usec_t n, const char *p) {
}
int verb_calendar(int argc, char *argv[], void *userdata) {
- int ret = 0, r;
+ int r = 0;
usec_t n;
if (arg_base_time != USEC_INFINITY)
@@ -132,13 +132,15 @@ int verb_calendar(int argc, char *argv[], void *userdata) {
n = now(CLOCK_REALTIME); /* We want to use the same "base" for all expressions */
STRV_FOREACH(p, strv_skip(argv, 1)) {
- r = test_calendar_one(n, *p);
- if (ret == 0 && r < 0)
- ret = r;
+ int k;
- if (*(p + 1))
+ k = test_calendar_one(n, *p);
+ if (r == 0 && k < 0)
+ r = k;
+
+ if (p[1])
putchar('\n');
}
- return ret;
+ return r;
}
diff --git a/src/analyze/analyze-capability.c b/src/analyze/analyze-capability.c
index ebb205e7f2..8072175a84 100644
--- a/src/analyze/analyze-capability.c
+++ b/src/analyze/analyze-capability.c
@@ -48,5 +48,9 @@ int verb_capabilities(int argc, char *argv[], void *userdata) {
pager_open(arg_pager_flags);
- return table_print(table, NULL);
+ r = table_print(table, NULL);
+ if (r < 0)
+ return r;
+
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-cat-config.c b/src/analyze/analyze-cat-config.c
index 85ed8b01e0..d214ceaf42 100644
--- a/src/analyze/analyze-cat-config.c
+++ b/src/analyze/analyze-cat-config.c
@@ -42,5 +42,5 @@ int verb_cat_config(int argc, char *argv[], void *userdata) {
return r;
}
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-condition.c b/src/analyze/analyze-condition.c
index 011066f148..d1643b6180 100644
--- a/src/analyze/analyze-condition.c
+++ b/src/analyze/analyze-condition.c
@@ -137,5 +137,11 @@ static int verify_conditions(char **lines, LookupScope scope, const char *unit,
}
int verb_condition(int argc, char *argv[], void *userdata) {
- return verify_conditions(strv_skip(argv, 1), arg_scope, arg_unit, arg_root);
+ int r;
+
+ r = verify_conditions(strv_skip(argv, 1), arg_scope, arg_unit, arg_root);
+ if (r < 0)
+ return r;
+
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-critical-chain.c b/src/analyze/analyze-critical-chain.c
index a3d993a373..bb077e2293 100644
--- a/src/analyze/analyze-critical-chain.c
+++ b/src/analyze/analyze-critical-chain.c
@@ -226,5 +226,5 @@ int verb_critical_chain(int argc, char *argv[], void *userdata) {
else
list_dependencies(bus, SPECIAL_DEFAULT_TARGET);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-dump.c b/src/analyze/analyze-dump.c
index 24094ce614..448ce09bd7 100644
--- a/src/analyze/analyze-dump.c
+++ b/src/analyze/analyze-dump.c
@@ -60,5 +60,9 @@ int verb_dump(int argc, char *argv[], void *userdata) {
return bus_log_parse_error(r);
fflush(stdout);
- return copy_bytes(fd, STDOUT_FILENO, UINT64_MAX, 0);
+ r = copy_bytes(fd, STDOUT_FILENO, UINT64_MAX, 0);
+ if (r < 0)
+ return r;
+
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-exit-status.c b/src/analyze/analyze-exit-status.c
index a3f21c60ea..3a8d3f4b2a 100644
--- a/src/analyze/analyze-exit-status.c
+++ b/src/analyze/analyze-exit-status.c
@@ -48,5 +48,9 @@ int verb_exit_status(int argc, char *argv[], void *userdata) {
pager_open(arg_pager_flags);
- return table_print(table, NULL);
+ r = table_print(table, NULL);
+ if (r < 0)
+ return r;
+
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-filesystems.c b/src/analyze/analyze-filesystems.c
index 66d8397e31..e30b3a6ac6 100644
--- a/src/analyze/analyze-filesystems.c
+++ b/src/analyze/analyze-filesystems.c
@@ -221,5 +221,5 @@ int verb_filesystems(int argc, char *argv[], void *userdata) {
first = false;
}
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-log-control.c b/src/analyze/analyze-log-control.c
index d31081b6a0..cead0e833f 100644
--- a/src/analyze/analyze-log-control.c
+++ b/src/analyze/analyze-log-control.c
@@ -14,5 +14,9 @@ int verb_log_control(int argc, char *argv[], void *userdata) {
if (r < 0)
return bus_log_connect_error(r, arg_transport);
- return verb_log_control_common(bus, "org.freedesktop.systemd1", argv[0], argc == 2 ? argv[1] : NULL);
+ r = verb_log_control_common(bus, "org.freedesktop.systemd1", argv[0], argc == 2 ? argv[1] : NULL);
+ if (r < 0)
+ return r;
+
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-plot.c b/src/analyze/analyze-plot.c
index edfdfba144..100bdc3787 100644
--- a/src/analyze/analyze-plot.c
+++ b/src/analyze/analyze-plot.c
@@ -391,5 +391,5 @@ int verb_plot(int argc, char *argv[], void *userdata) {
svg("</svg>\n");
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-service-watchdogs.c b/src/analyze/analyze-service-watchdogs.c
index 96aed32b55..6535eb1a89 100644
--- a/src/analyze/analyze-service-watchdogs.c
+++ b/src/analyze/analyze-service-watchdogs.c
@@ -37,5 +37,5 @@ int verb_service_watchdogs(int argc, char *argv[], void *userdata) {
return log_error_errno(r, "Failed to set service-watchdog state: %s", bus_error_message(&error, r));
}
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-syscall-filter.c b/src/analyze/analyze-syscall-filter.c
index 582a043088..308b1724e5 100644
--- a/src/analyze/analyze-syscall-filter.c
+++ b/src/analyze/analyze-syscall-filter.c
@@ -176,7 +176,7 @@ int verb_syscall_filters(int argc, char *argv[], void *userdata) {
first = false;
}
- return 0;
+ return EXIT_SUCCESS;
}
#else
diff --git a/src/analyze/analyze-time.c b/src/analyze/analyze-time.c
index e5744a218e..c233b1f085 100644
--- a/src/analyze/analyze-time.c
+++ b/src/analyze/analyze-time.c
@@ -18,5 +18,5 @@ int verb_time(int argc, char *argv[], void *userdata) {
return r;
puts(buf);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-timestamp.c b/src/analyze/analyze-timestamp.c
index ddf34ab75f..79764e014e 100644
--- a/src/analyze/analyze-timestamp.c
+++ b/src/analyze/analyze-timestamp.c
@@ -79,16 +79,18 @@ static int test_timestamp_one(const char *p) {
}
int verb_timestamp(int argc, char *argv[], void *userdata) {
- int ret = 0, r;
+ int r = 0;
STRV_FOREACH(p, strv_skip(argv, 1)) {
- r = test_timestamp_one(*p);
- if (ret == 0 && r < 0)
- ret = r;
+ int k;
- if (*(p + 1))
+ k = test_timestamp_one(*p);
+ if (r == 0 && k < 0)
+ r = k;
+
+ if (p[1])
putchar('\n');
}
- return ret;
+ return r;
}
diff --git a/src/analyze/analyze-unit-files.c b/src/analyze/analyze-unit-files.c
index f07ec3e56c..ec9be336e1 100644
--- a/src/analyze/analyze-unit-files.c
+++ b/src/analyze/analyze-unit-files.c
@@ -46,5 +46,5 @@ int verb_unit_files(int argc, char *argv[], void *userdata) {
printf("aliases: %s ← %s\n", k, j);
}
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze-unit-paths.c b/src/analyze/analyze-unit-paths.c
index 6fa1527dd6..c2254619bc 100644
--- a/src/analyze/analyze-unit-paths.c
+++ b/src/analyze/analyze-unit-paths.c
@@ -16,5 +16,5 @@ int verb_unit_paths(int argc, char *argv[], void *userdata) {
STRV_FOREACH(p, paths.search_path)
puts(*p);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c
index cb83e73877..2935ecea7a 100644
--- a/src/analyze/analyze.c
+++ b/src/analyze/analyze.c
@@ -607,4 +607,4 @@ static int run(int argc, char *argv[]) {
return dispatch_verb(argc, argv, verbs, NULL);
}
-DEFINE_MAIN_FUNCTION(run);
+DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE(run);
diff --git a/src/shared/verb-log-control.c b/src/shared/verb-log-control.c
index eea0e8151a..555fb9ff7c 100644
--- a/src/shared/verb-log-control.c
+++ b/src/shared/verb-log-control.c
@@ -30,27 +30,22 @@ int verb_log_control_common(sd_bus *bus, const char *destination, const char *ve
r = bus_set_property(bus, &bloc,
level ? "LogLevel" : "LogTarget",
&error, "s", value);
- if (r >= 0)
- return 0;
-
- log_error_errno(r, "Failed to set log %s of %s to %s: %s",
- level ? "level" : "target",
- bloc.destination, value, bus_error_message(&error, r));
+ if (r < 0)
+ return log_error_errno(r, "Failed to set log %s of %s to %s: %s",
+ level ? "level" : "target",
+ bloc.destination, value, bus_error_message(&error, r));
} else {
_cleanup_free_ char *t = NULL;
r = bus_get_property_string(bus, &bloc,
level ? "LogLevel" : "LogTarget",
&error, &t);
- if (r >= 0) {
- puts(t);
- return 0;
- }
-
- log_error_errno(r, "Failed to get log %s of %s: %s",
- level ? "level" : "target",
- bloc.destination, bus_error_message(&error, r));
+ if (r < 0)
+ return log_error_errno(r, "Failed to get log %s of %s: %s",
+ level ? "level" : "target",
+ bloc.destination, bus_error_message(&error, r));
+ puts(t);
}
- return r;
+ return 0;
}