From: Tycho Andersen Date: Wed, 20 Dec 2017 17:52:38 +0000 (+0000) Subject: unlink lxc-init X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e14d827055df730ec85cbe26938a37d787f31998;p=thirdparty%2Flxc.git unlink lxc-init It's sort of an implementation detail that this exists at all, and we should probably not pollute the container's mount tables or FS with this. Signed-off-by: Tycho Andersen --- diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c index 7ec8a0def..08ef03ee4 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -74,6 +74,30 @@ static void usage(void) { " and does not need to be run by hand\n\n"); } +static void remove_self(void) +{ + char path[PATH_MAX]; + ssize_t n; + + n = readlink("/proc/self/exe", path, sizeof(path)); + if (n < 0) { + SYSERROR("Failed to readlink \"/proc/self/exe\""); + return; + } + + path[n] = 0; + + if (umount2(path, MNT_DETACH) < 0) { + SYSERROR("Failed to unmount \"%s\"", path); + return; + } + + if (unlink(path) < 0) { + SYSERROR("Failed to unlink \"%s\"", path); + return; + } +} + int main(int argc, char *argv[]) { pid_t pid; @@ -166,6 +190,8 @@ int main(int argc, char *argv[]) lxc_setup_fs(); + remove_self(); + pid = fork(); if (pid < 0)