]> granicus.if.org Git - procps-ng/commitdiff
library: introduce a fatal 'proc not mounted' function
authorJim Warner <james.warner@comcast.net>
Fri, 11 Sep 2015 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Mon, 21 Sep 2015 12:38:38 +0000 (22:38 +1000)
Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/libprocps.sym
proc/pids.c
proc/pids.h

index c32258dd724c2baf69ede92cb312b664f9c62b6f..9236454de2e17633caec58ed30ae5cfb3a3a50b2 100644 (file)
@@ -6,6 +6,7 @@ global:
        escape_str;
        escape_strlist;
        escaped_copy;
+       fatal_proc_unmounted;
        freeproc;
        get_pid_digits;
        look_up_our_self;
index 25ae3e3ac6f55893fe31ad5c4cabd1977a4e8f94..d35fca2bb4f0c7f387614e79f5d6be85311a3d61 100644 (file)
@@ -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)
index 60f8a46acce015c2a914333c0d82ed621c94669e..ca43dfa7bee183017ee9d503774d85931f97fe4a 100644 (file)
@@ -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,