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 @@ ...@@ -4,6 +4,8 @@
#include <linux/falloc.h> #include <linux/falloc.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "cr_options.h" #include "cr_options.h"
#include "servicefd.h" #include "servicefd.h"
...@@ -309,17 +311,20 @@ no_server: ...@@ -309,17 +311,20 @@ no_server:
pr_perror("Can't run in the background"); pr_perror("Can't run in the background");
goto out; goto out;
} }
if (ret > 0) /* parent task, daemon started */ if (ret > 0) { /* parent task, daemon started */
return ret;
}
if (opts.pidfile) { if (opts.pidfile) {
if (write_pidfile(getpid()) == -1) { if (write_pidfile(ret) == -1) {
pr_perror("Can't write pidfile"); pr_perror("Can't write pidfile");
kill(ret, SIGKILL);
waitpid(ret, NULL, 0);
return -1; return -1;
} }
} }
return ret;
}
}
if (sk >= 0) { if (sk >= 0) {
ret = ask = accept(sk, (struct sockaddr *)&caddr, &clen); ret = ask = accept(sk, (struct sockaddr *)&caddr, &clen);
if (ask < 0) if (ask < 0)
......
...@@ -573,8 +573,8 @@ EOF ...@@ -573,8 +573,8 @@ EOF
[ -n "$DUMP_ONLY" ] && dump_only=1 [ -n "$DUMP_ONLY" ] && dump_only=1
if [ $PAGE_SERVER -eq 1 ]; then if [ $PAGE_SERVER -eq 1 ]; then
$CRIU page-server -D $ddump -o page_server.log -v4 --port $PS_PORT $ps_args --daemon || return 1 $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=`lsof -s TCP:LISTEN -i :$PS_PORT -t` ps_pid=`cat $ddump/page-server.pid`
ps -p "$ps_pid" -o cmd h | grep -q page-server || { ps -p "$ps_pid" -o cmd h | grep -q page-server || {
echo "Unable to determing PID of page-server" echo "Unable to determing PID of page-server"
return 1 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