[CRIU] [PATCH] log: write pidfile at logdir

Ruslan Kuprieiev kupruser at gmail.com
Fri Nov 1 08:08:24 PDT 2013


Hi!

Now we're unable to use relative pidfile path with -d option, because
criu chdir to /, before writing pidfile. So lets open pidfile at log dir.

Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 log.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/log.c b/log.c
index 1e5fcad..5426297 100644
--- a/log.c
+++ b/log.c
@@ -194,11 +194,17 @@ void print_on_level(unsigned int loglevel, const char *format, ...)
 
 int write_pidfile(char *pfname, int pid)
 {
-	int fd;
+	int dfd, fd;
 
-	fd = open(pfname, O_WRONLY | O_TRUNC | O_CREAT, 0600);
+	dfd = get_service_fd(LOG_DIR_FD_OFF);
+	if (dfd < 0) {
+		pr_perror("Can't get log directory fd");
+		return -1;
+	}
+
+	fd = openat(dfd, pfname, O_CREAT | O_TRUNC | O_WRONLY, 0600);
 	if (fd == -1) {
-		pr_perror("Can't open %s", pfname);
+		pr_perror("Can't open pidfile %s", pfname);
 		kill(pid, SIGKILL);
 		return -1;
 	}
-- 
1.8.1.2



More information about the CRIU mailing list