uptime display more in style with original code

This commit is contained in:
David E. O'Brien 1999-01-09 20:25:02 +00:00
parent 244cf84b1e
commit a2641311ff
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=42447
4 changed files with 56 additions and 43 deletions

View File

@ -30,8 +30,6 @@
#include <ctype.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include "screen.h" /* interface to screen package */
#include "layout.h" /* defines for screen position layout */
@ -243,51 +241,11 @@ double *avenrun;
}
}
struct timeval boottime;
time_t now;
time_t uptime;
i_timeofday(tod)
time_t *tod;
{
int days, hrs, i, mins, secs;
int mib[2];
size_t size;
(void)time(&now);
/*
* Print how long system has been up.
* (Found by looking getting "boottime" from the kernel)
*/
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
size = sizeof(boottime);
if (sysctl(mib, 2, &boottime, &size, NULL, 0) != -1 &&
boottime.tv_sec != 0) {
uptime = now - boottime.tv_sec;
uptime += 30;
days = uptime / 86400;
uptime %= 86400;
hrs = uptime / 3600;
uptime %= 3600;
mins = uptime / 60;
secs = uptime % 60;
if (smart_terminal)
{
Move_to((screen_width - 24) - (days > 9 ? 1 : 0), 0);
}
else
{
fputs(" ", stdout);
}
printf(" up %d+%02d:%02d:%02d", days, hrs, mins, secs);
}
/*
* Display the current time.
* "ctime" always returns a string that looks like this:
@ -1211,3 +1169,38 @@ char *str;
}
return(str);
}
i_uptime(bt, tod)
struct timeval* bt;
time_t *tod;
{
time_t uptime;
int days, hrs, mins, secs;
if (bt->tv_sec != -1) {
uptime = *tod - bt->tv_sec;
uptime += 30;
days = uptime / 86400;
uptime %= 86400;
hrs = uptime / 3600;
uptime %= 3600;
mins = uptime / 60;
secs = uptime % 60;
/*
* Display the uptime.
*/
if (smart_terminal)
{
Move_to((screen_width - 24) - (days > 9 ? 1 : 0), 0);
}
else
{
fputs(" ", stdout);
}
printf(" up %d+%02d:%02d:%02d", days, hrs, mins, secs);
}
}

View File

@ -32,6 +32,7 @@ struct system_info
int *cpustates;
int *memory;
int *swap;
struct timeval boottime;
};
/* cpu_states is an array of percentages * 10. For example,

View File

@ -549,6 +549,7 @@ Usage: %s [-ISbinqut] [-d x] [-s x] [-o field] [-U username] [number]\n",
/* display the current time */
/* this method of getting the time SHOULD be fairly portable */
time(&curr_time);
i_uptime(&system_info.boottime, &curr_time);
i_timeofday(&curr_time);
/* display process state breakdown */

View File

@ -19,10 +19,11 @@
* Steven Wallace <swallace@freebsd.org>
* Wolfram Schneider <wosch@FreeBSD.org>
*
* $Id: machine.c,v 1.16 1998/11/25 09:45:28 dfr Exp $
* $Id: machine.c,v 1.17 1998/11/26 12:59:21 bde Exp $
*/
#include <sys/time.h>
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/param.h>
@ -343,6 +344,9 @@ struct system_info *si;
{
long total;
load_avg avenrun[3];
int mib[2];
struct timeval boottime;
size_t bt_size;
/* get the cp_time array */
(void) getkval(cp_time_offset, (int *)cp_time, sizeof(cp_time),
@ -438,6 +442,20 @@ struct system_info *si;
} else {
si->last_pid = -1;
}
/*
* Print how long system has been up.
* (Found by looking getting "boottime" from the kernel)
*/
mib[0] = CTL_KERN;
mib[1] = KERN_BOOTTIME;
bt_size = sizeof(boottime);
if (sysctl(mib, 2, &boottime, &bt_size, NULL, 0) != -1 &&
boottime.tv_sec != 0) {
si->boottime = boottime;
} else {
si->boottime.tv_sec = -1;
}
}
static struct handle handle;