chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
vconsole: make sure we don't merge configuration settings from different sources
[elogind.git]
/
src
/
shutdownd.c
diff --git
a/src/shutdownd.c
b/src/shutdownd.c
index d88982453653a25a6976d180482e45b0fed55020..72a28018cf565ac824c766b605d88ed6f30161aa 100644
(file)
--- a/
src/shutdownd.c
+++ b/
src/shutdownd.c
@@
-99,30
+99,31
@@
static int read_packet(int fd, struct shutdownd_command *_c) {
return 1;
}
return 1;
}
-static void warn_wall(struct shutdownd_command *c) {
+static void warn_wall(
usec_t n,
struct shutdownd_command *c) {
assert(c);
assert(c->warn_wall);
assert(c);
assert(c->warn_wall);
+ if (n >= c->elapse)
+ return;
+
if (c->wall_message[0])
utmp_wall(c->wall_message);
else {
char date[FORMAT_TIMESTAMP_MAX];
const char* prefix;
if (c->wall_message[0])
utmp_wall(c->wall_message);
else {
char date[FORMAT_TIMESTAMP_MAX];
const char* prefix;
- char *l;
+ char *l
= NULL
;
if (c->mode == 'H')
if (c->mode == 'H')
- prefix = "The system is going down for system halt at";
+ prefix = "The system is going down for system halt at
";
else if (c->mode == 'P')
else if (c->mode == 'P')
- prefix = "The system is going down for power-off at";
+ prefix = "The system is going down for power-off at
";
else if (c->mode == 'r')
else if (c->mode == 'r')
- prefix = "The system is going down for reboot at";
+ prefix = "The system is going down for reboot at
";
else
assert_not_reached("Unknown mode!");
else
assert_not_reached("Unknown mode!");
- if (asprintf(&l, "%s %s!",
- prefix,
- format_timestamp(date, sizeof(date), c->elapse)) < 0)
+ if (asprintf(&l, "%s%s!", prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0)
log_error("Failed to allocate wall message");
else {
utmp_wall(l);
log_error("Failed to allocate wall message");
else {
utmp_wall(l);
@@
-151,8
+152,10
@@
static usec_t when_wall(usec_t n, usec_t elapse) {
left = elapse - n;
for (i = 0; i < ELEMENTSOF(table); i++)
left = elapse - n;
for (i = 0; i < ELEMENTSOF(table); i++)
- if (n + table[i].delay >= elapse)
+ if (n + table[i].delay >= elapse)
{
sub = ((left / table[i].interval) * table[i].interval);
sub = ((left / table[i].interval) * table[i].interval);
+ break;
+ }
if (i >= ELEMENTSOF(table))
sub = ((left / USEC_PER_HOUR) * USEC_PER_HOUR);
if (i >= ELEMENTSOF(table))
sub = ((left / USEC_PER_HOUR) * USEC_PER_HOUR);
@@
-173,7
+176,7
@@
int main(int argc, char *argv[]) {
_FD_MAX
};
_FD_MAX
};
- int r =
4
, n_fds;
+ int r =
EXIT_FAILURE
, n_fds;
int one = 1;
struct shutdownd_command c;
struct pollfd pollfd[_FD_MAX];
int one = 1;
struct shutdownd_command c;
struct pollfd pollfd[_FD_MAX];
@@
-182,30
+185,31
@@
int main(int argc, char *argv[]) {
if (getppid() != 1) {
log_error("This program should be invoked by init only.");
if (getppid() != 1) {
log_error("This program should be invoked by init only.");
- return
1
;
+ return
EXIT_FAILURE
;
}
if (argc > 1) {
log_error("This program does not take arguments.");
}
if (argc > 1) {
log_error("This program does not take arguments.");
- return
1
;
+ return
EXIT_FAILURE
;
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
log_parse_environment();
}
log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
log_parse_environment();
+ log_open();
if ((n_fds = sd_listen_fds(true)) < 0) {
log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
if ((n_fds = sd_listen_fds(true)) < 0) {
log_error("Failed to read listening file descriptors from environment: %s", strerror(-r));
- return
1
;
+ return
EXIT_FAILURE
;
}
if (n_fds != 1) {
log_error("Need exactly one file descriptor.");
}
if (n_fds != 1) {
log_error("Need exactly one file descriptor.");
- return
2
;
+ return
EXIT_FAILURE
;
}
if (setsockopt(SD_LISTEN_FDS_START, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
log_error("SO_PASSCRED failed: %m");
}
if (setsockopt(SD_LISTEN_FDS_START, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one)) < 0) {
log_error("SO_PASSCRED failed: %m");
- return
3
;
+ return
EXIT_FAILURE
;
}
zero(c);
}
zero(c);
@@
-271,7
+275,7
@@
int main(int argc, char *argv[]) {
/* Warn immediately if less than 15 minutes are left */
if (n < c.elapse &&
n + 15*USEC_PER_MINUTE >= c.elapse)
/* Warn immediately if less than 15 minutes are left */
if (n < c.elapse &&
n + 15*USEC_PER_MINUTE >= c.elapse)
- warn_wall(&c);
+ warn_wall(
n,
&c);
}
/* Disallow logins 5 minutes prior to shutdown */
}
/* Disallow logins 5 minutes prior to shutdown */
@@
-299,7
+303,7
@@
int main(int argc, char *argv[]) {
if (pollfd[FD_WALL_TIMER].revents) {
struct itimerspec its;
if (pollfd[FD_WALL_TIMER].revents) {
struct itimerspec its;
- warn_wall(&c);
+ warn_wall(
n,
&c);
flush_fd(pollfd[FD_WALL_TIMER].fd);
/* Restart timer */
flush_fd(pollfd[FD_WALL_TIMER].fd);
/* Restart timer */
@@
-314,6
+318,8
@@
int main(int argc, char *argv[]) {
if (pollfd[FD_NOLOGIN_TIMER].revents) {
int e;
if (pollfd[FD_NOLOGIN_TIMER].revents) {
int e;
+ log_info("Creating /etc/nologin, blocking further logins...");
+
if ((e = touch("/etc/nologin")) < 0)
log_error("Failed to create /etc/nologin: %s", strerror(-e));
else
if ((e = touch("/etc/nologin")) < 0)
log_error("Failed to create /etc/nologin: %s", strerror(-e));
else
@@
-329,7
+335,7
@@
int main(int argc, char *argv[]) {
} while (c.elapse > 0);
} while (c.elapse > 0);
- r =
0
;
+ r =
EXIT_SUCCESS
;
log_debug("systemd-shutdownd stopped as pid %lu", (unsigned long) getpid());
log_debug("systemd-shutdownd stopped as pid %lu", (unsigned long) getpid());
@@
-339,6
+345,9
@@
finish:
if (pollfd[i].fd >= 0)
close_nointr_nofail(pollfd[i].fd);
if (pollfd[i].fd >= 0)
close_nointr_nofail(pollfd[i].fd);
+ if (unlink_nologin)
+ unlink("/etc/nologin");
+
if (exec_shutdown) {
char sw[3];
if (exec_shutdown) {
char sw[3];
@@
-346,13
+355,17
@@
finish:
sw[1] = c.mode;
sw[2] = 0;
sw[1] = c.mode;
sw[2] = 0;
- execl(SYSTEMCTL_BINARY_PATH, "shutdown", sw, "now", NULL);
+ execl(SYSTEMCTL_BINARY_PATH,
+ "shutdown",
+ sw,
+ "now",
+ (c.warn_wall && c.wall_message[0]) ? c.wall_message :
+ (c.warn_wall ? NULL : "--no-wall"),
+ NULL);
+
log_error("Failed to execute /sbin/shutdown: %m");
}
log_error("Failed to execute /sbin/shutdown: %m");
}
- if (unlink_nologin)
- unlink("/etc/nologin");
-
sd_notify(false,
"STATUS=Exiting...");
sd_notify(false,
"STATUS=Exiting...");