Merge pull request #2095 from tych0/remove-lxc-init

unlink lxc-init
This commit is contained in:
Christian Brauner 2018-01-19 18:49:21 +01:00 committed by GitHub
commit 7c76f49546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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);