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

Dmitry Safonov dsafonov at odin.com
Tue Dec 8 04:39:52 PST 2015


On 12/08/2015 03:22 PM, Andrew Vagin wrote:
> 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
Yeah, you right, will remove this

>
>> +		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
and make errors critical for restoring, but only loginuid errors,
not the oom_score_adj (for that will add comment that it's not
that critical).

>
>> +	}
>> +	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


-- 
Regards,
Dmitry Safonov



More information about the CRIU mailing list