aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-08-31 21:45:52 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-08-31 21:45:52 +0000
commit7bc5360bba5ae057771200e2d5ae55c45f178c0d (patch)
tree0929ad64b228119c8f0bc7bda08fe5bb4c7f5907
parent05241802a7c7c4f85b69f34c5c13df88cdf9fb1e (diff)
downloadbusybox-w32-7bc5360bba5ae057771200e2d5ae55c45f178c0d.tar.gz
busybox-w32-7bc5360bba5ae057771200e2d5ae55c45f178c0d.tar.bz2
busybox-w32-7bc5360bba5ae057771200e2d5ae55c45f178c0d.zip
isrv: use monotonic_sec
runsv: do not use clock_gettime if !MONOTONIC_CLOCK
-rw-r--r--networking/isrv.c18
-rw-r--r--runit/runsv.c36
2 files changed, 30 insertions, 24 deletions
diff --git a/networking/isrv.c b/networking/isrv.c
index 1a41dd4fb..080c60fbd 100644
--- a/networking/isrv.c
+++ b/networking/isrv.c
@@ -21,20 +21,6 @@
21 21
22/* Helpers */ 22/* Helpers */
23 23
24/* Even if _POSIX_MONOTONIC_CLOCK is defined, this
25 * may require librt */
26#if 0 /*def _POSIX_MONOTONIC_CLOCK*/
27static time_t monotonic_time(void)
28{
29 struct timespec ts;
30 if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
31 time(&ts.tv_sec);
32 return ts.tv_sec;
33}
34#else
35#define monotonic_time() (time(NULL))
36#endif
37
38/* Opaque structure */ 24/* Opaque structure */
39 25
40struct isrv_state_t { 26struct isrv_state_t {
@@ -258,7 +244,7 @@ static void handle_fd_set(isrv_state_t *state, fd_set *fds, int (*h)(int, void *
258 /* this peer is gone */ 244 /* this peer is gone */
259 remove_peer(state, peer); 245 remove_peer(state, peer);
260 } else if (TIMEOUT) { 246 } else if (TIMEOUT) {
261 TIMEO_TBL[peer] = monotonic_time(); 247 TIMEO_TBL[peer] = monotonic_sec();
262 } 248 }
263 } 249 }
264} 250}
@@ -335,7 +321,7 @@ void isrv_run(
335 break; 321 break;
336 322
337 if (timeout) { 323 if (timeout) {
338 time_t t = monotonic_time(); 324 time_t t = monotonic_sec();
339 if (t != CURTIME) { 325 if (t != CURTIME) {
340 CURTIME = t; 326 CURTIME = t;
341 handle_timeout(state, do_timeout); 327 handle_timeout(state, do_timeout);
diff --git a/runit/runsv.c b/runit/runsv.c
index baef6e13f..b35c26630 100644
--- a/runit/runsv.c
+++ b/runit/runsv.c
@@ -33,6 +33,34 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33#include "libbb.h" 33#include "libbb.h"
34#include "runit_lib.h" 34#include "runit_lib.h"
35 35
36#if ENABLE_MONOTONIC_SYSCALL
37#include <sys/syscall.h>
38
39/* libc has incredibly messy way of doing this,
40 * typically requiring -lrt. We just skip all this mess */
41static void gettimeofday_ns(struct timespec *ts)
42{
43 syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
44}
45#else
46static void gettimeofday_ns(struct timespec *ts)
47{
48 if (sizeof(struct timeval) == sizeof(struct timespec)
49 && sizeof(((struct timeval*)ts)->tv_usec) == sizeof(ts->tv_nsec)
50 ) {
51 /* Cheat */
52 gettimeofday((void*)ts, NULL);
53 ts->tv_nsec *= 1000;
54 } else {
55 extern void BUG_need_to_implement_gettimeofday_ns(void);
56 BUG_need_to_implement_gettimeofday_ns();
57 }
58}
59#endif
60
61/* Compare possibly overflowing unsigned counters */
62#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
63
36static int selfpipe[2]; 64static int selfpipe[2];
37 65
38/* state */ 66/* state */
@@ -126,14 +154,6 @@ static int rename_or_warn(const char *old, const char *new)
126 return 0; 154 return 0;
127} 155}
128 156
129#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
130
131#include <sys/syscall.h>
132static void gettimeofday_ns(struct timespec *ts)
133{
134 syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
135}
136
137static void update_status(struct svdir *s) 157static void update_status(struct svdir *s)
138{ 158{
139 ssize_t sz; 159 ssize_t sz;