diff options
author | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-21 09:26:09 +0000 |
---|---|---|
committer | Jeremie Koenig <jk@jk.fr.eu.org> | 2010-08-30 14:19:08 +0200 |
commit | 1f1661d6a5b6f22acb48460b5304e29af2a0a554 (patch) | |
tree | 0aa7eb5eb5838df4e946cb7317f3cc2f18b30eba /proclist.c | |
parent | 086569ee636d91a820aa23031dda3cb74bab9505 (diff) |
Use libps and enhance [pid]/stat
* Makefile: Add libps to the $(LIBS).
* proclist.c, proclist.h: Embed the proc server port in a
ps_context structure. (proclist_make_node): Change to prototype to
allow for the possibility of error. Rename to proclist_create_node to
reflect the change and non-triviality.
* process.c, process.h: Revamp. Use a full-blown procstat
structure instead of just the procinfo fetched from the process
server. Use the additional data to complement [pid]/stat.
(process_lookup_pid): Get a ps_context structure instead of a port to
the process server.
* main.c (root_make_node): Convert to the new interface for
proclist_create_node.
Diffstat (limited to 'proclist.c')
-rw-r--r-- | proclist.c | 35 |
1 files changed, 15 insertions, 20 deletions
@@ -3,27 +3,23 @@ #include <string.h> #include <mach.h> #include <hurd/process.h> +#include <ps.h> #include "procfs.h" #include "process.h" #define PID_STR_SIZE (3 * sizeof (pid_t) + 1) -struct proclist_node -{ - process_t process; -}; - static error_t proclist_get_contents (void *hook, void **contents, size_t *contents_len) { - struct proclist_node *pl = hook; + struct ps_context *pc = hook; pidarray_t pids; mach_msg_type_number_t num_pids; error_t err; int i; num_pids = 0; - err = proc_getallpids (pl->process, &pids, &num_pids); + err = proc_getallpids (pc->server, &pids, &num_pids); if (err) return EIO; @@ -48,7 +44,7 @@ proclist_get_contents (void *hook, void **contents, size_t *contents_len) static error_t proclist_lookup (void *hook, const char *name, struct node **np) { - struct proclist_node *pl = hook; + struct ps_context *pc = hook; char *endp; pid_t pid; @@ -63,28 +59,27 @@ proclist_lookup (void *hook, const char *name, struct node **np) if (*endp) return ENOENT; - return process_lookup_pid (pl->process, pid, np); + return process_lookup_pid (pc, pid, np); } -struct node * -proclist_make_node (process_t process) +error_t +proclist_create_node (process_t procserv, struct node **np) { static const struct procfs_node_ops ops = { .get_contents = proclist_get_contents, .lookup = proclist_lookup, .cleanup_contents = procfs_cleanup_contents_with_free, - .cleanup = free, + .cleanup = (void (*)(void *)) ps_context_free, .enable_refresh_hack_and_break_readdir = 1, }; - struct proclist_node *pl; - - pl = malloc (sizeof *pl); - if (! pl) - return NULL; + struct ps_context *pc; + error_t err; - memset (pl, 0, sizeof *pl); - pl->process = process; + err = ps_context_create (procserv, &pc); + if (err) + return err; - return procfs_make_node (&ops, pl); + *np = procfs_make_node (&ops, pc); + return 0; } |