From b478b2fb2f6fa2212ce552d7c2022839634082b1 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Thu, 13 Mar 2014 14:30:48 +0400 Subject: [PATCH] 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 Signed-off-by: Pavel Emelyanov --- cr-restore.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/cr-restore.c b/cr-restore.c index ab8fa770d..f7fea99b8 100644 --- a/cr-restore.c +++ b/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) {