add helper to check if we can see pids

This commit is contained in:
Christian Hergert
2019-05-10 19:58:25 -07:00
parent 907064583f
commit 63969f0c09
2 changed files with 29 additions and 0 deletions

View File

@ -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;
}

View File

@ -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,