[Xfce4-commits] [apps/xfce4-taskmanager] 01/01: Fix UID reporting properly

noreply at xfce.org noreply at xfce.org
Sat Nov 11 22:11:27 CET 2017


This is an automated email from the git hooks/post-receive script.

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-taskmanager.

commit 946be336114ed84ad5d24838b4ae14a0bfc0f0fe
Author: Bobby Hopere <bobbyhopere at mail.com>
Date:   Sat Nov 11 22:09:20 2017 +0100

    Fix UID reporting properly
    
    The patch that was already committed apparently fixes the issue but
    using a non-documented method. This patch fixes the issue as described in
    "man proc". (The UID is extracted by parsing /proc/*/status not by using
    stat() on /proc/*/task). Also, this patch can easily be extended to also
    report other UIDs besides the "effective" UID: real, effective, saved
    set, and filesystem UIDs.
---
 src/task-manager-linux.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/task-manager-linux.c b/src/task-manager-linux.c
index 3242e5c..1262d08 100644
--- a/src/task-manager-linux.c
+++ b/src/task-manager-linux.c
@@ -223,8 +223,6 @@ get_task_details (guint pid, Task *task)
 		gchar dummy[256];
 		gint idummy;
 		gulong jiffies_user = 0, jiffies_system = 0;
-		struct passwd *pw;
-		struct stat sstat;
 
 		sscanf(buffer, "%i %255s %1s %i %i %i %i %i %255s %255s %255s %255s %255s %lu %lu %i %i %i %d %i %i %i %llu %llu %255s %255s %255s %i %255s %255s %255s %255s %255s %255s %255s %255s %255s %255s %i %255s %255s",
 			&task->pid,	// processid
@@ -280,11 +278,25 @@ get_task_details (guint pid, Task *task)
 
 		task->rss *= get_pagesize ();
 		get_cpu_percent (task->pid, jiffies_user, &task->cpu_user, jiffies_system, &task->cpu_system);
+	}
+
+	/* Parse the status file: it contains the UIDs */
+	{
+		struct passwd *pw;
+		guint dummy;
+
+		snprintf(filename, sizeof (filename), "/proc/%d/status", pid);
+		if ((file = fopen (filename, "r")) == NULL)
+			return FALSE;
+
+		while (fgets (buffer, sizeof(buffer), file) != NULL)
+		{
+			if (sscanf (buffer, "Uid:\t%u\t%u\t%u\t%u", &dummy, &task->uid, &dummy, &dummy) == 1) // UIDs in order: real, effective, saved set, and filesystem
+				break;
+		}
+		fclose (file);
 
-		snprintf (filename, sizeof(filename), "/proc/%d/task", pid);
-		stat (filename, &sstat);
-		pw = getpwuid (sstat.st_uid);
-		task->uid = sstat.st_uid;
+		pw = getpwuid (task->uid);
 		g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name));
 	}
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list