summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/csh/csh.h4
-rw-r--r--bin/csh/extern.h4
-rw-r--r--bin/csh/proc.c14
-rw-r--r--bin/csh/proc.h6
-rw-r--r--bin/csh/time.c14
-rw-r--r--bin/ksh/c_sh.c52
6 files changed, 56 insertions, 38 deletions
diff --git a/bin/csh/csh.h b/bin/csh/csh.h
index e34a04a6f09..601b7bb9772 100644
--- a/bin/csh/csh.h
+++ b/bin/csh/csh.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: csh.h,v 1.28 2015/12/26 13:48:38 mestre Exp $ */
+/* $OpenBSD: csh.h,v 1.29 2017/07/22 09:37:21 anton Exp $ */
/* $NetBSD: csh.h,v 1.9 1995/03/21 09:02:40 cgd Exp $ */
/*-
@@ -122,7 +122,7 @@ char *seterr; /* Error message from scanner/parser */
#include <sys/time.h>
#include <sys/resource.h>
-struct timeval time0; /* Time at which the shell started */
+struct timespec time0; /* Time at which the shell started */
struct rusage ru0;
/*
diff --git a/bin/csh/extern.h b/bin/csh/extern.h
index f6c64817ff6..aba5f06ca06 100644
--- a/bin/csh/extern.h
+++ b/bin/csh/extern.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: extern.h,v 1.25 2015/12/26 13:48:38 mestre Exp $ */
+/* $OpenBSD: extern.h,v 1.26 2017/07/22 09:37:21 anton Exp $ */
/* $NetBSD: extern.h,v 1.8 1996/10/31 23:50:54 christos Exp $ */
/*-
@@ -272,7 +272,7 @@ void plist(struct varent *);
void donice(Char **, struct command *);
void dotime(Char **, struct command *);
void prusage(struct rusage *, struct rusage *,
- struct timeval *, struct timeval *);
+ struct timespec *, struct timespec *);
void ruadd(struct rusage *, struct rusage *);
void settimes(void);
void pcsecs(long);
diff --git a/bin/csh/proc.c b/bin/csh/proc.c
index 7759edce234..3accda9ff7c 100644
--- a/bin/csh/proc.c
+++ b/bin/csh/proc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.c,v 1.30 2015/12/26 13:48:38 mestre Exp $ */
+/* $OpenBSD: proc.c,v 1.31 2017/07/22 09:37:21 anton Exp $ */
/* $NetBSD: proc.c,v 1.9 1995/04/29 23:21:33 mycroft Exp $ */
/*-
@@ -108,7 +108,7 @@ found:
}
else {
if (pp->p_flags & (PTIME | PPTIME) || adrof(STRtime))
- (void) gettimeofday(&pp->p_etime, NULL);
+ (void) clock_gettime(CLOCK_MONOTONIC, &pp->p_etime);
pp->p_rusage = ru;
if (WIFSIGNALED(w)) {
@@ -494,7 +494,7 @@ palloc(int pid, struct command *t)
}
pp->p_next = proclist.p_next;
proclist.p_next = pp;
- (void) gettimeofday(&pp->p_btime, NULL);
+ (void) clock_gettime(CLOCK_MONOTONIC, &pp->p_btime);
}
static void
@@ -799,8 +799,8 @@ prcomd:
static void
ptprint(struct process *tp)
{
- struct timeval tetime, diff;
- static struct timeval ztime;
+ struct timespec tetime, diff;
+ static struct timespec ztime;
struct rusage ru;
static struct rusage zru;
struct process *pp = tp;
@@ -809,8 +809,8 @@ ptprint(struct process *tp)
tetime = ztime;
do {
ruadd(&ru, &pp->p_rusage);
- timersub(&pp->p_etime, &pp->p_btime, &diff);
- if (timercmp(&diff, &tetime, >))
+ timespecsub(&pp->p_etime, &pp->p_btime, &diff);
+ if (timespeccmp(&diff, &tetime, >))
tetime = diff;
} while ((pp = pp->p_friends) != tp);
prusage(&zru, &ru, &tetime, &ztime);
diff --git a/bin/csh/proc.h b/bin/csh/proc.h
index 511a3c73bc4..705cceae83c 100644
--- a/bin/csh/proc.h
+++ b/bin/csh/proc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: proc.h,v 1.3 2003/06/02 23:32:07 millert Exp $ */
+/* $OpenBSD: proc.h,v 1.4 2017/07/22 09:37:21 anton Exp $ */
/* $NetBSD: proc.h,v 1.7 1995/04/29 23:21:35 mycroft Exp $ */
/*-
@@ -50,8 +50,8 @@ struct process {
pid_t p_pid;
pid_t p_jobid; /* pid of job leader */
/* if a job is stopped/background p_jobid gives its pgrp */
- struct timeval p_btime; /* begin time */
- struct timeval p_etime; /* end time */
+ struct timespec p_btime; /* begin time */
+ struct timespec p_etime; /* end time */
struct rusage p_rusage;
Char *p_command; /* first PMAXLEN chars of command */
};
diff --git a/bin/csh/time.c b/bin/csh/time.c
index cfa3b4adfaa..bf16de91096 100644
--- a/bin/csh/time.c
+++ b/bin/csh/time.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: time.c,v 1.14 2013/08/22 04:43:40 guenther Exp $ */
+/* $OpenBSD: time.c,v 1.15 2017/07/22 09:37:21 anton Exp $ */
/* $NetBSD: time.c,v 1.7 1995/03/21 13:55:25 mycroft Exp $ */
/*-
@@ -46,7 +46,7 @@ settimes(void)
{
struct rusage ruch;
- (void) gettimeofday(&time0, NULL);
+ (void) clock_gettime(CLOCK_MONOTONIC, &time0);
(void) getrusage(RUSAGE_SELF, &ru0);
(void) getrusage(RUSAGE_CHILDREN, &ruch);
ruadd(&ru0, &ruch);
@@ -60,13 +60,13 @@ void
/*ARGSUSED*/
dotime(Char **v, struct command *t)
{
- struct timeval timedol;
+ struct timespec timedol;
struct rusage ru1, ruch;
(void) getrusage(RUSAGE_SELF, &ru1);
(void) getrusage(RUSAGE_CHILDREN, &ruch);
ruadd(&ru1, &ruch);
- (void) gettimeofday(&timedol, NULL);
+ (void) clock_gettime(CLOCK_MONOTONIC, &timedol);
prusage(&ru0, &ru1, &timedol, &time0);
}
@@ -112,8 +112,8 @@ ruadd(struct rusage *ru, struct rusage *ru2)
}
void
-prusage(struct rusage *r0, struct rusage *r1, struct timeval *e,
- struct timeval *b)
+prusage(struct rusage *r0, struct rusage *r1, struct timespec *e,
+ struct timespec *b)
{
time_t t =
(r1->ru_utime.tv_sec - r0->ru_utime.tv_sec) * 100 +
@@ -125,7 +125,7 @@ prusage(struct rusage *r0, struct rusage *r1, struct timeval *e,
struct varent *vp = adrof(STRtime);
int ms =
- (e->tv_sec - b->tv_sec) * 100 + (e->tv_usec - b->tv_usec) / 10000;
+ (e->tv_sec - b->tv_sec) * 100 + (e->tv_nsec - b->tv_nsec) / 10000000;
cp = "%Uu %Ss %E %P %X+%Dk %I+%Oio %Fpf+%Ww";
diff --git a/bin/ksh/c_sh.c b/bin/ksh/c_sh.c
index 4e40c464ecb..6c54839cdcc 100644
--- a/bin/ksh/c_sh.c
+++ b/bin/ksh/c_sh.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: c_sh.c,v 1.59 2016/03/04 15:11:06 deraadt Exp $ */
+/* $OpenBSD: c_sh.c,v 1.60 2017/07/22 09:37:21 anton Exp $ */
/*
* built-in Bourne commands
@@ -18,7 +18,8 @@
#include "sh.h"
-static void p_time(struct shf *, int, struct timeval *, int, char *, char *);
+static void p_tv(struct shf *, int, struct timeval *, int, char *, char *);
+static void p_ts(struct shf *, int, struct timespec *, int, char *, char *);
/* :, false and true */
int
@@ -670,7 +671,7 @@ c_unset(char **wp)
}
static void
-p_time(struct shf *shf, int posix, struct timeval *tv, int width, char *prefix,
+p_tv(struct shf *shf, int posix, struct timeval *tv, int width, char *prefix,
char *suffix)
{
if (posix)
@@ -683,18 +684,34 @@ p_time(struct shf *shf, int posix, struct timeval *tv, int width, char *prefix,
tv->tv_usec / 10000, suffix);
}
+static void
+p_ts(struct shf *shf, int posix, struct timespec *ts, int width, char *prefix,
+ char *suffix)
+{
+ if (posix)
+ shf_fprintf(shf, "%s%*lld.%02ld%s", prefix ? prefix : "",
+ width, (long long)ts->tv_sec, ts->tv_nsec / 10000000,
+ suffix);
+ else
+ shf_fprintf(shf, "%s%*lldm%02lld.%02lds%s", prefix ? prefix : "",
+ width, (long long)ts->tv_sec / 60,
+ (long long)ts->tv_sec % 60,
+ ts->tv_nsec / 10000000, suffix);
+}
+
+
int
c_times(char **wp)
{
struct rusage usage;
(void) getrusage(RUSAGE_SELF, &usage);
- p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " ");
- p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n");
+ p_tv(shl_stdout, 0, &usage.ru_utime, 0, NULL, " ");
+ p_tv(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n");
(void) getrusage(RUSAGE_CHILDREN, &usage);
- p_time(shl_stdout, 0, &usage.ru_utime, 0, NULL, " ");
- p_time(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n");
+ p_tv(shl_stdout, 0, &usage.ru_utime, 0, NULL, " ");
+ p_tv(shl_stdout, 0, &usage.ru_stime, 0, NULL, "\n");
return 0;
}
@@ -710,11 +727,12 @@ timex(struct op *t, int f, volatile int *xerrok)
#define TF_POSIX BIT(2) /* report in posix format */
int rv = 0;
struct rusage ru0, ru1, cru0, cru1;
- struct timeval usrtime, systime, tv0, tv1;
+ struct timeval usrtime, systime;
+ struct timespec ts0, ts1, ts2;
int tf = 0;
extern struct timeval j_usrtime, j_systime; /* computed by j_wait */
- gettimeofday(&tv0, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &ts0);
getrusage(RUSAGE_SELF, &ru0);
getrusage(RUSAGE_CHILDREN, &cru0);
if (t->left) {
@@ -731,7 +749,7 @@ timex(struct op *t, int f, volatile int *xerrok)
rv = execute(t->left, f | XTIME, xerrok);
if (t->left->type == TCOM)
tf |= t->left->str[0];
- gettimeofday(&tv1, NULL);
+ clock_gettime(CLOCK_MONOTONIC, &ts1);
getrusage(RUSAGE_SELF, &ru1);
getrusage(RUSAGE_CHILDREN, &cru1);
} else
@@ -749,20 +767,20 @@ timex(struct op *t, int f, volatile int *xerrok)
}
if (!(tf & TF_NOREAL)) {
- timersub(&tv1, &tv0, &tv1);
+ timespecsub(&ts1, &ts0, &ts2);
if (tf & TF_POSIX)
- p_time(shl_out, 1, &tv1, 5, "real ", "\n");
+ p_ts(shl_out, 1, &ts2, 5, "real ", "\n");
else
- p_time(shl_out, 0, &tv1, 5, NULL, " real ");
+ p_ts(shl_out, 0, &ts2, 5, NULL, " real ");
}
if (tf & TF_POSIX)
- p_time(shl_out, 1, &usrtime, 5, "user ", "\n");
+ p_tv(shl_out, 1, &usrtime, 5, "user ", "\n");
else
- p_time(shl_out, 0, &usrtime, 5, NULL, " user ");
+ p_tv(shl_out, 0, &usrtime, 5, NULL, " user ");
if (tf & TF_POSIX)
- p_time(shl_out, 1, &systime, 5, "sys ", "\n");
+ p_tv(shl_out, 1, &systime, 5, "sys ", "\n");
else
- p_time(shl_out, 0, &systime, 5, NULL, " system\n");
+ p_tv(shl_out, 0, &systime, 5, NULL, " system\n");
shf_flush(shl_out);
return rv;