summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c35
-rw-r--r--proclist.c15
-rw-r--r--proclist.h6
-rw-r--r--rootdir.c13
-rw-r--r--rootdir.h6
5 files changed, 36 insertions, 39 deletions
diff --git a/main.c b/main.c
index 4be506f..9115648 100644
--- a/main.c
+++ b/main.c
@@ -4,6 +4,7 @@
#include <error.h>
#include <argp.h>
#include <hurd/netfs.h>
+#include <ps.h>
#include "procfs.h"
#include "proclist.h"
#include "rootdir.h"
@@ -94,38 +95,42 @@ struct argp argp = {
};
error_t
-root_make_node (struct node **np)
+root_make_node (struct ps_context *pc, struct node **np)
{
/* We never have two root nodes alive simultaneously, so it's ok to
have this as static data. */
static struct node *root_dirs[3];
- error_t err;
- err = proclist_create_node (getproc (), &root_dirs[0]);
- if (err)
- return err;
+ root_dirs[0] = proclist_make_node (pc);
+ if (! root_dirs[0])
+ goto nomem;
- err = rootdir_create_node (&root_dirs[1]);
- if (err)
- {
- netfs_nrele (root_dirs[0]);
- return err;
- }
+ root_dirs[1] = rootdir_make_node (pc);
+ if (! root_dirs[1])
+ goto nomem;
root_dirs[2] = NULL;
*np = dircat_make_node (root_dirs);
if (! *np)
- return ENOMEM;
+ goto nomem;
/* Since this one is not created through proc_lookup(), we have to affect an
inode number to it. */
(*np)->nn_stat.st_ino = * (uint32_t *) "PROC";
return 0;
+
+nomem:
+ if (root_dirs[1])
+ netfs_nrele (root_dirs[1]);
+ if (root_dirs[0])
+ netfs_nrele (root_dirs[0]);
+ return ENOMEM;
}
int main (int argc, char **argv)
{
+ struct ps_context *pc;
mach_port_t bootstrap;
error_t err;
@@ -137,12 +142,16 @@ int main (int argc, char **argv)
if (err)
error (1, err, "Could not parse command line");
+ err = ps_context_create (getproc (), &pc);
+ if (err)
+ error (1, err, "Could not create libps context");
+
task_get_bootstrap_port (mach_task_self (), &bootstrap);
if (bootstrap == MACH_PORT_NULL)
error (1, 0, "Must be started as a translator");
netfs_init ();
- err = root_make_node (&netfs_root_node);
+ err = root_make_node (pc, &netfs_root_node);
if (err)
error (1, err, "Could not create the root node");
diff --git a/proclist.c b/proclist.c
index 56a3fdf..35422a8 100644
--- a/proclist.c
+++ b/proclist.c
@@ -62,24 +62,15 @@ proclist_lookup (void *hook, const char *name, struct node **np)
return process_lookup_pid (pc, pid, np);
}
-error_t
-proclist_create_node (process_t procserv, struct node **np)
+struct node *
+proclist_make_node (struct ps_context *pc)
{
static const struct procfs_node_ops ops = {
.get_contents = proclist_get_contents,
.lookup = proclist_lookup,
.cleanup_contents = procfs_cleanup_contents_with_free,
- .cleanup = (void (*)(void *)) ps_context_free,
.enable_refresh_hack_and_break_readdir = 1,
};
- struct ps_context *pc;
- error_t err;
-
- err = ps_context_create (procserv, &pc);
- if (err)
- return err;
-
- *np = procfs_make_node (&ops, pc);
- return 0;
+ return procfs_make_node (&ops, pc);
}
diff --git a/proclist.h b/proclist.h
index 1c7ab08..ce69dde 100644
--- a/proclist.h
+++ b/proclist.h
@@ -1,2 +1,4 @@
-#include <hurd/hurd_types.h>
-error_t proclist_create_node (process_t procserv, struct node **np);
+#include <ps.h>
+
+struct node *
+proclist_make_node (struct ps_context *pc);
diff --git a/rootdir.c b/rootdir.c
index 865342c..8062f0d 100644
--- a/rootdir.c
+++ b/rootdir.c
@@ -357,22 +357,15 @@ static const struct procfs_dir_entry rootdir_entries[] = {
{}
};
-error_t
-rootdir_create_node (struct node **np)
+struct node
+*rootdir_make_node (struct ps_context *pc)
{
- struct ps_context *pc;
const struct procfs_dir_entry *entries;
- error_t err;
-
- err = ps_context_create (getproc (), &pc);
- if (err)
- return err;
entries = rootdir_entries;
if (opt_fake_self < 0)
entries++;
- *np = procfs_dir_make_node (entries, pc, (void (*)(void *)) ps_context_free);
- return 0;
+ return procfs_dir_make_node (entries, pc, NULL);
}
diff --git a/rootdir.h b/rootdir.h
index a764b0f..0caee25 100644
--- a/rootdir.h
+++ b/rootdir.h
@@ -1,2 +1,4 @@
-error_t
-rootdir_create_node (struct node **np);
+#include <ps.h>
+
+struct node *
+rootdir_make_node (struct ps_context *pc);