summaryrefslogtreecommitdiff
path: root/usr.bin/systat/engine.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2021-07-02 15:34:17 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2021-07-02 15:34:17 +0000
commit4ce8bdc78901cb2369b086b27ec7b056960c2016 (patch)
tree8a24020694bcfbeeafce9802d8c52fd68895d656 /usr.bin/systat/engine.c
parent7b7ab9b132699bf3b82cbf78e0e210a14aec4aaa (diff)
Use nanosleep() and setitimer() instead of usleep() and ualarm().
Both usleep() and ualarm() are obsolete and were removed from POSIX. OK deraadt@
Diffstat (limited to 'usr.bin/systat/engine.c')
-rw-r--r--usr.bin/systat/engine.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/usr.bin/systat/engine.c b/usr.bin/systat/engine.c
index 068174a74cc..84d3146534d 100644
--- a/usr.bin/systat/engine.c
+++ b/usr.bin/systat/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.28 2021/06/02 08:32:22 martijn Exp $ */
+/* $OpenBSD: engine.c,v 1.29 2021/07/02 15:34:16 millert Exp $ */
/*
* Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org>
*
@@ -27,6 +27,7 @@
#include <string.h>
#include <term.h>
#include <unistd.h>
+#include <math.h>
#include <err.h>
/* XXX These are defined in term.h and conflict with our variable names */
@@ -50,7 +51,9 @@ struct view_ent {
TAILQ_ENTRY(view_ent) entries;
};
-useconds_t udelay = 5000000;
+static struct timespec ts_delay = { 5, 0 };
+static struct itimerval it_delay = { { 0, 0 }, { 5, 0 } };
+
int dispstart = 0;
int humanreadable = 0;
int interactive = 1;
@@ -1355,7 +1358,7 @@ engine_loop(int countmax)
read_view();
need_sort = 1;
gotsig_alarm = 0;
- ualarm(udelay, 0);
+ setitimer(ITIMER_REAL, &it_delay, NULL);
}
if (need_sort) {
@@ -1366,7 +1369,7 @@ engine_loop(int countmax)
/* XXX if sort took too long */
if (gotsig_alarm) {
gotsig_alarm = 0;
- ualarm(udelay, 0);
+ setitimer(ITIMER_REAL, &it_delay, NULL);
}
}
@@ -1408,7 +1411,7 @@ engine_loop(int countmax)
if (interactive && need_update == 0)
keyboard();
else if (interactive == 0)
- usleep(udelay);
+ nanosleep(&ts_delay, NULL);
}
if (rawmode == 0)
@@ -1457,3 +1460,16 @@ check_termcap(void)
return(0);
}
+
+void
+refresh_delay(double delay)
+{
+ double secs, frac;
+
+ frac = modf(delay, &secs);
+ ts_delay.tv_sec = secs;
+ ts_delay.tv_nsec = frac * 1000000000.0;
+ if (!timespecisset(&ts_delay))
+ ts_delay.tv_nsec = 1000000000;
+ TIMESPEC_TO_TIMEVAL(&it_delay.it_value, &ts_delay);
+}