summaryrefslogtreecommitdiffstats
path: root/src/proc-linux.c
diff options
context:
space:
mode:
authorWilliam Jon McCann <mccann@jhu.edu>2007-03-02 17:51:37 -0500
committerWilliam Jon McCann <mccann@jhu.edu>2007-03-02 17:51:37 -0500
commit4f0911bf685f51b51d05a69a40d3950debb995a0 (patch)
tree1b5d38a8e52126e200c8954b3c185ca7ff4f3f94 /src/proc-linux.c
parent75ad4b862611bd6a39bda06db3db4c9737657dad (diff)
add linux backends for collecting session information
These tools will be used to generate and verify the parameters used to open a session.
Diffstat (limited to 'src/proc-linux.c')
-rw-r--r--src/proc-linux.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/proc-linux.c b/src/proc-linux.c
index 080293e..b766183 100644
--- a/src/proc-linux.c
+++ b/src/proc-linux.c
@@ -421,6 +421,62 @@ proc_stat_free (proc_stat_t *stat)
g_free (stat);
}
+GHashTable *
+proc_pid_get_env_hash (pid_t pid)
+{
+ char *path;
+ gboolean res;
+ char *contents;
+ gsize length;
+ GError *error;
+ GHashTable *hash;
+ int i;
+ gboolean last_was_null;
+
+ contents = NULL;
+ hash = NULL;
+
+ path = g_strdup_printf ("/proc/%u/environ", (guint)pid);
+
+ error = NULL;
+ res = g_file_get_contents (path,
+ &contents,
+ &length,
+ &error);
+ if (! res) {
+ g_warning ("Couldn't read %s: %s", path, error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ hash = g_hash_table_new_full (g_str_hash,
+ g_str_equal,
+ g_free,
+ g_free);
+
+ last_was_null = TRUE;
+ for (i = 0; i < length; i++) {
+ if (contents[i] == '\0') {
+ last_was_null = TRUE;
+ continue;
+ }
+ if (last_was_null) {
+ char **vals;
+ vals = g_strsplit (contents + i, "=", 2);
+ if (vals != NULL) {
+ g_hash_table_insert (hash, vals[0], vals[1]);
+ }
+ }
+ last_was_null = FALSE;
+ }
+
+ out:
+ g_free (contents);
+ g_free (path);
+
+ return hash;
+}
+
char *
proc_pid_get_env (pid_t pid,
const char *var)
@@ -468,6 +524,7 @@ proc_pid_get_env (pid_t pid,
val = g_strdup (contents + i + prefix_len);
break;
}
+ last_was_null = FALSE;
}
out: