[CRIU] [PATCH 2/2] page-server: write pidfile before chdir to /, if going daemon
Ruslan Kuprieiev
kupruser at gmail.com
Tue Oct 29 16:27:34 PDT 2013
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
page-xfer.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/page-xfer.c b/page-xfer.c
index 087595f..f07244a 100644
--- a/page-xfer.c
+++ b/page-xfer.c
@@ -267,11 +267,16 @@ int cr_page_server(bool daemon_mode)
goto out;
}
- if (daemon_mode)
- if(daemon(0, 0) == -1){
- pr_perror("Can't run in the background");
+ if (daemon_mode) {
+ /*
+ * Will chdir to /, after writing pidfile,
+ * so pidfile path will be resolved properly.
+ */
+ if (daemon(1, 0) == -1) {
+ pr_perror("Can't run page-server in the background");
return -errno;
}
+ }
if (opts.pidfile) {
if (write_pidfile(opts.pidfile, getpid()) == -1) {
@@ -280,6 +285,14 @@ int cr_page_server(bool daemon_mode)
}
}
+ if (daemon_mode) {
+ /* And now we can chdir to /. */
+ if (chdir("/")) {
+ pr_perror("Can't chdir to /");
+ return -1;
+ }
+ }
+
ask = accept(sk, (struct sockaddr *)&caddr, &clen);
if (ask < 0)
pr_perror("Can't accept connection to server");
--
1.8.1.2
More information about the CRIU
mailing list