Skip to content

Commit cf1f63d

Browse files
codypssofar
authored andcommitted
Avoid loosing track of processes
Due to the changes in ps_struct list tracking, we were inserting new items in the middle of the list and leaving orphaned segments hanging around. Avoid this by seeking to the end for inserting new ps_structs.
1 parent 09afbcf commit cf1f63d

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

src/store.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,19 @@ int log_sample(DIR *proc,
258258
char t[32];
259259
struct ps_struct *parent;
260260

261-
ps->next_ps = ps->next_running = new0(struct ps_struct, 1);
262-
if (!ps->next_ps)
261+
/* find the insertion point for the last item */
262+
struct ps_struct **ps_next = &ps->next_ps;
263+
while (*ps_next) {
264+
ps_next = &(*ps_next)->next_ps;
265+
}
266+
267+
assert(!*ps_next);
268+
assert(!ps->next_running);
269+
*ps_next = ps->next_running = new0(struct ps_struct, 1);
270+
if (!*ps_next)
263271
return log_oom();
264272

265-
ps = ps->next_ps;
273+
ps = *ps_next;
266274
ps->pid = pid;
267275
ps->sched = -1;
268276
ps->schedstat = -1;

0 commit comments

Comments
 (0)