logind-utmp.c revision e2fa5721c3ee5ea400b99a6463e8c1c257e20415
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2015 Daniel Mack
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <pwd.h>
#include "sd-messages.h"
#include "strv.h"
#include "special.h"
#include "unit-name.h"
#include "audit.h"
#include "bus-util.h"
#include "bus-error.h"
#include "bus-common-errors.h"
#include "logind.h"
#include "formats-util.h"
#include "utmp-wtmp.h"
unsigned int i;
static const int wall_timers[] = {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
25, 40, 55, 70, 100, 130, 150, 180,
};
/* If the time is already passed, then don't announce */
if (n >= elapse)
return 0;
return left % USEC_PER_HOUR;
}
assert(m);
return true;
}
char date[FORMAT_TIMESTAMP_MAX] = {};
_cleanup_free_ char *l = NULL;
int r;
assert(m);
if (!m->enable_wall_messages)
return 0;
left = m->scheduled_shutdown_timeout > n;
r = asprintf(&l, "%s%sThe system is going down for %s %s%s!",
strempty(m->wall_message),
if (r < 0) {
log_oom();
return 0;
}
return 1;
}
static int wall_message_timeout_handler(
sd_event_source *s,
void *userdata) {
int r;
assert(m);
assert(s == m->wall_message_timeout_source);
n = now(CLOCK_REALTIME);
r = warn_wall(m, n);
if (r == 0)
return 0;
if (next > 0) {
r = sd_event_source_set_time(s, n + next);
if (r < 0)
return log_error_errno(r, "sd_event_source_set_time() failed. %m\n");
if (r < 0)
return log_error_errno(r, "sd_event_source_set_enabled() failed. %m\n");
}
return 0;
}
int manager_setup_wall_message_timer(Manager *m) {
int r;
assert(m);
n = now(CLOCK_REALTIME);
/* wall message handling */
if (isempty(m->scheduled_shutdown_type)) {
warn_wall(m, n);
return 0;
}
if (elapse < n)
return 0;
/* Warn immediately if less than 15 minutes are left */
r = warn_wall(m, n);
if (r == 0)
return 0;
}
if (elapse == 0)
return 0;
if (m->wall_message_timeout_source) {
if (r < 0)
return log_error_errno(r, "sd_event_source_set_time() failed. %m\n");
if (r < 0)
return log_error_errno(r, "sd_event_source_set_enabled() failed. %m\n");
} else {
if (r < 0)
return log_error_errno(r, "sd_event_add_time() failed. %m\n");
}
return 0;
}