diff options
author | Darren Tucker <dtucker@cvs.openbsd.org> | 2016-03-02 22:42:41 +0000 |
---|---|---|
committer | Darren Tucker <dtucker@cvs.openbsd.org> | 2016-03-02 22:42:41 +0000 |
commit | a83db834aef595238f0ccad3ba165434dff5d046 (patch) | |
tree | 10c0f0f758fc0066d37a0b038b6f571e664023b4 /usr.bin | |
parent | 5a1e53b879b499a918b746f75529b99621c83117 (diff) |
Improve precision of progressmeter for sftp and scp by storing sub-second
timestamps. Pointed out by mmcc@, ok deraadt@ markus@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/ssh/misc.c | 13 | ||||
-rw-r--r-- | usr.bin/ssh/misc.h | 3 | ||||
-rw-r--r-- | usr.bin/ssh/progressmeter.c | 13 |
3 files changed, 20 insertions, 9 deletions
diff --git a/usr.bin/ssh/misc.c b/usr.bin/ssh/misc.c index e81d2a161f4..f1c0a973540 100644 --- a/usr.bin/ssh/misc.c +++ b/usr.bin/ssh/misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.c,v 1.101 2016/01/20 09:22:39 dtucker Exp $ */ +/* $OpenBSD: misc.c,v 1.102 2016/03/02 22:42:40 dtucker Exp $ */ /* * Copyright (c) 2000 Markus Friedl. All rights reserved. * Copyright (c) 2005,2006 Damien Miller. All rights reserved. @@ -871,6 +871,17 @@ monotime(void) return (ts.tv_sec); } +double +monotime_double(void) +{ + struct timespec ts; + + if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) + fatal("clock_gettime: %s", strerror(errno)); + + return (ts.tv_sec + (double)ts.tv_nsec / 1000000000); +} + void bandwidth_limit_init(struct bwlimit *bw, u_int64_t kbps, size_t buflen) { diff --git a/usr.bin/ssh/misc.h b/usr.bin/ssh/misc.h index 53d469bc4ea..1b81be82e50 100644 --- a/usr.bin/ssh/misc.h +++ b/usr.bin/ssh/misc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: misc.h,v 1.54 2014/07/15 15:54:14 millert Exp $ */ +/* $OpenBSD: misc.h,v 1.55 2016/03/02 22:42:40 dtucker Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> @@ -55,6 +55,7 @@ void sanitise_stdfd(void); void ms_subtract_diff(struct timeval *, int *); void ms_to_timeval(struct timeval *, int); time_t monotime(void); +double monotime_double(void); void lowercase(char *s); int unix_listener(const char *, int, int); diff --git a/usr.bin/ssh/progressmeter.c b/usr.bin/ssh/progressmeter.c index 5aeaee647ed..320edff4930 100644 --- a/usr.bin/ssh/progressmeter.c +++ b/usr.bin/ssh/progressmeter.c @@ -1,4 +1,4 @@ -/* $OpenBSD: progressmeter.c,v 1.41 2015/01/14 13:54:13 djm Exp $ */ +/* $OpenBSD: progressmeter.c,v 1.42 2016/03/02 22:42:40 dtucker Exp $ */ /* * Copyright (c) 2003 Nils Nordman. All rights reserved. * @@ -61,8 +61,8 @@ void refresh_progress_meter(void); /* signal handler for updating the progress meter */ static void update_progress_meter(int); -static time_t start; /* start progress */ -static time_t last_update; /* last progress update */ +static double start; /* start progress */ +static double last_update; /* last progress update */ static const char *file; /* name of the file being transferred */ static off_t start_pos; /* initial position of transfer */ static off_t end_pos; /* ending position of transfer */ @@ -118,9 +118,8 @@ void refresh_progress_meter(void) { char buf[MAX_WINSIZE + 1]; - time_t now; off_t transferred; - double elapsed; + double elapsed, now; int percent; off_t bytes_left; int cur_speed; @@ -130,7 +129,7 @@ refresh_progress_meter(void) transferred = *counter - (cur_pos ? cur_pos : start_pos); cur_pos = *counter; - now = monotime(); + now = monotime_double(); bytes_left = end_pos - cur_pos; if (bytes_left > 0) @@ -248,7 +247,7 @@ update_progress_meter(int ignore) void start_progress_meter(const char *f, off_t filesize, off_t *ctr) { - start = last_update = monotime(); + start = last_update = monotime_double(); file = f; start_pos = *ctr; end_pos = filesize; |