Codebase list openbsd-inetd / f56ac36
Use a monotonic clock instead of gettimeofday(3) Marco d'Itri 7 years ago
2 changed file(s) with 31 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 Use a monotonic clock instead of gettimeofday(3).
1
2 Inspired by https://svnweb.freebsd.org/base/head/usr.sbin/inetd/inetd.c?r1=229403&r2=236572 .
3
4 --- a/inetd.c
5 +++ b/inetd.c
6 @@ -228,7 +228,7 @@ struct servtab {
7 int se_ctrladdr_size;
8 int se_max; /* max # of instances of this service */
9 int se_count; /* number started since se_time */
10 - struct timeval se_time; /* start of se_count */
11 + struct timespec se_time; /* start of se_count */
12 struct servtab *se_next;
13 struct event se_event;
14 } *servtab;
15 @@ -1873,11 +1873,11 @@ spawn(int ctrl, short events, void *xsep
16 dofork = (sep->se_bi == 0 || sep->se_bi->bi_fork);
17 if (dofork) {
18 if (sep->se_count++ == 0)
19 - (void)gettimeofday(&sep->se_time, NULL);
20 + (void)clock_gettime(CLOCK_BOOTTIME, &sep->se_time);
21 else if (sep->se_count >= sep->se_max) {
22 - struct timeval now;
23 + struct timespec now;
24
25 - (void)gettimeofday(&now, NULL);
26 + (void)clock_gettime(CLOCK_BOOTTIME, &now);
27 if (now.tv_sec - sep->se_time.tv_sec >
28 CNT_INTVL) {
29 sep->se_time = now;
1111 print_pause_time
1212 tcp46
1313 buftuning
14 monotonic_clock