summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.c40
-rw-r--r--main.h2
-rw-r--r--process.c3
-rw-r--r--rootdir.c3
4 files changed, 45 insertions, 3 deletions
diff --git a/main.c b/main.c
index 15ad60f4..a59ab47f 100644
--- a/main.c
+++ b/main.c
@@ -1,5 +1,6 @@
#include <mach.h>
#include <hurd.h>
+#include <unistd.h>
#include <error.h>
#include <argp.h>
#include <hurd/netfs.h>
@@ -7,6 +8,42 @@
#include "proclist.h"
#include "rootdir.h"
#include "dircat.h"
+#include "main.h"
+
+/* Command-line options */
+int opt_clk_tck;
+
+static error_t
+argp_parser (int key, char *arg, struct argp_state *state)
+{
+ char *endp;
+
+ switch (key)
+ {
+ case 'h':
+ opt_clk_tck = strtol (arg, &endp, 0);
+ if (*endp || ! *arg || opt_clk_tck <= 0)
+ error (1, 0, "--clk-tck: HZ should be a positive integer");
+ break;
+ }
+
+ return 0;
+}
+
+struct argp argp = {
+ .options = (struct argp_option []) {
+ { "clk-tck", 'h', "HZ", 0,
+ "Unit used for the values expressed in system clock ticks "
+ "(default: sysconf(_SC_CLK_TCK))" },
+ {}
+ },
+ .parser = argp_parser,
+ .doc = "A virtual filesystem emulating the Linux procfs.",
+ .children = (struct argp_child []) {
+ { &netfs_std_startup_argp, },
+ {}
+ },
+};
error_t
root_make_node (struct node **np)
@@ -43,7 +80,8 @@ int main (int argc, char **argv)
{
mach_port_t bootstrap;
- argp_parse (&netfs_std_startup_argp, argc, argv, 0, 0, 0);
+ opt_clk_tck = sysconf(_SC_CLK_TCK);
+ argp_parse (&argp, argc, argv, 0, 0, 0);
task_get_bootstrap_port (mach_task_self (), &bootstrap);
if (bootstrap == MACH_PORT_NULL)
diff --git a/main.h b/main.h
new file mode 100644
index 00000000..4b2ef9a1
--- /dev/null
+++ b/main.h
@@ -0,0 +1,2 @@
+/* Startup options */
+extern int opt_clk_tck;
diff --git a/process.c b/process.c
index 8955cf40..65f0e503 100644
--- a/process.c
+++ b/process.c
@@ -8,6 +8,7 @@
#include "procfs.h"
#include "procfs_dir.h"
#include "process.h"
+#include "main.h"
/* Implementations for the process_file_desc.get_contents callback. */
@@ -39,7 +40,7 @@ static char state_char (struct proc_stat *ps)
static long int sc_tv (time_value_t tv)
{
double usecs = ((double) tv.seconds) * 1000000 + tv.microseconds;
- return usecs * sysconf(_SC_CLK_TCK) / 1000000;
+ return usecs * opt_clk_tck / 1000000;
}
static long long int jiff_tv (time_value_t tv)
diff --git a/rootdir.c b/rootdir.c
index 50f6e071..1d9c083c 100644
--- a/rootdir.c
+++ b/rootdir.c
@@ -7,6 +7,7 @@
#include <ps.h>
#include "procfs.h"
#include "procfs_dir.h"
+#include "main.h"
/* This implements a directory node with the static files in /proc */
@@ -105,7 +106,7 @@ rootdir_gc_stat (void *hook, void **contents, size_t *contents_len)
return EIO;
timersub (&time, &boottime, &time);
- up_ticks = sysconf(_SC_CLK_TCK) * (time.tv_sec + time.tv_usec / 1000000.);
+ up_ticks = opt_clk_tck * (time.tv_sec + time.tv_usec / 1000000.);
*contents_len = asprintf ((char **) contents,
/* Does Mach keeps track of any of this? */