summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-08-23 11:54:10 +0000
committerJeremie Koenig <jk@jk.fr.eu.org>2010-08-30 14:31:31 +0200
commit4646c4a3ef6171a0ddec4fcfe0c6aa34b50501cd (patch)
tree6b84772adf6f4c45c852dfc051b94995864caa86 /main.c
parent6e202c432e2f16dfa83a7dc21b759c03623fa394 (diff)
Improve the interface for dircat_make_node
* dircat.c, dircat.h (dircat_make_node): Use an explicit array size for DIRS, fail with ENOMEM is any of them is NULL, and release the reference on the non-NULL nodes on any error. * main.c (root_make_node): Use the new interface.
Diffstat (limited to 'main.c')
-rw-r--r--main.c27
1 files changed, 6 insertions, 21 deletions
diff --git a/main.c b/main.c
index 06c1da0..eaab986 100644
--- a/main.c
+++ b/main.c
@@ -118,35 +118,20 @@ struct argp argp = {
error_t
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];
+ struct node *root_dirs[] = {
+ proclist_make_node (pc),
+ rootdir_make_node (pc),
+ };
- root_dirs[0] = proclist_make_node (pc);
- if (! root_dirs[0])
- goto nomem;
-
- root_dirs[1] = rootdir_make_node (pc);
- if (! root_dirs[1])
- goto nomem;
-
- root_dirs[2] = NULL;
- *np = dircat_make_node (root_dirs);
+ *np = dircat_make_node (root_dirs, sizeof root_dirs / sizeof root_dirs[0]);
if (! *np)
- goto nomem;
+ return ENOMEM;
/* 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)