e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack This file is part of systemd.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack Copyright 2015 Daniel Mack
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack systemd is free software; you can redistribute it and/or modify it
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack under the terms of the GNU Lesser General Public License as published by
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack the Free Software Foundation; either version 2.1 of the License, or
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack (at your option) any later version.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack systemd is distributed in the hope that it will be useful, but
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack WITHOUT ANY WARRANTY; without even the implied warranty of
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack Lesser General Public License for more details.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack You should have received a copy of the GNU Lesser General Public License
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack along with systemd; If not, see <http://www.gnu.org/licenses/>.
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack_const_ static usec_t when_wall(usec_t n, usec_t elapse) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack unsigned int i;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack /* If the time is already passed, then don't announce */
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack return left - wall_timers[i-1] * USEC_PER_MINUTE;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackbool logind_wall_tty_filter(const char *tty, void *userdata) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack return true;
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack return !streq(tty + 5, m->scheduled_shutdown_tty);
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack r = asprintf(&l, "%s%sThe system is going down for %s %s%s!",
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack left ? format_timestamp(date, sizeof(date), m->scheduled_shutdown_timeout) : "");
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack if (r < 0) {
d02608170e599b1ffbc7c9a22062bae2579d6e36Lennart Poettering utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid),
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack next = when_wall(n, m->scheduled_shutdown_timeout);
c2a23db0b91faca3795099fd4b41587bac170ff7Daniel Mack return log_error_errno(r, "sd_event_source_set_time() failed. %m");
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack r = sd_event_source_set_enabled(s, SD_EVENT_ONESHOT);
c2a23db0b91faca3795099fd4b41587bac170ff7Daniel Mack return log_error_errno(r, "sd_event_source_set_enabled() failed. %m");
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mackint manager_setup_wall_message_timer(Manager *m) {
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack /* wall message handling */
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack /* Warn immediately if less than 15 minutes are left */
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack r = sd_event_source_set_time(m->wall_message_timeout_source, n + elapse);
c2a23db0b91faca3795099fd4b41587bac170ff7Daniel Mack return log_error_errno(r, "sd_event_source_set_time() failed. %m");
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack r = sd_event_source_set_enabled(m->wall_message_timeout_source, SD_EVENT_ONESHOT);
c2a23db0b91faca3795099fd4b41587bac170ff7Daniel Mack return log_error_errno(r, "sd_event_source_set_enabled() failed. %m");
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack r = sd_event_add_time(m->event, &m->wall_message_timeout_source,
e2fa5721c3ee5ea400b99a6463e8c1c257e20415Daniel Mack CLOCK_REALTIME, n + elapse, 0, wall_message_timeout_handler, m);
c2a23db0b91faca3795099fd4b41587bac170ff7Daniel Mack return log_error_errno(r, "sd_event_add_time() failed. %m");