summaryrefslogtreecommitdiff
path: root/src/systemctl/systemctl.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2015-09-24 11:51:51 +0200
committerLennart Poettering <lennart@poettering.net>2015-09-29 21:55:51 +0200
commitf2d11d35e90d5143d2bc6103ff451778909644f0 (patch)
treebb9f0ac4d0dbfbf7ae45bf56def8fb26b37af74b /src/systemctl/systemctl.c
parentb9e74c399458a1146894ce371e7d85c60658110c (diff)
systemctl: introduce a single function to set the wall message
Let's not have the same code three times, but reduce it to one function.
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r--src/systemctl/systemctl.c110
1 files changed, 35 insertions, 75 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 2b9de5d016..4de01d91d1 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -2760,6 +2760,37 @@ static int start_unit(sd_bus *bus, char **args) {
return r;
}
+static int set_wall_message(sd_bus *bus) {
+#ifdef HAVE_LOGIND
+ _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
+ _cleanup_free_ char *m = NULL;
+ int r;
+
+ assert(bus);
+
+ m = strv_join(arg_wall, " ");
+ if (!m)
+ return log_oom();
+
+ r = sd_bus_call_method(
+ bus,
+ "org.freedesktop.login1",
+ "/org/freedesktop/login1",
+ "org.freedesktop.login1.Manager",
+ "SetWallMessage",
+ &error,
+ NULL,
+ "sb",
+ m,
+ !arg_no_wall);
+
+ if (r < 0)
+ return log_warning_errno(r, "Failed to set wall message, ignoring: %s", bus_error_message(&error, r));
+
+#endif
+ return 0;
+}
+
/* Ask systemd-logind, which might grant access to unprivileged users
* through PolicyKit */
static int reboot_with_logind(sd_bus *bus, enum action a) {
@@ -2773,6 +2804,8 @@ static int reboot_with_logind(sd_bus *bus, enum action a) {
polkit_agent_open_if_enabled();
+ (void) set_wall_message(bus);
+
switch (a) {
case ACTION_REBOOT:
@@ -2804,33 +2837,6 @@ static int reboot_with_logind(sd_bus *bus, enum action a) {
return -EINVAL;
}
- if (!strv_isempty(arg_wall)) {
- _cleanup_free_ char *m;
-
- m = strv_join(arg_wall, " ");
- if (!m)
- return log_oom();
-
- r = sd_bus_call_method(
- bus,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "SetWallMessage",
- &error,
- NULL,
- "sb",
- m,
- !arg_no_wall);
-
- if (r < 0) {
- log_warning_errno(r, "Failed to set wall message, ignoring: %s",
- bus_error_message(&error, r));
- sd_bus_error_free(&error);
- }
- }
-
-
r = sd_bus_call_method(
bus,
"org.freedesktop.login1",
@@ -7455,7 +7461,6 @@ static int halt_main(sd_bus *bus) {
if (arg_when > 0) {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_flush_close_unref_ sd_bus *b = NULL;
- _cleanup_free_ char *m = NULL;
const char *action;
assert(geteuid() == 0);
@@ -7469,27 +7474,7 @@ static int halt_main(sd_bus *bus) {
if (r < 0)
return log_error_errno(r, "Unable to open system bus: %m");
- m = strv_join(arg_wall, " ");
- if (!m)
- return log_oom();
-
- r = sd_bus_call_method(
- b,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "SetWallMessage",
- &error,
- NULL,
- "sb",
- m,
- !arg_no_wall);
-
- if (r < 0) {
- log_warning_errno(r, "Failed to set wall message, ignoring: %s",
- bus_error_message(&error, r));
- sd_bus_error_free(&error);
- }
+ (void) set_wall_message(b);
switch (arg_action) {
case ACTION_HALT:
@@ -7642,7 +7627,6 @@ int main(int argc, char*argv[]) {
case ACTION_CANCEL_SHUTDOWN: {
_cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
_cleanup_bus_flush_close_unref_ sd_bus *b = NULL;
- _cleanup_free_ char *m = NULL;
if (avoid_bus()) {
log_error("Unable to perform operation without bus connection.");
@@ -7653,31 +7637,7 @@ int main(int argc, char*argv[]) {
if (r < 0)
return log_error_errno(r, "Unable to open system bus: %m");
- if (arg_wall) {
- m = strv_join(arg_wall, " ");
- if (!m) {
- r = log_oom();
- goto finish;
- }
- }
-
- r = sd_bus_call_method(
- b,
- "org.freedesktop.login1",
- "/org/freedesktop/login1",
- "org.freedesktop.login1.Manager",
- "SetWallMessage",
- &error,
- NULL,
- "sb",
- m,
- !arg_no_wall);
-
- if (r < 0) {
- log_warning_errno(r, "Failed to set wall message, ignoring: %s",
- bus_error_message(&error, r));
- sd_bus_error_free(&error);
- }
+ (void) set_wall_message(b);
r = sd_bus_call_method(
b,