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

Andrew Vagin avagin at virtuozzo.com
Tue Dec 8 04:22:49 PST 2015


On Mon, Dec 07, 2015 at 05:17:09PM +0300, Dmitry Safonov wrote:
> https://jira.sw.ru/browse/PSBM-41993
> 
> Signed-off-by: Dmitry Safonov <dsafonov at odin.com>
> ---
>  cr-restore.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/cr-restore.c b/cr-restore.c
> index 1c0c641..11e86cd 100644
> --- a/cr-restore.c
> +++ b/cr-restore.c
> @@ -840,6 +840,49 @@ err:
>  	return -1;
>  }
>  
> +static void prepare_pid_oom_score_adj(pid_t pid, int value)
> +{
> +	int fd;
> +	char buf[11];
> +
> +	fd = open_proc_rw(pid, "oom_score_adj");
> +	if (fd < 0) {
> +		pr_err("Can't open /proc/%d/oom_score_adj to restore\n", pid);

open_proc_rw() prints a similar error

> +		return;
> +	}
> +	snprintf(buf, 11, "%d", value);
> +	if (write(fd, buf, 11) < 0) {
> +		pr_perror("Write %s to /proc/%d/oom_score_adj failed", buf, pid);
		return -1;

and the caller has to handle errors

> +	}
> +	close(fd);
> +}
> +
> +static void prepare_pid_loginuid(pid_t pid, unsigned int value)
> +{
> +	int fd;
> +	char buf[11]; /* 4294967295 is maximum for u32 */
> +
> +	fd = open_proc_rw(pid, "loginuid");
> +	if (fd < 0) {
> +		pr_err("Can't open /proc/%d/loginuid to restore\n", pid);
> +		return;
> +	}
> +	snprintf(buf, 11, "%u", value);
> +	if (write(fd, buf, 11) < 0) {
> +		pr_perror("Write %s to /proc/%d/loginuid failed", buf, pid);
> +	}
> +	close(fd);
> +}
> +
> +static int prepare_proc_misc(pid_t pid, TaskCoreEntry *tc)
> +{
> +	if (tc->has_loginuid)
> +		prepare_pid_loginuid(pid, tc->loginuid);
> +	if (tc->has_oom_score_adj)
> +		prepare_pid_oom_score_adj(pid, tc->oom_score_adj);
> +	return 0;
> +}
> +
>  static int restore_one_alive_task(int pid, CoreEntry *core)
>  {
>  	pr_info("Restoring resources\n");
> @@ -876,6 +919,9 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
>  	if (inherit_fd_fini() < 0)
>  		return -1;
>  
> +	if (prepare_proc_misc(pid, core->tc))
> +		return -1;
> +
>  	return sigreturn_restore(pid, core);
>  }
>  
> -- 
> 2.6.3
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list