From 4665f087fde174a9de3e1c3f3de090dd4bfa85e0 Mon Sep 17 00:00:00 2001 From: Jeremie Koenig Date: Sun, 22 Aug 2010 21:23:36 +0000 Subject: Add a fake-self option to control the self symlink * main.c (argp_parse, main): Add the --fake-self option. * main.h: Publish it. * rootdir.c (rootdir_gc_fakeself, rootdir_entries, rootdir_create_node): Use it. --- rootdir.c | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'rootdir.c') diff --git a/rootdir.c b/rootdir.c index 1d9c083..833fc15 100644 --- a/rootdir.c +++ b/rootdir.c @@ -156,9 +156,8 @@ rootdir_gc_empty (void *hook, void **contents, size_t *contents_len) static error_t rootdir_gc_fakeself (void *hook, void **contents, size_t *contents_len) { - *contents = "1"; - *contents_len = strlen (*contents); - return 0; + *contents_len = asprintf ((char **) contents, "%d", opt_fake_self); + return *contents_len >= 0 ? 0 : ENOMEM; } @@ -177,7 +176,15 @@ rootdir_symlink_make_node (void *dir_hook, void *entry_hook) return np; } -static struct procfs_dir_entry rootdir_entries[] = { +static const struct procfs_dir_entry rootdir_entries[] = { + { + .name = "self", + .make_node = rootdir_symlink_make_node, + .hook = & (struct procfs_node_ops) { + .get_contents = rootdir_gc_fakeself, + .cleanup_contents = procfs_cleanup_contents_with_free, + }, + }, { .name = "version", .make_node = rootdir_file_make_node, @@ -217,13 +224,6 @@ static struct procfs_dir_entry rootdir_entries[] = { .get_contents = rootdir_gc_empty, }, }, - { - .name = "self", - .make_node = rootdir_symlink_make_node, - .hook = & (struct procfs_node_ops) { - .get_contents = rootdir_gc_fakeself, - }, - }, {} }; @@ -231,14 +231,18 @@ error_t rootdir_create_node (struct node **np) { struct ps_context *pc; + const struct procfs_dir_entry *entries; error_t err; err = ps_context_create (getproc (), &pc); if (err) return err; - *np = procfs_dir_make_node (rootdir_entries, pc, - (void (*)(void *)) ps_context_free); + entries = rootdir_entries; + if (opt_fake_self < 0) + entries++; + + *np = procfs_dir_make_node (entries, pc, (void (*)(void *)) ps_context_free); return 0; } -- cgit v1.2.3