]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
unlink lxc-init
authorTycho Andersen <tycho@tycho.ws>
Wed, 20 Dec 2017 17:52:38 +0000 (17:52 +0000)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 7 Feb 2018 11:30:16 +0000 (12:30 +0100)
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 <tycho@tycho.ws>
src/lxc/lxc_init.c

index 7ec8a0def0cd1f9754e9f27eec2ee6594d60ef21..08ef03ee4719e12df5b0b770976ff9d29e2e68ee 100644 (file)
@@ -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)