Simplify shutdown in container, call _exit()

Calling _exit(2) lets libc do most of the cleanup we want when shutting
down while in a container.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-03-24 21:56:47 +01:00
1 parent 094e00d405
commit 2002157032
2 files changed
+8 -7

No files matched your search

+7 -6
View File
@@ -296,6 +296,12 @@ void do_shutdown(shutop_t op)
while (waitpid(-1, NULL, WNOHANG) > 0)
;
if (in_cont) {
if (osheading)
logit(LOG_CONSOLE | LOG_NOTICE, "%s, shutting down container.", osheading);
_exit(0);
}
/* Close all local non-console descriptors */
for (int fd = 3; fd < 128; fd++)
close(fd);
@@ -309,11 +315,6 @@ void do_shutdown(shutop_t op)
return;
}
if (in_cont) {
sync();
goto done;
}
if (wdog) {
print(kill(wdog->pid, SIGPWR) == 1, "Advising watchdog, system going down");
do_sleep(2);
@@ -336,7 +337,7 @@ void do_shutdown(shutop_t op)
/* Call mdadm to mark any RAID array(s) as clean before halting. */
mdadm_wait();
done: /* Reboot via watchdog or kernel, or shutdown? */
/* Reboot via watchdog or kernel, or shutdown? */
if (op == SHUT_REBOOT) {
if (wdog && wdog->pid > 1) {
int timeout = 10;