]> git.proxmox.com Git - mirror_lxc.git/commitdiff
unlink lxc-init
authorTycho Andersen <tycho@tycho.ws>
Wed, 20 Dec 2017 17:52:38 +0000 (17:52 +0000)
committerTycho Andersen <tycho@tycho.ws>
Fri, 19 Jan 2018 16:43:38 +0000 (16:43 +0000)
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 78811de4b560425b37fafee796401b669f22ddeb..29394c80d0788c9ef0da3988ae31b28bdd1df42f 100644 (file)
@@ -195,6 +195,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;
@@ -296,6 +320,8 @@ int main(int argc, char *argv[])
 
        lxc_setup_fs();
 
+       remove_self();
+
        pid = fork();
        if (pid < 0)
                exit(EXIT_FAILURE);