diff options
author | Justus Winter <justus@gnupg.org> | 2016-10-13 22:52:49 +0200 |
---|---|---|
committer | Justus Winter <justus@gnupg.org> | 2016-10-15 21:36:38 +0200 |
commit | 587704fc6a85e3ac080c58b7dfa9ebc73c72fede (patch) | |
tree | f9bf30bdb11d5fa9bf337df0d91d4b8917fb1704 | |
parent | 0719a1600ade8d1d0f5031778abf850a8b520efc (diff) |
procfs: Gracefully degrade meminfo.
* procfs/rootdir.c (rootdir_gc_meminfo): Just omit the swap
information if the default pager is unreachable.
-rw-r--r-- | procfs/rootdir.c | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/procfs/rootdir.c b/procfs/rootdir.c index 8e7c6595..748805e7 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 |