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.
This commit is contained in:
committed by
Simon Steinbeiss
parent
eed347b74b
commit
946be33611
@@ -223,8 +223,6 @@ get_task_details (guint pid, Task *task)
|
|||||||
gchar dummy[256];
|
gchar dummy[256];
|
||||||
gint idummy;
|
gint idummy;
|
||||||
gulong jiffies_user = 0, jiffies_system = 0;
|
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",
|
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
|
&task->pid, // processid
|
||||||
@@ -280,11 +278,25 @@ get_task_details (guint pid, Task *task)
|
|||||||
|
|
||||||
task->rss *= get_pagesize ();
|
task->rss *= get_pagesize ();
|
||||||
get_cpu_percent (task->pid, jiffies_user, &task->cpu_user, jiffies_system, &task->cpu_system);
|
get_cpu_percent (task->pid, jiffies_user, &task->cpu_user, jiffies_system, &task->cpu_system);
|
||||||
|
}
|
||||||
|
|
||||||
snprintf (filename, sizeof(filename), "/proc/%d/task", pid);
|
/* Parse the status file: it contains the UIDs */
|
||||||
stat (filename, &sstat);
|
{
|
||||||
pw = getpwuid (sstat.st_uid);
|
struct passwd *pw;
|
||||||
task->uid = sstat.st_uid;
|
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);
|
||||||
|
|
||||||
|
pw = getpwuid (task->uid);
|
||||||
g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name));
|
g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user