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
2022-03-24 21:56:47 +01:00
parent 094e00d405
commit 2002157032
2 changed files with 8 additions and 7 deletions
+1 -1
View File
@@ -260,7 +260,6 @@ int run_interactive(char *cmd, char *fmt, ...)
int exec_runtask(char *cmd, char *args[])
{
size_t i;
char buf[1024] = "";
char *argv[4] = {
"sh",
@@ -268,6 +267,7 @@ int exec_runtask(char *cmd, char *args[])
buf,
NULL
};
size_t i;
strlcat(buf, cmd, sizeof(buf));
for (i = 1; args[i]; i++) {
+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;