The following fixes uptime in coreutils to *drum roll* show the uptime! *applause*. Have fun with it. And now to more important things...
Were do we dump functions that we would like external programs (things that are not in the Hurd project) to use? Like fetch_boot_time() for example. If for example this hack would get in coreutils, then we would have this ugly code duplication all over the place. I might note that fetch_boot_time() is a bad example, since it should be in coreutils, and `w' should die as to let `who' live, ditto for our hacked `uptime' script that uses `w'. --- Makefile.am.~1.33.~ 2004-03-12 22:35:37.000000000 -0800 +++ Makefile.am 2004-03-14 05:41:22.000000000 -0800 @@ -61,7 +61,7 @@ nanosec_libs = \ sleep_LDADD = $(nanosec_libs) tail_LDADD = $(nanosec_libs) -uptime_LDADD = $(LDADD) $(GETLOADAVG_LIBS) +uptime_LDADD = $(LDADD) $(GETLOADAVG_LIBS) -lps su_LDADD = $(LDADD) $(LIB_CRYPT) --- uptime.c.~1.40.~ 2004-03-07 08:04:03.000000000 -0800 +++ uptime.c 2004-03-14 05:22:42.000000000 -0800 @@ -47,6 +47,47 @@ static struct option const longopts[] = {NULL, 0, NULL, 0} }; +#include <hurd.h> +#include <ps.h> + +/* Find the absolute timestamp of when the system was booted. We + define "system boot time" as the task creation time of PID 1 + (init). */ +static error_t +fetch_boot_time (struct timeval *when) +{ + struct ps_context *context; + struct proc_stat *ps; + error_t err; + + err = ps_context_create (getproc (), &context); + if (err) + error (2, err, "ps_context_create"); + + err = ps_context_find_proc_stat (context, 1, &ps); + if (err) + error (3, err, "ps_context_find_proc_stat"); + + err = proc_stat_set_flags (ps, PSTAT_TASK_BASIC); + if (!err && !(ps->flags & PSTAT_TASK_BASIC)) + err = EGRATUITOUS; + if (err) + { + error (0, err, "cannot find boot time"); + return err; + } + else + { + time_value_t *const tv = &proc_stat_task_basic_info (ps)->creation_time; + when->tv_sec = tv->seconds; + when->tv_usec = tv->microseconds; + } + + ps_context_free (context); + + return 0; +} + static void print_uptime (int n, const STRUCT_UTMP *this) { @@ -96,6 +137,14 @@ print_uptime (int n, const STRUCT_UTMP * } #endif + { + struct timeval result; + if (fetch_boot_time (&result)) + boot_time = 0; + else + boot_time = result.tv_sec; + } + /* Loop through all the utmp entries we just read and count up the valid ones, also in the process possibly gleaning boottime. */ while (n--) _______________________________________________ Bug-hurd mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-hurd