diff --git a/NEWS b/NEWS index 489b0ae1..9da14259 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,8 @@ xbps-0.46 (???): + * xbps-uchroot(1): now handles SIG{INT,TERM,QUIT} signals to clean up the + temporary masterdir if `-t` is set. + * /usr/sbin is now a symlink in void, don't consider it as obsolete and never remove it even if it was detected as obsolete. diff --git a/bin/xbps-uchroot/main.c b/bin/xbps-uchroot/main.c index fa2a6570..c06b3385 100644 --- a/bin/xbps-uchroot/main.c +++ b/bin/xbps-uchroot/main.c @@ -50,6 +50,7 @@ #include #include /* PATH_MAX */ #include +#include #include #include "queue.h" @@ -144,6 +145,19 @@ cleanup_overlayfs(void) rmdir(tmpdir); } +static void +sighandler_cleanup(int signum) +{ + switch (signum) { + case SIGINT: + case SIGTERM: + case SIGQUIT: + cleanup_overlayfs(); + break; + } + _exit(signum); +} + static void add_bindmount(char *bm) { @@ -261,6 +275,7 @@ setup_overlayfs(const char *chrootdir, uid_t ruid, gid_t rgid, bool tmpfs, const int main(int argc, char **argv) { + struct sigaction sa; uid_t ruid, euid, suid; gid_t rgid, egid, sgid; const char *chrootdir, *tmpfs_opts, *cmd, *argv0; @@ -327,6 +342,15 @@ main(int argc, char **argv) die("chown tmpdir %s", tmpdir); } + /* + * Register a signal handler to clean up temporary masterdir. + */ + memset(&sa, 0, sizeof(sa)); + sa.sa_handler = sighandler_cleanup; + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + sigaction(SIGQUIT, &sa, NULL); + clone_flags = (SIGCHLD|CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUTS|CLONE_NEWPID); if (openvz_container()) { /*