logind-utmp.c revision c2a23db0b91faca3795099fd4b41587bac170ff7
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen This file is part of systemd.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen Copyright 2015 Daniel Mack
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen systemd is free software; you can redistribute it and/or modify it
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen under the terms of the GNU Lesser General Public License as published by
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen the Free Software Foundation; either version 2.1 of the License, or
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen (at your option) any later version.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen systemd is distributed in the hope that it will be useful, but
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen WITHOUT ANY WARRANTY; without even the implied warranty of
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen Lesser General Public License for more details.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen You should have received a copy of the GNU Lesser General Public License
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen along with systemd; If not, see <http://www.gnu.org/licenses/>.
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering_const_ static usec_t when_wall(usec_t n, usec_t elapse) {
8fcde01280adcbd07e8205b91ac52b06305b6208Lennart Poettering unsigned int i;
8b43440b7ef4b81c69c31de7ff820dc07a780254Lennart Poettering static const int wall_timers[] = {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen /* If the time is already passed, then don't announce */
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen return left - wall_timers[i-1] * USEC_PER_MINUTE;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmekbool logind_wall_tty_filter(const char *tty, void *userdata) {
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return !streq(tty + 5, m->scheduled_shutdown_tty);
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen r = asprintf(&l, "%s%sThe system is going down for %s %s%s!",
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen left ? format_timestamp(date, sizeof(date), m->scheduled_shutdown_timeout) : "");
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen utmp_wall(l, lookup_uid(m->scheduled_shutdown_uid),
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen m->scheduled_shutdown_tty, logind_wall_tty_filter, m);
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen next = when_wall(n, m->scheduled_shutdown_timeout);
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return log_error_errno(r, "sd_event_source_set_time() failed. %m");
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen r = sd_event_source_set_enabled(s, SD_EVENT_ONESHOT);
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return log_error_errno(r, "sd_event_source_set_enabled() failed. %m");
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersenint manager_setup_wall_message_timer(Manager *m) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen /* wall message handling */
6e37cd2f4af8928d905203108a4331e375d7127cThomas Hindoe Paaboel Andersen if (isempty(m->scheduled_shutdown_type)) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen /* Warn immediately if less than 15 minutes are left */
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek r = sd_event_source_set_time(m->wall_message_timeout_source, n + elapse);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return log_error_errno(r, "sd_event_source_set_time() failed. %m");
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen r = sd_event_source_set_enabled(m->wall_message_timeout_source, SD_EVENT_ONESHOT);
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen return log_error_errno(r, "sd_event_source_set_enabled() failed. %m");
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek r = sd_event_add_time(m->event, &m->wall_message_timeout_source,
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek CLOCK_REALTIME, n + elapse, 0, wall_message_timeout_handler, m);
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek return log_error_errno(r, "sd_event_add_time() failed. %m");