mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-29 13:28:27 +00:00
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: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
6aaf65642b
commit
3ae36e700f
40
cr-restore.c
40
cr-restore.c
@ -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,25 +509,31 @@ 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;
|
||||
ca.fd = open(LAST_PID_PATH, O_RDWR);
|
||||
if (ca.fd < 0) {
|
||||
pr_perror("%d: Can't open %s", pid, LAST_PID_PATH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (flock(ca.fd, LOCK_EX)) {
|
||||
pr_perror("%d: Can't lock %s", pid, LAST_PID_PATH);
|
||||
goto err_close;
|
||||
}
|
||||
|
||||
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);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (flock(ca.fd, LOCK_EX)) {
|
||||
close(ca.fd);
|
||||
pr_perror("%d: Can't lock %s", pid, LAST_PID_PATH);
|
||||
goto err;
|
||||
}
|
||||
|
||||
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 (flock(ca.fd, LOCK_UN))
|
||||
pr_perror("%d: Can't unlock %s", pid, LAST_PID_PATH);
|
||||
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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user