goto finish;
}
- r = verb_daemon_reload(argc, argv, userdata);
+ r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
+ if (r > 0)
+ r = 0;
}
finish:
}
int reload_with_fallback(void) {
- /* First, try systemd via D-Bus. */
- if (verb_daemon_reload(0, NULL, NULL) >= 0)
- return 0;
- /* Nothing else worked, so let's try signals */
assert(IN_SET(arg_action, ACTION_RELOAD, ACTION_REEXEC));
+ /* First, try systemd via D-Bus */
+ if (daemon_reload(arg_action, /* graceful= */ true) > 0)
+ return 0;
+
+ /* That didn't work, so let's try signals */
if (kill(1, arg_action == ACTION_RELOAD ? SIGHUP : SIGTERM) < 0)
return log_error_errno(errno, "kill() failed: %m");
int exec_telinit(char *argv[]) {
(void) rlimit_nofile_safe();
- execv(TELINIT, argv);
+ (void) execv(TELINIT, argv);
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Couldn't find an alternative telinit implementation to spawn.");
#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;
polkit_agent_open_maybe();
- switch (arg_action) {
+ switch (action) {
case ACTION_RELOAD:
method = "Reload";
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);
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;
}
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
+#include "systemctl.h"
+
+int daemon_reload(enum action, bool graceful);
+
int verb_daemon_reload(int argc, char *argv[], void *userdata);
r = 0;
- if (!arg_no_reload && !install_client_side())
- r = verb_daemon_reload(argc, argv, userdata);
+ if (!arg_no_reload && !install_client_side()) {
+ r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
+ if (r > 0)
+ r = 0;
+ }
end:
STRV_FOREACH_PAIR(original, tmp, paths) {
if (strv_isempty(names)) {
if (arg_no_reload || install_client_side())
return 0;
- return verb_daemon_reload(argc, argv, userdata);
+
+ r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
+ return r > 0 ? 0 : r;
}
if (streq(verb, "disable")) {
goto finish;
/* Try to reload if enabled */
- if (!arg_no_reload)
- r = verb_daemon_reload(argc, argv, userdata);
- else
+ if (!arg_no_reload) {
+ r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
+ if (r > 0)
+ r = 0;
+ } else
r = 0;
}
goto finish;
}
- r = verb_daemon_reload(argc, argv, userdata);
+ r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
+ if (r > 0)
+ r = 0;
}
finish:
goto finish;
/* Try to reload if enabled */
- if (!arg_no_reload)
- r = verb_daemon_reload(argc, argv, userdata);
- else
+ if (!arg_no_reload) {
+ r = daemon_reload(ACTION_RELOAD, /* graceful= */ false);
+ if (r > 0)
+ r = 0;
+ } else
r = 0;
}
{ "cat", 2, VERB_ANY, VERB_ONLINE_ONLY, verb_cat },
{ "status", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show },
{ "help", VERB_ANY, VERB_ANY, VERB_ONLINE_ONLY, verb_show },
- { "daemon-reload", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_daemon_reload },
- { "daemon-reexec", VERB_ANY, 1, VERB_ONLINE_ONLY, verb_daemon_reload },
+ { "daemon-reload", 1, 1, VERB_ONLINE_ONLY, verb_daemon_reload },
+ { "daemon-reexec", 1, 1, VERB_ONLINE_ONLY, verb_daemon_reload },
{ "log-level", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting },
{ "log-target", VERB_ANY, 2, VERB_ONLINE_ONLY, verb_log_setting },
{ "service-log-level", 2, 3, VERB_ONLINE_ONLY, verb_service_log_setting },