commit-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[hurd] 23/25: procfs: Gracefully degrade meminfo.


From: Samuel Thibault
Subject: [hurd] 23/25: procfs: Gracefully degrade meminfo.
Date: Mon, 24 Oct 2016 00:16:46 +0000

This is an automated email from the git hooks/post-receive script.

sthibault pushed a commit to branch upstream
in repository hurd.

commit 587704fc6a85e3ac080c58b7dfa9ebc73c72fede
Author: Justus Winter <address@hidden>
Date:   Thu Oct 13 22:52:49 2016 +0200

    procfs: Gracefully degrade meminfo.
    
    * procfs/rootdir.c (rootdir_gc_meminfo): Just omit the swap
    information if the default pager is unreachable.
---
 procfs/rootdir.c | 44 ++++++++++++++++++++++++++++++++------------
 1 file changed, 32 insertions(+), 12 deletions(-)

diff --git a/procfs/rootdir.c b/procfs/rootdir.c
index 8e7c659..748805e 100644
--- a/procfs/rootdir.c
+++ b/procfs/rootdir.c
@@ -272,27 +272,37 @@ rootdir_gc_meminfo (void *hook, char **contents, ssize_t 
*contents_len)
   struct vm_statistics vmstats;
   struct vm_cache_statistics cache_stats;
   default_pager_info_t swap;
+  FILE *m;
   error_t err;
 
+  m = open_memstream (contents, (size_t *) contents_len);
+  if (m == NULL)
+    {
+      err = ENOMEM;
+      goto out;
+    }
+
   err = vm_statistics (mach_task_self (), &vmstats);
   if (err)
-    return EIO;
+    {
+      err = EIO;
+      goto out;
+    }
 
   err = vm_cache_statistics (mach_task_self (), &cache_stats);
   if (err)
-    return EIO;
+    {
+      err = EIO;
+      goto out;
+    }
 
   cnt = HOST_BASIC_INFO_COUNT;
   err = host_info (mach_host_self (), HOST_BASIC_INFO, (host_info_t) &hbi, 
&cnt);
   if (err)
-    return err;
-
-  err = get_swapinfo (&swap);
-  if (err)
-    return err;
+    goto out;
 
   assert (cnt == HOST_BASIC_INFO_COUNT);
-  *contents_len = asprintf (contents,
+  fprintf (m,
       "MemTotal: %14lu kB\n"
       "MemFree:  %14lu kB\n"
       "Buffers:  %14lu kB\n"
@@ -300,8 +310,6 @@ rootdir_gc_meminfo (void *hook, char **contents, ssize_t 
*contents_len)
       "Active:   %14lu kB\n"
       "Inactive: %14lu kB\n"
       "Mlocked:  %14lu kB\n"
-      "SwapTotal:%14lu kB\n"
-      "SwapFree: %14lu kB\n"
       ,
       (long unsigned) hbi.memory_size / 1024,
       (long unsigned) vmstats.free_count * PAGE_SIZE / 1024,
@@ -309,11 +317,23 @@ rootdir_gc_meminfo (void *hook, char **contents, ssize_t 
*contents_len)
       (long unsigned) cache_stats.cache_count * PAGE_SIZE / 1024,
       (long unsigned) vmstats.active_count * PAGE_SIZE / 1024,
       (long unsigned) vmstats.inactive_count * PAGE_SIZE / 1024,
-      (long unsigned) vmstats.wire_count * PAGE_SIZE / 1024,
+      (long unsigned) vmstats.wire_count * PAGE_SIZE / 1024);
+
+  err = get_swapinfo (&swap);
+  if (err)
+    /* This is not fatal, we just omit the information.  */
+    err = 0;
+  else
+    fprintf (m,
+      "SwapTotal:%14lu kB\n"
+      "SwapFree: %14lu kB\n"
+      ,
       (long unsigned) swap.dpi_total_space / 1024,
       (long unsigned) swap.dpi_free_space / 1024);
 
-  return 0;
+ out:
+  fclose (m);
+  return err;
 }
 
 static error_t

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-hurd/hurd.git



reply via email to

[Prev in Thread] Current Thread [Next in Thread]