Commit 2491da92 authored by Andrey Vagin's avatar Andrey Vagin Committed by Pavel Emelyanov

page-xfer: write pidfile from a process which starts a service

When a process, which starts a service, exits, we know that we can
connect to the page server and we expect to find pidfile.

If we create pidfile from a page server process, we have a race window.
Signed-off-by: 's avatarAndrey Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent c80048d2
......@@ -4,6 +4,8 @@
#include <linux/falloc.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "cr_options.h"
#include "servicefd.h"
......@@ -309,14 +311,17 @@ no_server:
pr_perror("Can't run in the background");
goto out;
}
if (ret > 0) /* parent task, daemon started */
return ret;
}
if (ret > 0) { /* parent task, daemon started */
if (opts.pidfile) {
if (write_pidfile(ret) == -1) {
pr_perror("Can't write pidfile");
kill(ret, SIGKILL);
waitpid(ret, NULL, 0);
return -1;
}
}
if (opts.pidfile) {
if (write_pidfile(getpid()) == -1) {
pr_perror("Can't write pidfile");
return -1;
return ret;
}
}
......
......@@ -573,8 +573,8 @@ EOF
[ -n "$DUMP_ONLY" ] && dump_only=1
if [ $PAGE_SERVER -eq 1 ]; then
$CRIU page-server -D $ddump -o page_server.log -v4 --port $PS_PORT $ps_args --daemon || return 1
ps_pid=`lsof -s TCP:LISTEN -i :$PS_PORT -t`
$CRIU page-server -D $ddump -o page_server.log -v4 --port $PS_PORT $ps_args --daemon --pidfile $ddump/page-server.pid || return 1
ps_pid=`cat $ddump/page-server.pid`
ps -p "$ps_pid" -o cmd h | grep -q page-server || {
echo "Unable to determing PID of page-server"
return 1
......
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