[CRIU] [PATCH v3 2/3] criu: restore loginuid & oom_score_adj values

Pavel Emelyanov xemul at parallels.com
Thu Dec 17 05:07:48 PST 2015


One more thing that I've just noticed:

>  cr-restore.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 61 insertions(+)
> 
> diff --git a/cr-restore.c b/cr-restore.c
> index 1c0c641..b3d7019 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -840,6 +840,64 @@ err:
>  	return -1;
>  }
>  
> +static int prepare_pid_oom_score_adj(pid_t pid, int value)
> +{
> +	int fd, ret = 0;
> +	char buf[11];
> +
> +	fd = open_proc_rw(pid, "oom_score_adj");
> +	if (fd < 0)
> +		return -1;
> +
> +	snprintf(buf, 11, "%d", value);
> +
> +	if (write(fd, buf, 11) < 0) {
> +		pr_perror("Write %s to /proc/%d/oom_score_adj failed",
> +			buf, pid);
> +		ret = -1;
> +	}
> +
> +	close(fd);
> +	return ret;
> +}
> +
> +static int prepare_pid_loginuid(pid_t pid, unsigned int value)
> +{
> +	int fd, ret = 0;
> +	char buf[11]; /* 4294967295 is maximum for u32 */
> +
> +	fd = open_proc_rw(pid, "loginuid");
> +	if (fd < 0)
> +		return -1;
> +
> +	snprintf(buf, 11, "%u", value);
> +
> +	if (write(fd, buf, 11) < 0) {
> +		pr_perror("Write %s to /proc/%d/loginuid failed", buf, pid);
> +		ret = -1;
> +	}
> +	close(fd);
> +	return ret;
> +}
> +
> +static int prepare_proc_misc(pid_t pid, TaskCoreEntry *tc)

The pid here is the pid of current task, so everything that happens
afterwards works effectively on /proc/self/ files. For such cases we
have PROC_SELF that can be passed to open_proc_foo helpers and make 
it work with (surprise, surprise) /proc/slef/ files ;)

Plz, fix.

-- Pavel


More information about the CRIU mailing list