From: Jim Warner Date: Fri, 11 Sep 2015 05:00:00 +0000 (-0500) Subject: library: introduce a fatal 'proc not mounted' function X-Git-Tag: v4.0.0~1029 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=007e03280531f5808e8bbb01a2b15354db97aa9d;p=procps-ng library: introduce a fatal 'proc not mounted' function Signed-off-by: Jim Warner --- diff --git a/proc/libprocps.sym b/proc/libprocps.sym index c32258dd..9236454d 100644 --- a/proc/libprocps.sym +++ b/proc/libprocps.sym @@ -6,6 +6,7 @@ global: escape_str; escape_strlist; escaped_copy; + fatal_proc_unmounted; freeproc; get_pid_digits; look_up_our_self; diff --git a/proc/pids.c b/proc/pids.c index 25ae3e3a..d35fca2b 100644 --- a/proc/pids.c +++ b/proc/pids.c @@ -70,6 +70,7 @@ struct procps_pidsinfo { int alloc_total; // number of above pointers allocated int inuse_total; // number of above pointers occupied struct stacks_extent *extents; // anchor for all resettable extents + struct stacks_extent *otherexts; // anchor for single stack invariant extents int history_yes; // need historical data struct history_info *hist; // pointer to historical support data int dirty_stacks; // extents need dynamic storage clean @@ -969,6 +970,32 @@ static void validate_stacks ( // ___ Public Functions ||||||||||||||||||||||||||||||||||||||||||||||||||||||| +PROCPS_EXPORT struct pids_stack *fatal_proc_unmounted ( + struct procps_pidsinfo *info, + int return_self) +{ + static proc_t self; + struct stacks_extent *ext; + + // this is very likely the *only* newlib function where the + // context (procps_pidsinfo) of NULL will ever be permitted + look_up_our_self(&self); + if (!return_self) + return NULL; + + if (info == NULL + || !(ext = (struct stacks_extent *)procps_pids_stacks_alloc(info, 1)) + || !extent_cut(info, ext)) + return NULL; + + ext->next = info->otherexts; + info->otherexts = ext; + assign_results(info, ext->stacks[0], &self); + + return ext->stacks[0]; +} // end: fatal_proc_unmounted + + /* * procps_pids_new(): * @@ -1406,6 +1433,15 @@ PROCPS_EXPORT int procps_pids_unref ( free(p); } while ((*info)->extents); } + if ((*info)->otherexts) { + struct stacks_extent *nextext, *ext = (*info)->otherexts; + while (ext) { + nextext = ext->next; + cleanup_stack(ext->stacks[0]->head, ext->ext_numitems); + free(ext); + ext = nextext; + }; + } if ((*info)->reaped.stacks) free((*info)->reaped.stacks); if ((*info)->anchor) diff --git a/proc/pids.h b/proc/pids.h index 60f8a46a..ca43dfa7 100644 --- a/proc/pids.h +++ b/proc/pids.h @@ -195,6 +195,10 @@ struct pids_reap { stack -> head [ rel_enum ] . result . type +struct pids_stack *fatal_proc_unmounted ( + struct procps_pidsinfo *info, + int return_self); + int procps_pids_new ( struct procps_pidsinfo **info, int maxitems,