[tracker] tracker: detect uid from /proc/pid



commit 6d942b0a4df2ea234252e9bb93e7f8018d232456
Author: Denis Zalevskiy <denis zalevskiy jolla com>
Date:   Thu Oct 1 17:50:34 2015 +0300

    tracker: detect uid from /proc/pid
    
    Owner UID of the /proc/[pid]/cmdline could be different than process real UID
    while /proc/[pid] owner is expected to be equal.
    
    Signed-off-by: Denis Zalevskiy <denis zalevskiy jolla com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755945

 src/tracker/tracker-process.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/src/tracker/tracker-process.c b/src/tracker/tracker-process.c
index 71800d2..4262bbe 100644
--- a/src/tracker/tracker-process.c
+++ b/src/tracker/tracker-process.c
@@ -105,15 +105,18 @@ tracker_process_get_uid_for_pid (const gchar  *pid_as_string,
        GFileInfo *info;
        GError *error = NULL;
        gchar *fn;
+       gchar *proc_dir_name;
        guint uid;
 
+       proc_dir_name = g_build_filename ("/proc", pid_as_string, NULL);
+
 #ifdef __sun /* Solaris */
-       fn = g_build_filename ("/proc", pid_as_string, "psinfo", NULL);
+       fn = g_build_filename (proc_dir_name, "psinfo", NULL);
 #else
-       fn = g_build_filename ("/proc", pid_as_string, "cmdline", NULL);
+       fn = g_build_filename (proc_dir_name, "cmdline", NULL);
 #endif
 
-       f = g_file_new_for_path (fn);
+       f = g_file_new_for_path (proc_dir_name);
        info = g_file_query_info (f,
                                  G_FILE_ATTRIBUTE_UNIX_UID,
                                  G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -121,7 +124,7 @@ tracker_process_get_uid_for_pid (const gchar  *pid_as_string,
                                  &error);
 
        if (error) {
-               g_printerr ("%s '%s', %s", _("Could not stat() file"), fn, error->message);
+               g_printerr ("%s '%s', %s", _("Could not stat() file"), proc_dir_name, error->message);
                g_error_free (error);
                uid = 0;
        } else {
@@ -129,6 +132,8 @@ tracker_process_get_uid_for_pid (const gchar  *pid_as_string,
                g_object_unref (info);
        }
 
+       g_free (proc_dir_name);
+
        if (filename) {
                *filename = fn;
        } else {


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