summaryrefslogtreecommitdiffstats
path: root/src/systemctl/systemctl-daemon-reload.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2022-02-21 17:11:52 +0100
committerLennart Poettering <lennart@poettering.net>2022-02-22 14:15:08 +0100
commit623461c13074542b9a4dd2e7f605b6b7f8be5286 (patch)
tree3a5c12933192f53d53ba806a9e7aaf985d76263a /src/systemctl/systemctl-daemon-reload.c
parentsystemctl: systematically rename verb entrypoints verb_xyz() (diff)
downloadsystemd-623461c13074542b9a4dd2e7f605b6b7f8be5286.tar.xz
systemd-623461c13074542b9a4dd2e7f605b6b7f8be5286.zip
systemctl: rework daemon_reload() functions
Let's split out the inner parts of verb_daemon_reload() as a function daemon_reload() and then stop using the former outside of the verbs logic, and instead call the latter whenever we need to reload the daemon as auxiliary opeation. This should make our logic more systematic as we don't have to provide fake or misleading argc/argv to verb_daemon_reload() anymore.
Diffstat (limited to 'src/systemctl/systemctl-daemon-reload.c')
-rw-r--r--src/systemctl/systemctl-daemon-reload.c45
1 files changed, 31 insertions, 14 deletions
diff --git a/src/systemctl/systemctl-daemon-reload.c b/src/systemctl/systemctl-daemon-reload.c
index 35a10e84cc..33de7d161e 100644
--- a/src/systemctl/systemctl-daemon-reload.c
+++ b/src/systemctl/systemctl-daemon-reload.c
@@ -6,7 +6,7 @@
#include "systemctl-util.h"
#include "systemctl.h"
-int verb_daemon_reload(int argc, char *argv[], void *userdata) {
+int daemon_reload(enum action action, bool graceful) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL;
const char *method;
@@ -19,7 +19,7 @@ int verb_daemon_reload(int argc, char *argv[], void *userdata) {
polkit_agent_open_maybe();
- switch (arg_action) {
+ switch (action) {
case ACTION_RELOAD:
method = "Reload";
@@ -29,13 +29,8 @@ int verb_daemon_reload(int argc, char *argv[], void *userdata) {
method = "Reexecute";
break;
- case ACTION_SYSTEMCTL:
- method = streq(argv[0], "daemon-reexec") ? "Reexecute" :
- /* "daemon-reload" */ "Reload";
- break;
-
default:
- assert_not_reached();
+ return -EINVAL;
}
r = bus_message_new_method_call(bus, &m, bus_systemd_mgr, method);
@@ -50,14 +45,36 @@ int verb_daemon_reload(int argc, char *argv[], void *userdata) {
r = sd_bus_call(bus, m, DEFAULT_TIMEOUT_USEC * 2, &error, NULL);
/* On reexecution, we expect a disconnect, not a reply */
- if (IN_SET(r, -ETIMEDOUT, -ECONNRESET) && streq(method, "Reexecute"))
- r = 0;
+ if (IN_SET(r, -ETIMEDOUT, -ECONNRESET) && action == ACTION_REEXEC)
+ return 1;
+ if (r < 0) {
+ if (graceful) { /* If graceful mode is selected, debug log, but don't fail */
+ log_debug_errno(r, "Failed to reload daemon via the bus, ignoring: %s", bus_error_message(&error, r));
+ return 0;
+ }
- if (r < 0 && arg_action == ACTION_SYSTEMCTL)
return log_error_errno(r, "Failed to reload daemon: %s", bus_error_message(&error, r));
+ }
+
+ return 1;
+}
- /* Note that for the legacy commands (i.e. those with action != ACTION_SYSTEMCTL) we support
- * fallbacks to the old ways of doing things, hence don't log any error in that case here. */
+int verb_daemon_reload(int argc, char *argv[], void *userdata) {
+ enum action a;
+ int r;
+
+ assert(argc >= 1);
+
+ if (streq(argv[0], "daemon-reexec"))
+ a = ACTION_REEXEC;
+ else if (streq(argv[0], "daemon-reload"))
+ a = ACTION_RELOAD;
+ else
+ assert_not_reached();
+
+ r = daemon_reload(a, /* graceful= */ false);
+ if (r < 0)
+ return r;
- return r < 0 ? r : 0;
+ return 0;
}