xbps-uchroot: handle SIG{INT,TERM,QUIT} signals to cleanup temp masterdir.

This commit is contained in:
Juan RP 2015-06-11 11:21:35 +02:00
parent 1774d17e40
commit 5ebd4a6dfb
2 changed files with 27 additions and 0 deletions

3
NEWS
View File

@ -1,5 +1,8 @@
xbps-0.46 (???): 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 * /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. remove it even if it was detected as obsolete.

View File

@ -50,6 +50,7 @@
#include <sched.h> #include <sched.h>
#include <limits.h> /* PATH_MAX */ #include <limits.h> /* PATH_MAX */
#include <ftw.h> #include <ftw.h>
#include <signal.h>
#include <xbps.h> #include <xbps.h>
#include "queue.h" #include "queue.h"
@ -144,6 +145,19 @@ cleanup_overlayfs(void)
rmdir(tmpdir); rmdir(tmpdir);
} }
static void
sighandler_cleanup(int signum)
{
switch (signum) {
case SIGINT:
case SIGTERM:
case SIGQUIT:
cleanup_overlayfs();
break;
}
_exit(signum);
}
static void static void
add_bindmount(char *bm) add_bindmount(char *bm)
{ {
@ -261,6 +275,7 @@ setup_overlayfs(const char *chrootdir, uid_t ruid, gid_t rgid, bool tmpfs, const
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
struct sigaction sa;
uid_t ruid, euid, suid; uid_t ruid, euid, suid;
gid_t rgid, egid, sgid; gid_t rgid, egid, sgid;
const char *chrootdir, *tmpfs_opts, *cmd, *argv0; const char *chrootdir, *tmpfs_opts, *cmd, *argv0;
@ -327,6 +342,15 @@ main(int argc, char **argv)
die("chown tmpdir %s", tmpdir); 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); clone_flags = (SIGCHLD|CLONE_NEWNS|CLONE_NEWIPC|CLONE_NEWUTS|CLONE_NEWPID);
if (openvz_container()) { if (openvz_container()) {
/* /*