From: Tycho Andersen Date: Wed, 20 Dec 2017 17:52:38 +0000 (+0000) Subject: unlink lxc-init X-Git-Tag: lxc-2.0.10~387 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59b13dc1a473abeff40430c6bd126f50811281b2;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 c71c4d471..713a689e2 100644 --- a/src/lxc/lxc_init.c +++ b/src/lxc/lxc_init.c @@ -192,6 +192,30 @@ static void kill_children(pid_t pid) fclose(f); } +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[]) { int i, ret; @@ -293,6 +317,8 @@ int main(int argc, char *argv[]) lxc_setup_fs(); + remove_self(); + pid = fork(); if (pid < 0) exit(EXIT_FAILURE);