[CRIU] [PATCH 4/5] add init_work_dir

Pavel Emelyanov xemul at parallels.com
Tue Nov 12 11:21:19 PST 2013


On 11/13/2013 01:43 AM, Ruslan Kuprieiev wrote:
> 
> Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
> ---
>  cr-service.c   |  5 +++++
>  crtools.c      | 10 ++++++++++
>  include/util.h |  2 ++
>  util.c         | 25 +++++++++++++++++++++++++
>  4 files changed, 42 insertions(+)
> 
> diff --git a/cr-service.c b/cr-service.c
> index 92ccd66..58f765a 100644
> --- a/cr-service.c
> +++ b/cr-service.c
> @@ -127,6 +127,11 @@ static int setup_opts_from_req(int sk, CriuOpts *req)
>  	log_closedir();
>  
>  	/* initiate log file in imgs dir */
> +	if (init_work_dir(NULL) < 0) {
> +		pr_perror("Can't set work directory");
> +		return -1;
> +	}
> +
>  	if (req->log_file)
>  		opts.output = req->log_file;
>  	else
> diff --git a/crtools.c b/crtools.c
> index b9313b1..136d3fc 100644
> --- a/crtools.c
> +++ b/crtools.c
> @@ -79,6 +79,7 @@ int main(int argc, char *argv[])
>  	int opt, idx;
>  	int log_level = 0;
>  	char *imgs_dir = ".";
> +	char *work_dir = NULL;
>  
>  	BUILD_BUG_ON(PAGE_SIZE != PAGE_IMAGE_SIZE);
>  
> @@ -167,6 +168,7 @@ int main(int argc, char *argv[])
>  			imgs_dir = optarg;
>  			break;
>  		case 'W':
> +			work_dir = optarg;
>  			break;
>  		case 'o':
>  			opts.output = optarg;
> @@ -280,6 +282,14 @@ int main(int argc, char *argv[])
>  		}
>  	}
>  
> +	if (!work_dir)
> +		work_dir = imgs_dir;
> +
> +	if (init_work_dir(work_dir) < 0) {
> +		pr_perror("Can't initiate work directory");
> +		return -1;
> +	}
> +
>  	if (chdir(imgs_dir)) {
>  		pr_perror("Can't change directory to %s", optarg);
>  		return -1;
> diff --git a/include/util.h b/include/util.h
> index 72a79e9..5bc9557 100644
> --- a/include/util.h
> +++ b/include/util.h
> @@ -289,4 +289,6 @@ extern int read_fd_link(int lfd, char *buf, size_t size);
>  #define USEC_PER_SEC	1000000L
>  #define NSEC_PER_SEC    1000000000L
>  
> +extern int init_work_dir(char *work_dir);
> +
>  #endif /* __CR_UTIL_H__ */
> diff --git a/util.c b/util.c
> index 0b10f0d..23a3148 100644
> --- a/util.c
> +++ b/util.c
> @@ -571,3 +571,28 @@ out:
>  
>  	return ret;
>  }
> +
> +int init_work_dir(char *work_dir)
> +{
> +	int dfd, ret;
> +
> +	if (work_dir) {
> +		dfd = open(work_dir, O_RDONLY);
> +		if (dfd < 0) {
> +			pr_perror("Can't open work directory %s", work_dir);
> +			return -1;
> +		}
> +	} else {
> +		dfd = open(".", O_RDONLY);
> +		if (dfd < 0) {
> +			pr_perror("Can't open current directory %s", work_dir);
> +			return -1;
> +		}

Merge these two if () branched.

> +	}
> +
> +	ret = install_service_fd(WORK_DIR_FD_OFF, dfd);
> +
> +	close(dfd);
> +
> +	return ret;
> +}
> 




More information about the CRIU mailing list