Commit aabb56bd authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

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: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent a5ac06f5
...@@ -547,6 +547,20 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone ...@@ -547,6 +547,20 @@ static inline int fork_with_pid(struct pstree_item *item, unsigned long ns_clone
if (ca.clone_flags & CLONE_NEWPID) if (ca.clone_flags & CLONE_NEWPID)
item->pid.real = ret; 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: err_unlock:
if (flock(ca.fd, LOCK_UN)) if (flock(ca.fd, LOCK_UN))
pr_perror("%d: Can't unlock %s", pid, LAST_PID_PATH); pr_perror("%d: Can't unlock %s", pid, LAST_PID_PATH);
......
...@@ -89,6 +89,7 @@ int main(int argc, char *argv[]) ...@@ -89,6 +89,7 @@ int main(int argc, char *argv[])
{ "log-pid", no_argument, 0, 44}, { "log-pid", no_argument, 0, 44},
{ "version", no_argument, 0, 'V'}, { "version", no_argument, 0, 'V'},
{ "evasive-devices", no_argument, 0, 45}, { "evasive-devices", no_argument, 0, 45},
{ "pidfile", required_argument, 0, 46},
{ }, { },
}; };
...@@ -169,6 +170,9 @@ int main(int argc, char *argv[]) ...@@ -169,6 +170,9 @@ int main(int argc, char *argv[])
case 45: case 45:
opts.evasive_devices = true; opts.evasive_devices = true;
break; break;
case 46:
opts.pidfile = optarg;
break;
case 'V': case 'V':
pr_msg("Version: %d.%d\n", CRIU_VERSION_MAJOR, CRIU_VERSION_MINOR); pr_msg("Version: %d.%d\n", CRIU_VERSION_MAJOR, CRIU_VERSION_MINOR);
return 0; return 0;
...@@ -249,6 +253,7 @@ usage: ...@@ -249,6 +253,7 @@ usage:
pr_msg(" -d|--restore-detached detach after restore\n"); 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(" -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(" -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* Special resources support:\n");
pr_msg(" -n|--namespaces checkpoint/restore namespaces - values must be separated by comma\n"); pr_msg(" -n|--namespaces checkpoint/restore namespaces - values must be separated by comma\n");
......
...@@ -92,6 +92,7 @@ struct cr_options { ...@@ -92,6 +92,7 @@ struct cr_options {
bool log_file_per_pid; bool log_file_per_pid;
char *output; char *output;
char *root; char *root;
char *pidfile;
}; };
extern struct cr_options opts; extern struct cr_options opts;
......
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