Commit b478b2fb authored by Cyrill Gorcunov's avatar Cyrill Gorcunov Committed by Pavel Emelyanov

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: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent fd823848
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment