From 7291b145755836fbf7d7f8b449929e16cba967fa Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Sun, 12 May 2019 16:06:27 -0700 Subject: [PATCH] memory: get FD using the SysprofHelpers --- src/libsysprof/sysprof-memory-source.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libsysprof/sysprof-memory-source.c b/src/libsysprof/sysprof-memory-source.c index cf5b736f..20cc88c9 100644 --- a/src/libsysprof/sysprof-memory-source.c +++ b/src/libsysprof/sysprof-memory-source.c @@ -29,6 +29,7 @@ #include #include +#include "sysprof-helpers.h" #include "sysprof-memory-source.h" #define BUF_SIZE 4096 @@ -85,6 +86,9 @@ static GHashTable *keys; static void mem_stat_open (MemStat *st) { + SysprofHelpers *helpers = sysprof_helpers_get_default (); + g_autoptr(GError) error = NULL; + g_assert (st != NULL); g_assert (st->stat_fd == -1); @@ -92,12 +96,13 @@ mem_stat_open (MemStat *st) { g_autofree gchar *path = g_strdup_printf ("/proc/%d/statm", st->pid); - if (-1 == (st->stat_fd = open (path, O_RDONLY))) - g_warning ("Failed to access statm for pid %d", st->pid); + if (!sysprof_helpers_get_proc_fd (helpers, path, NULL, &st->stat_fd, &error)) + g_warning ("Failed to access statm for pid %d: %s", st->pid, error->message); } else { - st->stat_fd = open ("/proc/meminfo", O_RDONLY); + if (!sysprof_helpers_get_proc_fd (helpers, "/proc/meminfo", NULL, &st->stat_fd, &error)) + g_warning ("Failed to access /proc/statm: %s", error->message); } }