summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-03-31 00:38:23 -0400
committerEric S. Raymond <esr@thyrsus.com>2015-03-31 00:38:23 -0400
commit2e4a91e8dac81838a2a35e7aed5a74c3ec098e0e (patch)
tree1d171a6f656fff34a9ce7d0dfb57582dfffef232
parente59a564ceb7190a889a98dea3793bc7a9e6104ee (diff)
downloadgpsd-2e4a91e8dac81838a2a35e7aed5a74c3ec098e0e.tar.gz
ppsthread.[ch] and timespec_str.c are now fully detached from the rest of GPSD.
This means they could be dropped into NTP or another time-service program. The only requirement is to set -DHAVE_SYS_TIMEPPS_H if you want the RFC2783 code compiled in.
-rw-r--r--SConstruct3
-rw-r--r--ppsthread.c8
-rw-r--r--ppsthread.h20
3 files changed, 17 insertions, 14 deletions
diff --git a/SConstruct b/SConstruct
index 60b93e95..51d0654e 100644
--- a/SConstruct
+++ b/SConstruct
@@ -727,10 +727,9 @@ else:
confdefs.append("#define %s \"%s\"\n" % (key.upper(), value))
if config.CheckHeader(["sys/types.h", "sys/time.h", "sys/timepps.h"]):
- confdefs.append("#define HAVE_SYS_TIMEPPS_H 1\n")
+ env.MergeFlags("-DHAVE_SYS_TIMEPPS_H=1")
kpps = True
else:
- confdefs.append("/* #undef HAVE_SYS_TIMEPPS_H */\n")
kpps = False
tiocmiwait = config.CheckHeaderDefines("sys/ioctl.h", "TIOCMIWAIT")
if env["pps"] and not tiocmiwait and not kpps:
diff --git a/ppsthread.c b/ppsthread.c
index 1c270820..3e850795 100644
--- a/ppsthread.c
+++ b/ppsthread.c
@@ -1,6 +1,8 @@
/*
* ppsthread.c - manage PPS watcher threads
*
+ * To enable KPPS, this file needs to be compiled with -DHAVE_SYS_TIMEPPS_H
+ *
* If you are not good at threads do not touch this file!
* For example: errno is thread safe; strerror() is not.
*
@@ -59,7 +61,6 @@
#include <unistd.h>
#include <pthread.h> /* pacifies OpenBSD's compiler */
-#include "gpsd_config.h"
#include "timespec_str.h"
#include "ppsthread.h"
@@ -184,9 +185,12 @@ static int init_kernel_pps(volatile struct pps_thread_t *pps_thread)
* Some Linuxes, like the RasbPi's, have PPS devices preexisting.
* Other OS have no way to automatically determine the proper /dev/ppsX.
* Allow user to pass in an explicit PPS device path.
+ *
+ * (We use strncpy() here because this might be compiled where
+ * strlcpy() is not available.)
*/
if (strncmp(pps_thread->devicename, "/dev/pps", 8) == 0)
- (void)strlcpy(path, pps_thread->devicename, sizeof(path));
+ (void)strncpy(path, pps_thread->devicename, sizeof(path));
else {
char pps_num = '\0'; /* /dev/pps[pps_num] is our device */
size_t i; /* to match type of globbuf.gl_pathc */
diff --git a/ppsthread.h b/ppsthread.h
index 3d4aece7..ae9c824c 100644
--- a/ppsthread.h
+++ b/ppsthread.h
@@ -6,6 +6,16 @@
#ifndef PPSTHREAD_H
#define PPSTHREAD_H
+#include <time.h>
+
+#ifndef TIMEDELTA_DEFINED
+#define TIMEDELTA_DEFINED
+struct timedelta_t {
+ struct timespec real;
+ struct timespec clock;
+};
+#endif /* TIMEDELTA_DEFINED */
+
/* use RFC 2782 PPS API */
/* this needs linux >= 2.6.34 and
* CONFIG_PPS=y
@@ -15,20 +25,10 @@
#if defined(HAVE_SYS_TIMEPPS_H)
// include unistd.h here as it is missing on older pps-tools releases.
// 'close' is not defined otherwise.
-#include <unistd.h>
#include <sys/time.h>
#include <sys/timepps.h>
#endif
-#ifndef TIMEDELTA_DEFINED
-#define TIMEDELTA_DEFINED
-struct timedelta_t {
- struct timespec real;
- struct timespec clock;
-};
-#endif /* TIMEDELTA_DEFINED */
-
-
/* difference between timespecs in nanoseconds */
/* int is too small, avoid floats */
/* WARNING! this will overflow if x and y differ by more than a few seconds */