mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
sysprofd: add API to get a FD for a file in proc
This is useful for optimized parsing of proc files such as necessary by the memory source to seek() back to the start (instead of re-opening a new file).
This commit is contained in:
@ -22,6 +22,7 @@
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <gio/gio.h>
|
||||
#include <errno.h>
|
||||
#ifdef __linux__
|
||||
@ -281,6 +282,25 @@ helpers_get_proc_file (const gchar *path,
|
||||
g_file_get_contents (canon, contents, len, NULL);
|
||||
}
|
||||
|
||||
gboolean
|
||||
helpers_get_proc_fd (const gchar *path,
|
||||
gint *out_fd)
|
||||
{
|
||||
g_autofree gchar *canon = NULL;
|
||||
g_autoptr(GFile) file = NULL;
|
||||
|
||||
g_assert (path != NULL);
|
||||
g_assert (out_fd != NULL);
|
||||
|
||||
/* Canonicalize filename */
|
||||
file = g_file_new_for_path (path);
|
||||
canon = g_file_get_path (file);
|
||||
|
||||
return g_file_is_native (file) &&
|
||||
(g_str_has_prefix (canon, "/proc/") || g_str_has_prefix (canon, "/sys/")) &&
|
||||
-1 != (*out_fd = open (canon, O_RDONLY | O_CLOEXEC));
|
||||
}
|
||||
|
||||
gboolean
|
||||
helpers_can_see_pids (void)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user