From d2e30bcce830ed48980fdf4af75bc99b8fedbd91 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Thu, 13 Mar 2014 17:17:26 +0400 Subject: [PATCH] rlimit: Allocate and free appropriate Core entry, v2 On Thu, Mar 13, 2014 at 04:20:37PM +0400, Pavel Emelyanov wrote: > > Would you rework this patch on top of my recent > "allocate Core in on xmalloc call" one? Attached. >From c2233d4fafce30c4e7214a1a7ab3677824a30d75 Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Thu, 13 Mar 2014 16:57:14 +0400 Subject: [PATCH] rlimit: Allocate and free appropriate Core entry Signed-off-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- pstree.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pstree.c b/pstree.c index eba0c30c8..85b82f2ef 100644 --- a/pstree.c +++ b/pstree.c @@ -29,8 +29,14 @@ CoreEntry *core_entry_alloc(int th, int tsk) void *m; sz = sizeof(CoreEntry); - if (tsk) + if (tsk) { sz += sizeof(TaskCoreEntry) + TASK_COMM_LEN; + if (th) { + sz += sizeof(TaskRlimitsEntry); + sz += RLIM_NLIMITS * sizeof(RlimitEntry *); + sz += RLIM_NLIMITS * sizeof(RlimitEntry); + } + } if (th) sz += sizeof(ThreadCoreEntry) + sizeof(ThreadSasEntry); @@ -45,6 +51,23 @@ CoreEntry *core_entry_alloc(int th, int tsk) task_core_entry__init(core->tc); core->tc->comm = xptr_pull_s(&m, TASK_COMM_LEN); memzero(core->tc->comm, TASK_COMM_LEN); + + if (th) { + TaskRlimitsEntry *rls; + int i; + + rls = xptr_pull(&m, TaskRlimitsEntry); + task_rlimits_entry__init(rls); + core->rlimits = rls; + + rls->n_rlimits = RLIM_NLIMITS; + rls->rlimits = xptr_pull_s(&m, sizeof(RlimitEntry *) * RLIM_NLIMITS); + + for (i = 0; i < RLIM_NLIMITS; i++) { + rls->rlimits[i] = xptr_pull(&m, RlimitEntry); + rlimit_entry__init(rls->rlimits[i]); + } + } } if (th) {