summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWilliam Jon McCann <mccann@jhu.edu>2007-03-05 14:39:07 -0500
committerWilliam Jon McCann <mccann@jhu.edu>2007-03-05 14:39:07 -0500
commit4749b0ecb6241517685a2a809695a85bd9f93432 (patch)
tree335fb0cd80a78a1cf8ff14d8cf5f5fd6ac23dee8
parent4b245b3113480d495440e1b7d32eb4dc6d564c8c (diff)
add two more proc sysdep functions
-rw-r--r--src/proc-linux.c53
-rw-r--r--src/proc.h4
2 files changed, 57 insertions, 0 deletions
diff --git a/src/proc-linux.c b/src/proc-linux.c
index b766183..30e7d22 100644
--- a/src/proc-linux.c
+++ b/src/proc-linux.c
@@ -258,6 +258,16 @@ link_name (guint maj,
return tty;
}
+pid_t
+proc_stat_get_ppid (proc_stat_t *stat)
+{
+ if (stat == NULL) {
+ return -1;
+ }
+
+ return stat->ppid;
+}
+
char *
proc_stat_get_cmd (proc_stat_t *stat)
{
@@ -534,3 +544,46 @@ proc_pid_get_env (pid_t pid,
return val;
}
+
+uid_t
+proc_pid_get_uid (pid_t pid)
+{
+ struct stat st;
+ char *path;
+ int uid;
+ int res;
+
+ uid = -1;
+
+ path = g_strdup_printf ("/proc/%u", (guint)pid);
+ res = stat (path, &st);
+ g_free (path);
+
+ if (res == 0) {
+ uid = st.st_uid;
+ }
+
+ return uid;
+}
+
+pid_t
+proc_pid_get_ppid (pid_t pid)
+{
+ int ppid;
+ gboolean res;
+ proc_stat_t *stat;
+
+ ppid = -1;
+
+ res = proc_stat_new_for_pid (pid, &stat, NULL);
+ if (! res) {
+ goto out;
+ }
+
+ ppid = proc_stat_get_ppid (stat);
+
+ proc_stat_free (stat);
+
+ out:
+ return ppid;
+}
diff --git a/src/proc.h b/src/proc.h
index 4ddf64b..8c3fc64 100644
--- a/src/proc.h
+++ b/src/proc.h
@@ -30,6 +30,7 @@ typedef struct _proc_stat_t proc_stat_t;
gboolean proc_stat_new_for_pid (pid_t pid,
proc_stat_t **stat,
GError **error);
+pid_t proc_stat_get_ppid (proc_stat_t *stat);
char *proc_stat_get_tty (proc_stat_t *stat);
char *proc_stat_get_cmd (proc_stat_t *stat);
void proc_stat_free (proc_stat_t *stat);
@@ -39,6 +40,9 @@ char *proc_pid_get_env (pid_t pid,
GHashTable *proc_pid_get_env_hash (pid_t pid);
+pid_t proc_pid_get_ppid (pid_t pid);
+uid_t proc_pid_get_uid (pid_t pid);
+
G_END_DECLS
#endif /* __PROC_H */