Move getpwuid() from backends to gui, use getpwuid_r(), call only once on task add. (bug 14401)
This commit is contained in:
@@ -18,9 +18,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
/* for getpwuid() */
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <pwd.h>
|
|
||||||
/* for sysctl() */
|
/* for sysctl() */
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/sched.h>
|
#include <sys/sched.h>
|
||||||
@@ -54,7 +52,6 @@ gboolean get_task_list (GArray *task_list)
|
|||||||
struct kinfo_proc2 *kp;
|
struct kinfo_proc2 *kp;
|
||||||
#endif
|
#endif
|
||||||
Task t;
|
Task t;
|
||||||
struct passwd *passwdp;
|
|
||||||
char **args;
|
char **args;
|
||||||
gchar* buf;
|
gchar* buf;
|
||||||
int nproc, i;
|
int nproc, i;
|
||||||
@@ -143,10 +140,6 @@ gboolean get_task_list (GArray *task_list)
|
|||||||
|
|
||||||
t.cpu_user = (100.0 * ((double) p.p_pctcpu / FSCALE));
|
t.cpu_user = (100.0 * ((double) p.p_pctcpu / FSCALE));
|
||||||
t.cpu_system = 0.0f; /* TODO ? */
|
t.cpu_system = 0.0f; /* TODO ? */
|
||||||
/* get username from uid */
|
|
||||||
passwdp = getpwuid(t.uid);
|
|
||||||
if(passwdp != NULL && passwdp->pw_name != NULL)
|
|
||||||
g_strlcpy(t.uid_name, passwdp->pw_name, sizeof t.uid_name);
|
|
||||||
g_array_append_val(task_list, t);
|
g_array_append_val(task_list, t);
|
||||||
}
|
}
|
||||||
free(kp);
|
free(kp);
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <sys/user.h>
|
#include <sys/user.h>
|
||||||
#include <sys/proc.h>
|
#include <sys/proc.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -120,7 +119,6 @@ get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
|
|||||||
static gboolean
|
static gboolean
|
||||||
get_task_details (struct kinfo_proc *kp, Task *task)
|
get_task_details (struct kinfo_proc *kp, Task *task)
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
|
||||||
char buf[1024], *p;
|
char buf[1024], *p;
|
||||||
size_t bufsz;
|
size_t bufsz;
|
||||||
int i, oid[4];
|
int i, oid[4];
|
||||||
@@ -132,9 +130,7 @@ get_task_details (struct kinfo_proc *kp, Task *task)
|
|||||||
task->cpu_system = 0.0f;
|
task->cpu_system = 0.0f;
|
||||||
task->vsz = kp->ki_size;
|
task->vsz = kp->ki_size;
|
||||||
task->rss = kp->ki_rssize * getpagesize ();
|
task->rss = kp->ki_rssize * getpagesize ();
|
||||||
pw = getpwuid (kp->ki_uid);
|
|
||||||
task->uid = kp->ki_uid;
|
task->uid = kp->ki_uid;
|
||||||
g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name));
|
|
||||||
task->prio = (gushort)kp->ki_nice;
|
task->prio = (gushort)kp->ki_nice;
|
||||||
g_strlcpy (task->name, kp->ki_comm, sizeof(task->name));
|
g_strlcpy (task->name, kp->ki_comm, sizeof(task->name));
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -294,7 +293,6 @@ get_task_details (GPid pid, Task *task)
|
|||||||
|
|
||||||
/* Parse the status file: it contains the UIDs */
|
/* Parse the status file: it contains the UIDs */
|
||||||
{
|
{
|
||||||
struct passwd *pw;
|
|
||||||
guint dummy;
|
guint dummy;
|
||||||
|
|
||||||
snprintf(filename, sizeof (filename), "/proc/%d/status", pid);
|
snprintf(filename, sizeof (filename), "/proc/%d/status", pid);
|
||||||
@@ -307,9 +305,6 @@ get_task_details (GPid pid, Task *task)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|
||||||
pw = getpwuid (task->uid);
|
|
||||||
g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the full command line */
|
/* Read the full command line */
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
/* Add includes for system functions needed */
|
/* Add includes for system functions needed */
|
||||||
/* Example:
|
/* Example:
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <kstat.h>
|
#include <kstat.h>
|
||||||
#include <pwd.h>
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -173,7 +172,6 @@ get_task_details (GPid pid, Task *task)
|
|||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
gchar filename[96];
|
gchar filename[96];
|
||||||
struct passwd *pw;
|
|
||||||
psinfo_t process;
|
psinfo_t process;
|
||||||
|
|
||||||
snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid);
|
snprintf (filename, sizeof(filename), "/proc/%d/psinfo", pid);
|
||||||
@@ -195,9 +193,7 @@ get_task_details (GPid pid, Task *task)
|
|||||||
task->vsz = (guint64)process.pr_size * 1024;
|
task->vsz = (guint64)process.pr_size * 1024;
|
||||||
task->rss = (guint64)process.pr_rssize * 1024;
|
task->rss = (guint64)process.pr_rssize * 1024;
|
||||||
task->prio = (gushort)process.pr_lwp.pr_pri;
|
task->prio = (gushort)process.pr_lwp.pr_pri;
|
||||||
pw = getpwuid (process.pr_uid);
|
|
||||||
task->uid = (guint)process.pr_uid;
|
task->uid = (guint)process.pr_uid;
|
||||||
g_strlcpy (task->uid_name, (pw != NULL) ? pw->pw_name : "nobody", sizeof (task->uid_name));
|
|
||||||
get_cpu_percent (task->pid, (process.pr_time.tv_sec * 1000 + process.pr_time.tv_nsec / 100000), &task->cpu_user, 0, &task->cpu_system);
|
get_cpu_percent (task->pid, (process.pr_time.tv_sec * 1000 + process.pr_time.tv_nsec / 100000), &task->cpu_user, 0, &task->cpu_system);
|
||||||
|
|
||||||
fclose (file);
|
fclose (file);
|
||||||
|
|||||||
@@ -166,17 +166,17 @@ model_add_task (XtmTaskManager *manager, Task *task, glong timestamp)
|
|||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GtkTreeModel *model = manager->model;
|
GtkTreeModel *model = manager->model;
|
||||||
|
gchar *uid_name = get_uid_name (task->uid);
|
||||||
|
|
||||||
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
||||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||||
XTM_PTV_COLUMN_PID, task->pid,
|
XTM_PTV_COLUMN_PID, task->pid,
|
||||||
XTM_PTV_COLUMN_STATE, task->state,
|
XTM_PTV_COLUMN_STATE, task->state,
|
||||||
XTM_PTV_COLUMN_UID, task->uid,
|
XTM_PTV_COLUMN_UID, task->uid,
|
||||||
XTM_PTV_COLUMN_UID_STR, task->uid_name,
|
XTM_PTV_COLUMN_UID_STR, uid_name,
|
||||||
XTM_PTV_COLUMN_BACKGROUND, NULL,
|
|
||||||
XTM_PTV_COLUMN_FOREGROUND, NULL,
|
|
||||||
XTM_PTV_COLUMN_TIMESTAMP, timestamp,
|
XTM_PTV_COLUMN_TIMESTAMP, timestamp,
|
||||||
-1);
|
-1);
|
||||||
|
g_free(uid_name);
|
||||||
model_update_tree_iter (manager, &iter, timestamp, TRUE, task);
|
model_update_tree_iter (manager, &iter, timestamp, TRUE, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -524,6 +524,19 @@ get_hostname (void)
|
|||||||
return g_strdup_printf ("%s", hostname);
|
return g_strdup_printf ("%s", hostname);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar *
|
||||||
|
get_uid_name (guint uid)
|
||||||
|
{
|
||||||
|
int error;
|
||||||
|
struct passwd *pw = NULL, pwd_buf;
|
||||||
|
char buf[4096];
|
||||||
|
|
||||||
|
bzero(buf, sizeof(buf));
|
||||||
|
error = getpwuid_r(uid, &pwd_buf, buf, sizeof(buf), &pw);
|
||||||
|
|
||||||
|
return (g_strdup ((0 == error && pw != NULL) ? pw->pw_name : "nobody"));
|
||||||
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
send_signal_to_pid (GPid pid, gint xtm_signal)
|
send_signal_to_pid (GPid pid, gint xtm_signal)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ typedef struct _Task Task;
|
|||||||
struct _Task
|
struct _Task
|
||||||
{
|
{
|
||||||
guint uid;
|
guint uid;
|
||||||
gchar uid_name[256];
|
|
||||||
GPid pid;
|
GPid pid;
|
||||||
GPid ppid;
|
GPid ppid;
|
||||||
gchar name[256];
|
gchar name[256];
|
||||||
@@ -94,6 +93,7 @@ enum
|
|||||||
|
|
||||||
void get_owner_uid (guint *owner_uid, gchar **owner_uid_name);
|
void get_owner_uid (guint *owner_uid, gchar **owner_uid_name);
|
||||||
gchar * get_hostname (void);
|
gchar * get_hostname (void);
|
||||||
|
gchar * get_uid_name (guint uid);
|
||||||
gboolean send_signal_to_pid (GPid pid, gint xtm_signal);
|
gboolean send_signal_to_pid (GPid pid, gint xtm_signal);
|
||||||
gint task_pid_compare_fn (gconstpointer a, gconstpointer b);
|
gint task_pid_compare_fn (gconstpointer a, gconstpointer b);
|
||||||
gboolean set_priority_to_pid (GPid pid, gint priority);
|
gboolean set_priority_to_pid (GPid pid, gint priority);
|
||||||
|
|||||||
Reference in New Issue
Block a user