2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-29 13:28:27 +00:00

crtools: write a pid of a root task in a specified file

When we restore a pid namespace the root task will get some unknown pid
in the original (i.e. -- the ns crtools a launched from) one. To find
this pid out one can use this option -- it will make the pid obtained by
the new init to be written into a pid file.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Andrey Vagin 2012-08-14 12:54:00 +04:00 committed by Pavel Emelyanov
parent a5ac06f503
commit aabb56bd66
3 changed files with 20 additions and 0 deletions

View File

@ -547,6 +547,20 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone
if (ca.clone_flags & CLONE_NEWPID)
item->pid.real = ret;
if (opts.pidfile && root_item == item) {
int fd;
fd = open(opts.pidfile, O_WRONLY | O_TRUNC | O_CREAT, 0600);
if (fd == -1) {
pr_perror("Can't open %s", opts.pidfile);
kill(ret, SIGKILL);
} else {
dprintf(fd, "%d", ret);
close(fd);
}
}
err_unlock:
if (flock(ca.fd, LOCK_UN))
pr_perror("%d: Can't unlock %s", pid, LAST_PID_PATH);

View File

@ -89,6 +89,7 @@ int main(int argc, char *argv[])
{ "log-pid", no_argument, 0, 44},
{ "version", no_argument, 0, 'V'},
{ "evasive-devices", no_argument, 0, 45},
{ "pidfile", required_argument, 0, 46},
{ },
};
@ -169,6 +170,9 @@ int main(int argc, char *argv[])
case 45:
opts.evasive_devices = true;
break;
case 46:
opts.pidfile = optarg;
break;
case 'V':
pr_msg("Version: %d.%d\n", CRIU_VERSION_MAJOR, CRIU_VERSION_MINOR);
return 0;
@ -249,6 +253,7 @@ usage:
pr_msg(" -d|--restore-detached detach after restore\n");
pr_msg(" -s|--leave-stopped leave tasks in stopped state after checkpoint instead of killing them\n");
pr_msg(" -D|--images-dir directory where to put images to\n");
pr_msg(" --pidfile [FILE] write a pid of a root task in this file\n");
pr_msg("\n* Special resources support:\n");
pr_msg(" -n|--namespaces checkpoint/restore namespaces - values must be separated by comma\n");

View File

@ -92,6 +92,7 @@ struct cr_options {
bool log_file_per_pid;
char *output;
char *root;
char *pidfile;
};
extern struct cr_options opts;