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

+1 -1
View File
@@ -260,7 +260,6 @@ int run_interactive(char *cmd, char *fmt, ...)
int exec_runtask(char *cmd, char *args[]) int exec_runtask(char *cmd, char *args[])
{ {
size_t i;
char buf[1024] = ""; char buf[1024] = "";
char *argv[4] = { char *argv[4] = {
"sh", "sh",
@@ -268,6 +267,7 @@ int exec_runtask(char *cmd, char *args[])
buf, buf,
NULL NULL
}; };
size_t i;
strlcat(buf, cmd, sizeof(buf)); strlcat(buf, cmd, sizeof(buf));
for (i = 1; args[i]; i++) { 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) 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 */ /* Close all local non-console descriptors */
for (int fd = 3; fd < 128; fd++) for (int fd = 3; fd < 128; fd++)
close(fd); close(fd);
@@ -309,11 +315,6 @@ void do_shutdown(shutop_t op)
return; return;
} }
if (in_cont) {
sync();
goto done;
}
if (wdog) { if (wdog) {
print(kill(wdog->pid, SIGPWR) == 1, "Advising watchdog, system going down"); print(kill(wdog->pid, SIGPWR) == 1, "Advising watchdog, system going down");
do_sleep(2); 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. */ /* Call mdadm to mark any RAID array(s) as clean before halting. */
mdadm_wait(); mdadm_wait();
done: /* Reboot via watchdog or kernel, or shutdown? */ /* Reboot via watchdog or kernel, or shutdown? */
if (op == SHUT_REBOOT) { if (op == SHUT_REBOOT) {
if (wdog && wdog->pid > 1) { if (wdog && wdog->pid > 1) {
int timeout = 10; int timeout = 10;