[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: undefined reference to _NR_clock_gettime
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2007-08-31 16:25:19
Message-ID: 200708311725.19772.vda.linux () googlemail ! com
[Download RAW message or body]

On Wednesday 29 August 2007 16:03, Jeff Seifer wrote:
> Hi all,
> 
> I just downloaded the 1.7.0 source, ran make defconfig and compiled from 
> my device (running debian on an arm9 board).
> Almost everything built without a hitch, but when it got to 
> runit/runsv.c I got an undeclared _NR_clock_gettime.
> 
> Just curious what "_NR_clock_gettime" is and where it's supposed to be 
> declared.  I tried chaning to plain old clock_gettime, but got a link 
> problem with that, so I reconfigured my build to leave out runsv and it 
> built everything else.
> 
> Just curious if anyone knows why I'm getting the undefined reference.

My fault, I was a bit lazy and hadrcoded clock_gettinm when I was removing
some unneeded time abstractions in runit/*

Try attached patch, does it makes you happy?
--
vda

["1.patch" (text/x-diff)]

diff -d -urpN busybox.0/networking/isrv.c busybox.1/networking/isrv.c
--- busybox.0/networking/isrv.c	2007-08-29 19:10:44.000000000 +0100
+++ busybox.1/networking/isrv.c	2007-08-31 17:05:46.715818000 +0100
@@ -21,20 +21,6 @@
 
 /* Helpers */
 
-/* Even if _POSIX_MONOTONIC_CLOCK is defined, this
- * may require librt */
-#if 0 /*def _POSIX_MONOTONIC_CLOCK*/
-static time_t monotonic_time(void)
-{
-	struct timespec ts;
-	if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
-		time(&ts.tv_sec);
-	return ts.tv_sec;
-}
-#else
-#define monotonic_time() (time(NULL))
-#endif
-
 /* Opaque structure */
 
 struct isrv_state_t {
@@ -258,7 +244,7 @@ static void handle_fd_set(isrv_state_t *
 			/* this peer is gone */
 			remove_peer(state, peer);
 		} else if (TIMEOUT) {
-			TIMEO_TBL[peer] = monotonic_time();
+			TIMEO_TBL[peer] = monotonic_sec();
 		}
 	}
 }
@@ -335,7 +321,7 @@ void isrv_run(
 			break;
 
 		if (timeout) {
-			time_t t = monotonic_time();
+			time_t t = monotonic_sec();
 			if (t != CURTIME) {
 				CURTIME = t;
 				handle_timeout(state, do_timeout);
diff -d -urpN busybox.0/runit/runsv.c busybox.1/runit/runsv.c
--- busybox.0/runit/runsv.c	2007-08-29 19:11:41.000000000 +0100
+++ busybox.1/runit/runsv.c	2007-08-31 17:22:04.219061000 +0100
@@ -33,6 +33,34 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAG
 #include "libbb.h"
 #include "runit_lib.h"
 
+#if ENABLE_MONOTONIC_SYSCALL
+#include <sys/syscall.h>
+
+/* libc has incredibly messy way of doing this,
+ * typically requiring -lrt. We just skip all this mess */
+static void gettimeofday_ns(struct timespec *ts)
+{
+	syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
+}
+#else
+static void gettimeofday_ns(struct timespec *ts)
+{
+	if (sizeof(struct timeval) == sizeof(struct timespec)
+	 && sizeof(((struct timeval*)ts)->tv_usec) == sizeof(ts->tv_nsec)
+	) {
+		/* Cheat */
+		gettimeofday((void*)ts, NULL);
+		ts->tv_nsec *= 1000;
+	} else {
+		extern void BUG_need_to_implement_gettimeofday_ns(void);
+		BUG_need_to_implement_gettimeofday_ns();
+	}
+}
+#endif
+
+/* Compare possibly overflowing unsigned counters */
+#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
+
 static int selfpipe[2];
 
 /* state */
@@ -126,14 +154,6 @@ static int rename_or_warn(const char *ol
 	return 0;
 }
 
-#define LESS(a,b) ((int)((unsigned)(b) - (unsigned)(a)) > 0)
-
-#include <sys/syscall.h>
-static void gettimeofday_ns(struct timespec *ts)
-{
-	syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
-}
-
 static void update_status(struct svdir *s)
 {
 	ssize_t sz;


_______________________________________________
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic