[sysprof] add helper to check if we can see pids



commit 63969f0c0961a4e5db7260dff2415e36551ae341
Author: Christian Hergert <chergert redhat com>
Date:   Fri May 10 19:58:25 2019 -0700

    add helper to check if we can see pids

 src/helpers.c | 28 ++++++++++++++++++++++++++++
 src/helpers.h |  1 +
 2 files changed, 29 insertions(+)
---
diff --git a/src/helpers.c b/src/helpers.c
index c8e13c0..7aea216 100644
--- a/src/helpers.c
+++ b/src/helpers.c
@@ -280,3 +280,31 @@ helpers_get_proc_file (const gchar  *path,
          g_str_has_prefix (canon, "/proc/") &&
          g_file_get_contents (canon, contents, len, NULL);
 }
+
+gboolean
+helpers_can_see_pids (void)
+{
+  g_autofree gchar *contents = NULL;
+  gsize len = 0;
+
+  if (g_file_test ("/.flatpak-info", G_FILE_TEST_EXISTS))
+    return FALSE;
+
+  if (helpers_get_proc_file ("/proc/mounts", &contents, &len))
+    {
+      g_auto(GStrv) lines = g_strsplit (contents, "\n", 0);
+
+      for (guint i = 0; lines[i]; i++)
+        {
+          if (!g_str_has_prefix (lines[i], "proc /proc "))
+            continue;
+
+          if (strstr (lines[i], "hidepid=") && !strstr (lines[i], "hidepid=0"))
+            return FALSE;
+
+          return TRUE;
+        }
+    }
+
+  return TRUE;
+}
diff --git a/src/helpers.h b/src/helpers.h
index 4c5fe9a..430a4e2 100644
--- a/src/helpers.h
+++ b/src/helpers.h
@@ -27,6 +27,7 @@
 
 G_BEGIN_DECLS
 
+gboolean helpers_can_see_pids    (void);
 gboolean helpers_list_processes  (gint32      **processes,
                                   gsize        *n_processes);
 gboolean helpers_perf_event_open (GVariant     *options,


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