diff options
| author | William Jon McCann <mccann@jhu.edu> | 2007-03-02 17:51:37 -0500 | 
|---|---|---|
| committer | William Jon McCann <mccann@jhu.edu> | 2007-03-02 17:51:37 -0500 | 
| commit | 4f0911bf685f51b51d05a69a40d3950debb995a0 (patch) | |
| tree | 1b5d38a8e52126e200c8954b3c185ca7ff4f3f94 /src | |
| parent | 75ad4b862611bd6a39bda06db3db4c9737657dad (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')
| -rw-r--r-- | src/proc-linux.c | 57 | ||||
| -rw-r--r-- | src/proc.h | 20 | 
2 files changed, 68 insertions, 9 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: @@ -27,15 +27,17 @@ G_BEGIN_DECLS  typedef struct _proc_stat_t proc_stat_t; -gboolean proc_stat_new_for_pid (pid_t         pid, -                                proc_stat_t **stat, -                                GError      **error); -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); - -char    *proc_pid_get_env      (pid_t         pid, -                                const char   *var); +gboolean     proc_stat_new_for_pid (pid_t         pid, +                                    proc_stat_t **stat, +                                    GError      **error); +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); + +char        *proc_pid_get_env      (pid_t         pid, +                                    const char   *var); + +GHashTable  *proc_pid_get_env_hash (pid_t         pid);  G_END_DECLS  | 
