--- a/uptime.c Sat Nov 13 17:51:20 2010 +0100
+++ b/uptime.c Sun Nov 14 11:02:15 2010 +0100
@@ -99,27 +99,13 @@
void do_uptime (char *arg)
{
GString *line = g_string_new (NULL);
- guint seconds;
- guint minutes;
- guint hours;
- guint days;
- time_t now = time (NULL);
+ gchar strstartdate[256];
- if (proc_used && settings_opt_get_int ("uptime_use_proc")) {
- int sysup = sys_uptime();
- if (!sysup) {
- g_string_free (line, TRUE);
- scr_log_print (LPRINT_NORMAL, "Uptime not available :-(");
- return;
- }
- seconds = (sysup - mstime) / hz;
- } else {
- seconds = now - starttime;
- }
+ guint seconds = time (NULL) - starttime;
+ guint minutes = seconds / 60;
+ guint hours = minutes / 60;
+ guint days = hours / 24;
- minutes = seconds / 60;
- hours = minutes / 60;
- days = hours / 24;
seconds %= 60;
minutes %= 60;
hours %= 24;
@@ -133,7 +119,13 @@
if (seconds)
g_string_append_printf (line, " %u seconds", seconds);
- scr_log_print (LPRINT_NORMAL, "Uptime: %s.", line -> len ? line -> str : " 0 seconds");
+ // Running since:
+ strftime(strstartdate, sizeof(strstartdate),
+ "%Y-%m-%d %H:%M", localtime(&starttime));
+
+ scr_log_print (LPRINT_NORMAL, "Uptime: %s.\n(Running since %s)",
+ line -> len ? line -> str : " 0 second",
+ strstartdate);
g_string_free (line, TRUE);
}
@@ -222,8 +214,12 @@
g_string_free (line, TRUE);
hz = sysconf(_SC_CLK_TCK);
- if (hz && mstime)
+ if (hz && mstime) {
+ int sysup = sys_uptime();
+ if (sysup) // Let's calculate starttime more precisely:
+ starttime = time (NULL) - (sysup - mstime) / hz;
proc_used = TRUE;
+ }
}
cmd_add ("uptime", "", 0, 0, do_uptime, NULL);