Commit 3ae36e70 authored by Pavel Emelyanov's avatar Pavel Emelyanov

restore: Don't mess with last_pid when restoring pidns init

When we fork a pidns init there's no need in specifying its pid,
as it will be autogenerated to 1. Clean the code not to mess with
the last_pid sysctl at all in that case, rather than just omitting
the write into it.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 6aaf6564
......@@ -496,7 +496,6 @@ struct cr_clone_arg {
static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone_flags)
{
int ret = -1;
char buf[32];
struct cr_clone_arg ca;
void *stack;
pid_t pid = item->pid.virt;
......@@ -510,9 +509,12 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone
goto err;
}
snprintf(buf, sizeof(buf), "%d", pid - 1);
ca.item = item;
ca.clone_flags = ns_clone_flags;
if (!(ca.clone_flags & CLONE_NEWPID)) {
char buf[32];
ca.fd = open(LAST_PID_PATH, O_RDWR);
if (ca.fd < 0) {
pr_perror("%d: Can't open %s", pid, LAST_PID_PATH);
......@@ -520,15 +522,18 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone
}
if (flock(ca.fd, LOCK_EX)) {
close(ca.fd);
pr_perror("%d: Can't lock %s", pid, LAST_PID_PATH);
goto err_close;
goto err;
}
if (!(ca.clone_flags & CLONE_NEWPID)) {
snprintf(buf, sizeof(buf), "%d", pid - 1);
if (write_img_buf(ca.fd, buf, strlen(buf)))
goto err_unlock;
} else
} else {
ca.fd = -1;
BUG_ON(pid != 1);
}
if (ca.clone_flags & CLONE_NEWNET)
/*
......@@ -562,11 +567,12 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone
}
err_unlock:
if (ca.fd >= 0) {
if (flock(ca.fd, LOCK_UN))
pr_perror("%d: Can't unlock %s", pid, LAST_PID_PATH);
err_close:
close_safe(&ca.fd);
close(ca.fd);
}
err:
if (stack != MAP_FAILED)
munmap(stack, STACK_SIZE);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment