[CRIU] [PATCH 4/8] page-server: Start using new cr_daemon routine
Pavel Emelyanov
xemul at parallels.com
Tue Jan 28 10:36:16 PST 2014
After this the called of cr_page_server gets controll
back with the server's pid.
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
crtools.c | 2 +-
page-xfer.c | 35 +++++++++++++++++++++++------------
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/crtools.c b/crtools.c
index 3b881e6..2e60873 100644
--- a/crtools.c
+++ b/crtools.c
@@ -363,7 +363,7 @@ int main(int argc, char *argv[])
}
if (!strcmp(argv[optind], "page-server"))
- return cr_page_server(opts.restore_detach) != 0;
+ return cr_page_server(opts.restore_detach) > 0 ? 0 : 1;
if (!strcmp(argv[optind], "service"))
return cr_service(opts.restore_detach);
diff --git a/page-xfer.c b/page-xfer.c
index 976ed15..e56acfc 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -246,7 +246,7 @@ static int get_sockaddr_in(struct sockaddr_in *addr)
int cr_page_server(bool daemon_mode)
{
- int sk, ask = -1;
+ int sk, ask = -1, ret;
struct sockaddr_in saddr, caddr;
socklen_t clen = sizeof(caddr);
@@ -273,11 +273,15 @@ int cr_page_server(bool daemon_mode)
goto out;
}
- if (daemon_mode)
- if (daemon(1, 0) == -1) {
+ if (daemon_mode) {
+ ret = cr_daemon(1, 0);
+ if (ret == -1) {
pr_perror("Can't run in the background");
- return -errno;
+ goto out;
}
+ if (ret > 0) /* parent task, daemon started */
+ return ret;
+ }
if (opts.pidfile) {
if (write_pidfile(getpid()) == -1) {
@@ -286,21 +290,28 @@ int cr_page_server(bool daemon_mode)
}
}
- ask = accept(sk, (struct sockaddr *)&caddr, &clen);
+ ret = ask = accept(sk, (struct sockaddr *)&caddr, &clen);
if (ask < 0)
pr_perror("Can't accept connection to server");
-out:
close(sk);
- if (ask < 0)
- return -1;
+ if (ask >= 0) {
+ pr_info("Accepted connection from %s:%u\n",
+ inet_ntoa(caddr.sin_addr),
+ (int)ntohs(caddr.sin_port));
- pr_info("Accepted connection from %s:%u\n",
- inet_ntoa(caddr.sin_addr),
- (int)ntohs(caddr.sin_port));
+ ret = page_server_serve(ask);
+ }
+
+ if (daemon_mode)
+ exit(ret);
- return page_server_serve(ask);
+ return ret;
+
+out:
+ close(sk);
+ return -1;
}
static int page_server_sk = -1;
--
1.8.4.2
More information about the CRIU
mailing list