summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Koenig <jk@jk.fr.eu.org>2010-08-22 20:46:54 +0000
committerJeremie Koenig <jk@jk.fr.eu.org>2010-08-30 14:29:51 +0200
commit5714e1cef2584410a7823c7ead9d2435141fb0c4 (patch)
tree49579f8c7a427ca770f3a4b99df081c9233f58f6
parentb3427143ae8dc628cb3748da7618700c6bd7ac9e (diff)
Add --stat-mode to override the perms for [pid]/stat
* main.c (argp_parser, main): Add the --stat-mode option. * process.c (process_lookup_pid): Use it.
-rw-r--r--main.c14
-rw-r--r--main.h1
-rw-r--r--process.c5
3 files changed, 20 insertions, 0 deletions
diff --git a/main.c b/main.c
index a59ab47..09cffc7 100644
--- a/main.c
+++ b/main.c
@@ -12,6 +12,7 @@
/* Command-line options */
int opt_clk_tck;
+mode_t opt_stat_mode;
static error_t
argp_parser (int key, char *arg, struct argp_state *state)
@@ -25,6 +26,12 @@ argp_parser (int key, char *arg, struct argp_state *state)
if (*endp || ! *arg || opt_clk_tck <= 0)
error (1, 0, "--clk-tck: HZ should be a positive integer");
break;
+
+ case 's':
+ opt_stat_mode = strtol (arg, &endp, 8);
+ if (*endp || ! *arg || opt_stat_mode & ~07777)
+ error (1, 0, "--stat-mode: MODE should be an octal mode");
+ break;
}
return 0;
@@ -35,6 +42,12 @@ struct argp argp = {
{ "clk-tck", 'h', "HZ", 0,
"Unit used for the values expressed in system clock ticks "
"(default: sysconf(_SC_CLK_TCK))" },
+ { "stat-mode", 's', "MODE", 0,
+ "The [pid]/stat file publishes information which on Hurd is only "
+ "available to the process owner. "
+ "You can use this option to override its mode to be more permissive "
+ "for compatibility purposes. "
+ "(default: 0400)" },
{}
},
.parser = argp_parser,
@@ -81,6 +94,7 @@ int main (int argc, char **argv)
mach_port_t bootstrap;
opt_clk_tck = sysconf(_SC_CLK_TCK);
+ opt_stat_mode = 0400;
argp_parse (&argp, argc, argv, 0, 0, 0);
task_get_bootstrap_port (mach_task_self (), &bootstrap);
diff --git a/main.h b/main.h
index 4b2ef9a..6669d32 100644
--- a/main.h
+++ b/main.h
@@ -1,2 +1,3 @@
/* Startup options */
extern int opt_clk_tck;
+extern mode_t opt_stat_mode;
diff --git a/process.c b/process.c
index 65f0e50..f7a7a57 100644
--- a/process.c
+++ b/process.c
@@ -206,6 +206,7 @@ static struct procfs_dir_entry entries[] = {
},
},
{
+ /* Beware of the hack below, which requires this to be entries[2]. */
.name = "stat",
.make_node = process_file_make_node,
.hook = & (struct process_file_desc) {
@@ -235,6 +236,10 @@ process_lookup_pid (struct ps_context *pc, pid_t pid, struct node **np)
if (err || ! (proc_stat_flags (ps) & PSTAT_OWNER_UID))
return EIO;
+ /* FIXME: have a separate proc_desc structure for each file, so this can be
+ accessed in a more robust and straightforward way. */
+ ((struct process_file_desc *) entries[2].hook)->mode = opt_stat_mode;
+
*np = procfs_dir_make_node (entries, ps, (void (*)(void *)) _proc_stat_free);
if (! *np)
return ENOMEM;