mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 13:58:34 +00:00
rlimit: Restore rlimist from Core data
To save backward compatibility try to read data from old image if Core entry doesn't has rlimits bound. Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
fd82384866
commit
b478b2fb2f
35
cr-restore.c
35
cr-restore.c
@@ -86,7 +86,7 @@ static struct pstree_item *current;
|
||||
static int restore_task_with_children(void *);
|
||||
static int sigreturn_restore(pid_t pid, CoreEntry *core);
|
||||
static int prepare_restorer_blob(void);
|
||||
static int prepare_rlimits(int pid);
|
||||
static int prepare_rlimits(int pid, CoreEntry *core);
|
||||
static int prepare_posix_timers(int pid);
|
||||
static int prepare_signals(int pid);
|
||||
|
||||
@@ -717,7 +717,7 @@ static int restore_one_alive_task(int pid, CoreEntry *core)
|
||||
if (prepare_posix_timers(pid))
|
||||
return -1;
|
||||
|
||||
if (prepare_rlimits(pid) < 0)
|
||||
if (prepare_rlimits(pid, core) < 0)
|
||||
return -1;
|
||||
|
||||
return sigreturn_restore(pid, core);
|
||||
@@ -2034,13 +2034,42 @@ static unsigned long decode_rlim(u_int64_t ival)
|
||||
static unsigned long rlims_cpos;
|
||||
static unsigned int rlims_nr;
|
||||
|
||||
static int prepare_rlimits(int pid)
|
||||
static int prepare_rlimits(int pid, CoreEntry *core)
|
||||
{
|
||||
struct rlimit *r;
|
||||
int fd, ret;
|
||||
|
||||
rlims_cpos = rst_mem_cpos(RM_PRIVATE);
|
||||
|
||||
/*
|
||||
* New image format: rlimits are bound to the core entry.
|
||||
*/
|
||||
if (core->rlimits) {
|
||||
TaskRlimitsEntry *rls = core->rlimits;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rls->n_rlimits; i++) {
|
||||
r = rst_mem_alloc(sizeof(*r), RM_PRIVATE);
|
||||
if (!r) {
|
||||
pr_err("Can't allocate memory for resource %d\n", i);
|
||||
return -1;
|
||||
}
|
||||
|
||||
r->rlim_cur = decode_rlim(rls->rlimits[i]->cur);
|
||||
r->rlim_max = decode_rlim(rls->rlimits[i]->max);
|
||||
|
||||
if (r->rlim_cur > r->rlim_max) {
|
||||
pr_warn("Can't restore cur > max for %d.%d\n", pid, i);
|
||||
r->rlim_cur = r->rlim_max;
|
||||
}
|
||||
}
|
||||
rlims_nr = rls->n_rlimits;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Old image -- read from the file.
|
||||
*/
|
||||
fd = open_image(CR_FD_RLIMIT, O_RSTR, pid);
|
||||
if (fd < 0) {
|
||||
if (errno == ENOENT) {
|
||||
|
Reference in New Issue
Block a user