Commit 302591aa authored by Pavel Emelyanov's avatar Pavel Emelyanov

rlimits: Reshuffle new and legacy restoration code

Do the same as was done with timers.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1d438db6
...@@ -2100,39 +2100,15 @@ static unsigned long decode_rlim(u_int64_t ival) ...@@ -2100,39 +2100,15 @@ static unsigned long decode_rlim(u_int64_t ival)
static unsigned long rlims_cpos; static unsigned long rlims_cpos;
static unsigned int rlims_nr; static unsigned int rlims_nr;
static int prepare_rlimits(int pid, CoreEntry *core) /*
* Legacy rlimits restore from CR_FD_RLIMIT
*/
static int prepare_rlimits_from_fd(int pid)
{ {
struct rlimit *r; struct rlimit *r;
int fd, ret; int fd, ret;
rlims_cpos = rst_mem_cpos(RM_PRIVATE);
/*
* New image format: rlimits are bound to the core entry.
*/
if (core->tc->rlimits) {
TaskRlimitsEntry *rls = core->tc->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. * Old image -- read from the file.
*/ */
...@@ -2178,6 +2154,37 @@ static int prepare_rlimits(int pid, CoreEntry *core) ...@@ -2178,6 +2154,37 @@ static int prepare_rlimits(int pid, CoreEntry *core)
return 0; return 0;
} }
static int prepare_rlimits(int pid, CoreEntry *core)
{
int i;
TaskRlimitsEntry *rls = core->tc->rlimits;
struct rlimit *r;
rlims_cpos = rst_mem_cpos(RM_PRIVATE);
if (!rls)
return prepare_rlimits_from_fd(pid);
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;
}
static int open_signal_image(int type, pid_t pid, unsigned int *nr) static int open_signal_image(int type, pid_t pid, unsigned int *nr)
{ {
int fd, ret; int fd, ret;
......
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