diff options
author | anton <anton@cvs.openbsd.org> | 2017-07-22 09:37:22 +0000 |
---|---|---|
committer | anton <anton@cvs.openbsd.org> | 2017-07-22 09:37:22 +0000 |
commit | bd2709dd1500f77d1f9d41d0c8cdd51781768680 (patch) | |
tree | cd0e0724ca87b6bf1004cd7d6679d3e2420f9c02 /bin/csh | |
parent | 8a5d19608c201eda68d49d1d5a117be465dc2a33 (diff) |
Use monotonic clock for the time command in csh and ksh.
From Scott Cheloha
ok tb@
Diffstat (limited to 'bin/csh')
-rw-r--r-- | bin/csh/csh.h | 4 | ||||
-rw-r--r-- | bin/csh/extern.h | 4 | ||||
-rw-r--r-- | bin/csh/proc.c | 14 | ||||
-rw-r--r-- | bin/csh/proc.h | 6 | ||||
-rw-r--r-- | bin/csh/time.c | 14 |
5 files changed, 21 insertions, 21 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"; |