summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1999-06-02 06:24:39 +0000
committerRoland McGrath <roland@gnu.org>1999-06-02 06:24:39 +0000
commit4a4796ab4f9d43989e2b89fe4f98a8c7f69e80d7 (patch)
tree89a3bae010fc5979b50d08701d085b853f1e8388
parent793c7dd6961f5caed444bb10a871e4d2aff8b0fc (diff)
1999-06-02 Roland McGrath <roland@baalperazim.frob.com>
* ps.h (PSTAT_ENV): New macro. (struct proc_stat): New members `env', `env_len', `env_vm_alloced'. (proc_stat_env, proc_stat_env_len): New accessor macros. (PSTAT_USER_BASE): Increase value to leave more room for additions. * procstat.c (proc_stat_set_flags): Handle environment. (_proc_stat_free): Likewise. * spec.c (ps_get_env, ps_env_getter): New function and constant. (specs): New spec "Env" using ps_env_getter and ps_emit_args.
-rw-r--r--libps/procstat.c23
-rw-r--r--libps/ps.h28
-rw-r--r--libps/spec.c11
3 files changed, 52 insertions, 10 deletions
diff --git a/libps/procstat.c b/libps/procstat.c
index b9a3e632..8b120bd8 100644
--- a/libps/procstat.c
+++ b/libps/procstat.c
@@ -1,6 +1,6 @@
/* The proc_stat type, which holds information about a hurd process.
- Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -938,6 +938,26 @@ proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags)
}
}
+ /* The process's exec environment */
+ if (NEED (PSTAT_ENV, PSTAT_PID))
+ {
+ char *buf = malloc (100);
+ ps->env_len = 100;
+ ps->env = buf;
+ if (ps->env)
+ {
+ if (proc_getprocenv (server, ps->pid, &ps->env, &ps->env_len))
+ free (buf);
+ else
+ {
+ have |= PSTAT_ENV;
+ ps->env_vm_alloced = (ps->env != buf);
+ if (ps->env_vm_alloced)
+ free (buf);
+ }
+ }
+ }
+
/* The ctty id port; note that this is just a magic cookie;
we use it to fetch a port to the actual terminal -- it's not useful for
much else. */
@@ -1049,6 +1069,7 @@ _proc_stat_free (ps)
MFREEMEM (PSTAT_THREAD_BASIC, thread_basic_info, 0, 0, 0, 0);
MFREEMEM (PSTAT_THREAD_SCHED, thread_sched_info, 0, 0, 0, 0);
MFREEMEM (PSTAT_ARGS, args, ps->args_len, ps->args_vm_alloced, 0, char);
+ MFREEMEM (PSTAT_ENV, env, ps->env_len, ps->env_vm_alloced, 0, char);
MFREEMEM (PSTAT_TASK_EVENTS, task_events_info, ps->task_events_info_size,
0, &ps->task_events_info_buf, char);
diff --git a/libps/ps.h b/libps/ps.h
index 95611b70..417ad374 100644
--- a/libps/ps.h
+++ b/libps/ps.h
@@ -1,6 +1,6 @@
/* Routines to gather and print process information.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996, 1999 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -41,7 +41,7 @@ struct ps_user
/* The status */
enum ps_user_passwd_state passwd_state;
-
+
/* The user's password file entry. Only valid if PASSWD_STATE ==
PS_USER_PASSWD_OK. */
struct passwd passwd;
@@ -85,7 +85,7 @@ enum ps_tty_name_state
struct ps_tty {
/* Which tty this refers to. */
file_t port;
-
+
/* The name of the tty, if we could figure it out. */
const char *name;
/* What state the name is in. */
@@ -269,6 +269,7 @@ struct proc_stat
unsigned proc_info_vm_alloced : 1;
unsigned thread_waits_vm_alloced : 1;
unsigned args_vm_alloced : 1;
+ unsigned env_vm_alloced : 1;
/* Various libc ports: */
@@ -294,6 +295,12 @@ struct proc_stat
/* A hook for the user to use. */
void *hook;
+
+ /* XXX these members added at the end for binary compatibility */
+ /* The process's envp, as a string with each element separated by '\0'. */
+ char *env;
+ /* The length of ENV. */
+ unsigned env_len;
};
/* Proc_stat flag bits; each bit is set in the FLAGS field if that
@@ -319,6 +326,7 @@ struct proc_stat
#define PSTAT_THREAD_WAIT 0x00800 /* The rpc the thread is waiting on. */
#define PSTAT_THREAD_WAITS 0x01000 /* Thread waits for this PS's threads */
#define PSTAT_ARGS 0x02000 /* The process's args */
+#define PSTAT_ENV 0x2000000 /* The process's environment */
#define PSTAT_STATE 0x04000 /* A bitmask describing the process's
state (see below) */
#define PSTAT_SUSPEND_COUNT 0x08000 /* Task/thread suspend count */
@@ -335,7 +343,7 @@ struct proc_stat
#define PSTAT_NO_MSGPORT 0x1000000 /* Don't use the msgport at all */
/* Bits from PSTAT_USER_BASE on up are available for user-use. */
-#define PSTAT_USER_BASE 0x2000000
+#define PSTAT_USER_BASE 0x10000000
#define PSTAT_USER_MASK ~(PSTAT_USER_BASE - 1)
/* If the PSTAT_STATE flag is set, then the proc_stats state field holds a
@@ -422,6 +430,8 @@ char *proc_stat_state_tags;
#define proc_stat_suspend_count(ps) ((ps)->suspend_count)
#define proc_stat_args(ps) ((ps)->args)
#define proc_stat_args_len(ps) ((ps)->args_len)
+#define proc_stat_env(ps) ((ps)->env)
+#define proc_stat_env_len(ps) ((ps)->env_len)
#define proc_stat_state(ps) ((ps)->state)
#define proc_stat_cttyid(ps) ((ps)->cttyid)
#define proc_stat_cwdir(ps) ((ps)->cwdir)
@@ -506,7 +516,7 @@ struct ps_getter
ps_flags_t needs;
/* A function that will get the value; the protocol between this function
- and its caller is type-dependent. */
+ and its caller is type-dependent. */
void (*fn) ();
};
@@ -610,7 +620,7 @@ error_t ps_stream_write_int_field (struct ps_stream *stream,
int value, int width);
/* A PS_FMT_SPEC describes how to output something from a PROC_STAT; it
- is a combination of a getter (describing how to get the value), an output
+ is a combination of a getter (describing how to get the value), an output
function (which outputs the result of the getter), and a compare function
(which can be used to sort proc_stats according to how they are
output). It also specifies the default width of the field in which the
@@ -622,7 +632,7 @@ struct ps_fmt_spec
{
/* The name of the spec (and it's title, if TITLE is NULL). */
const char *name;
-
+
/* The title to be printed in the headers. */
const char *title;
@@ -675,7 +685,7 @@ struct ps_fmt_specs
struct ps_fmt_spec_block *expansions; /* Storage for expanded aliases. */
};
-/* An struct ps_fmt_specs, suitable for use with ps_fmt_specs_find,
+/* An struct ps_fmt_specs, suitable for use with ps_fmt_specs_find,
containing specs for most values in a proc_stat. */
extern struct ps_fmt_specs ps_std_fmt_specs;
@@ -739,7 +749,7 @@ struct ps_fmt
/* The (valid) length of the fields array. */
unsigned num_fields;
- /* A set of proc_stat flags describing what a proc_stat needs to hold in
+ /* A set of proc_stat flags describing what a proc_stat needs to hold in
order to print out every field in the fmt. */
ps_flags_t needs;
diff --git a/libps/spec.c b/libps/spec.c
index f790b691..1e30d95b 100644
--- a/libps/spec.c
+++ b/libps/spec.c
@@ -122,6 +122,15 @@ ps_get_args (struct proc_stat *ps, char **args_p, int *args_len_p)
const struct ps_getter ps_args_getter =
{"args", PSTAT_ARGS, ps_get_args};
+static void
+ps_get_env (struct proc_stat *ps, char **env_p, int *env_len_p)
+{
+ *env_p = proc_stat_env (ps);
+ *env_len_p = proc_stat_env_len (ps);
+}
+const struct ps_getter ps_env_getter =
+{"env", PSTAT_ENV, ps_get_env};
+
static int
ps_get_state (struct proc_stat *ps)
{
@@ -1087,6 +1096,8 @@ static const struct ps_fmt_spec specs[] =
&ps_args_getter, ps_emit_args, ps_cmp_strings,ps_nominal_string},
{"Arg0", 0, 0, -1, 0,
&ps_args_getter, ps_emit_string, ps_cmp_strings,ps_nominal_string},
+ {"Env", 0, 0, -1, 0,
+ &ps_env_getter, ps_emit_args, ps_cmp_strings,ps_nominal_string},
{"Start", 0, -7, 1, 0,
&ps_start_time_getter, ps_emit_past_time, ps_cmp_times,0},
{"Time", 0, -8, 2, 0,