[CRIU] [PATCH 2/2]v2 service: add work_dir support

Ruslan Kuprieiev kupruser at gmail.com
Tue Feb 4 00:31:26 PST 2014


Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
 cr-service.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/cr-service.c b/cr-service.c
index 74ea3c3..ff2fb0d 100644
--- a/cr-service.c
+++ b/cr-service.c
@@ -148,6 +148,7 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 	struct stat st;
 	socklen_t ids_len = sizeof(struct ucred);
 	char images_dir_path[PATH_MAX];
+	char work_dir_path[PATH_MAX];
 
 	if (getsockopt(sk, SOL_SOCKET, SO_PEERCRED, &ids, &ids_len)) {
 		pr_perror("Can't get socket options");
@@ -164,21 +165,30 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
 	BUG_ON(st.st_ino == -1);
 	service_sk_ino = st.st_ino;
 
-	/* going to dir, where to place/get images*/
+	/* open images_dir */
 	sprintf(images_dir_path, "/proc/%d/fd/%d", ids.pid, req->images_dir_fd);
 
 	if (req->parent_img)
 		opts.img_parent = req->parent_img;
 
-	if (chdir(images_dir_path)) {
-		pr_perror("Can't chdir to images directory");
+	if (open_image_dir(images_dir_path) < 0) {
+		pr_perror("Can't open images directory");
 		return -1;
 	}
 
-	if (open_image_dir(".") < 0)
+	/* chdir to work dir */
+	if (req->has_work_dir_fd)
+		sprintf(work_dir_path, "/proc/%d/fd/%d", ids.pid,
+							req->work_dir_fd);
+	else
+		strcpy(work_dir_path, images_dir_path);
+
+	if (chdir(work_dir_path)) {
+		pr_perror("Can't chdir to work_dir");
 		return -1;
+	}
 
-	/* initiate log file in imgs dir */
+	/* initiate log file in work dir */
 	if (req->log_file)
 		opts.output = req->log_file;
 	else
-- 
1.8.3.2



More information about the CRIU mailing list