diff options
author | Jan Synacek <jsynacek@redhat.com> | 2015-08-24 14:54:22 +0200 |
---|---|---|
committer | Jan Synacek <jsynacek@redhat.com> | 2015-08-25 13:52:44 +0200 |
commit | 9ef15026c0e7e6600372056c43442c99ec53746e (patch) | |
tree | 7b82f423cb3499c100c1d2a2b5540d336d4928f9 /src/systemctl/systemctl.c | |
parent | 72aa2c2a2083362afda9f09805563848d54e31df (diff) |
logind/systemctl: introduce SetWallMessage and --message
Enable unprivileged users to set wall message on a shutdown
operation. When the message is set via the --message option,
it is logged together with the default shutdown message.
$ systemctl reboot --message "Applied kernel updates."
$ journalctl -b -1
...
systemd-logind[27]: System is rebooting. (Applied kernel updates.)
...
Diffstat (limited to 'src/systemctl/systemctl.c')
-rw-r--r-- | src/systemctl/systemctl.c | 102 |
1 files changed, 58 insertions, 44 deletions
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 1a9dbadbe1..3cb5f61868 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -2794,6 +2794,33 @@ 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", @@ -6260,6 +6287,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { ARG_PRESET_MODE, ARG_FIRMWARE_SETUP, ARG_NOW, + ARG_MESSAGE, }; static const struct option options[] = { @@ -6304,6 +6332,7 @@ static int systemctl_parse_argv(int argc, char *argv[]) { { "preset-mode", required_argument, NULL, ARG_PRESET_MODE }, { "firmware-setup", no_argument, NULL, ARG_FIRMWARE_SETUP }, { "now", no_argument, NULL, ARG_NOW }, + { "message", required_argument, NULL, ARG_MESSAGE }, {} }; @@ -6588,6 +6617,11 @@ static int systemctl_parse_argv(int argc, char *argv[]) { arg_now = true; break; + case ARG_MESSAGE: + if (strv_extend(&arg_wall, optarg) < 0) + return log_oom(); + break; + case '?': return -EINVAL; @@ -7356,30 +7390,20 @@ static int halt_main(sd_bus *bus) { if (!m) return log_oom(); - r = sd_bus_set_property( - b, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "WallMessage", - &error, - "s", m); - if (r < 0) { - log_warning_errno(r, "Failed to set WallMessage property in logind: %s", - bus_error_message(&error, r)); - sd_bus_error_free(&error); - } + r = sd_bus_call_method( + b, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "SetWallMessage", + &error, + NULL, + "sb", + m, + !arg_no_wall); - r = sd_bus_set_property( - b, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "EnableWallMessages", - &error, - "b", !arg_no_wall); if (r < 0) { - log_warning_errno(r, "Failed to set EnableWallMessages property in logind: %s", + log_warning_errno(r, "Failed to set wall message, ignoring: %s", bus_error_message(&error, r)); sd_bus_error_free(&error); } @@ -7537,30 +7561,20 @@ int main(int argc, char*argv[]) { } } - r = sd_bus_set_property( - b, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "WallMessage", - &error, - "s", arg_wall); - if (r < 0) { - log_warning_errno(r, "Failed to set WallMessage property in logind: %s", - bus_error_message(&error, r)); - sd_bus_error_free(&error); - } + r = sd_bus_call_method( + b, + "org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "SetWallMessage", + &error, + NULL, + "sb", + m, + !arg_no_wall); - r = sd_bus_set_property( - b, - "org.freedesktop.login1", - "/org/freedesktop/login1", - "org.freedesktop.login1.Manager", - "EnableWallMessages", - &error, - "b", !arg_no_wall); if (r < 0) { - log_warning_errno(r, "Failed to set EnableWallMessages property in logind: %s", + log_warning_errno(r, "Failed to set wall message, ignoring: %s", bus_error_message(&error, r)); sd_bus_error_free(&error); } |