summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2018-12-26 13:23:04 -0500
committerEric S. Raymond <esr@thyrsus.com>2018-12-26 13:23:04 -0500
commit5517175ed53b877720fdf5a1a4085386b40c4590 (patch)
tree31c1ce53dea117cfb36a1e7d679cb785b32abdf8
parentc9e81aabcf2f5c6886be1fd0e859ceb63470e06f (diff)
downloadgpsd-5517175ed53b877720fdf5a1a4085386b40c4590.tar.gz
Eliminate effectively all uses of struct timeval.
Outide of one Mac portability shim, anyway. Associated select(2) calls become pselect(2) calls.
-rw-r--r--TODO2
-rw-r--r--driver_geostar.c13
-rw-r--r--driver_tsip.c8
-rw-r--r--gps2udp.c11
-rw-r--r--gpsd.c4
-rw-r--r--gpsmon.c4
-rw-r--r--gpspipe.c10
-rw-r--r--libgps_sock.c8
-rw-r--r--libgpsd_core.c4
-rw-r--r--timehint.c2
10 files changed, 40 insertions, 26 deletions
diff --git a/TODO b/TODO
index 0168c341..ea580c32 100644
--- a/TODO
+++ b/TODO
@@ -32,7 +32,7 @@ In gps_data_t add more string like subtype for HW version, SW version, etc.
In gps_data_t, save PPS precision; this will require creating a pps struct.
Where would PPS precision come from?
-Convert all the timestamp_t (double) and timeval (usec) to timespec (nsec).
+Convert all the timestamp_t (double) timespec (nsec).
That could be done one small step at a time.
Make the Python JSON client as smart as the C JSON client. Gonna be
diff --git a/driver_geostar.c b/driver_geostar.c
index 306ca3e9..127d92e1 100644
--- a/driver_geostar.c
+++ b/driver_geostar.c
@@ -10,7 +10,12 @@
* SPDX-License-Identifier: BSD-2-clause
*/
-#include <sys/time.h> /* for select() */
+#ifdef __linux__
+/* isfinite() and pselect() needs _POSIX_C_SOURCE >= 200112L */
+#define _POSIX_C_SOURCE 200112L
+#endif /* __linux__ */
+
+#include <sys/time.h> /* for pselect() */
#include <stdbool.h>
#include <stdio.h>
#include <math.h>
@@ -87,7 +92,7 @@ static bool geostar_detect(struct gps_device_t *session)
bool ret = false;
int myfd;
fd_set fdset;
- struct timeval to;
+ struct timespec to;
myfd = session->gpsdata.gps_fd;
@@ -99,8 +104,8 @@ static bool geostar_detect(struct gps_device_t *session)
FD_ZERO(&fdset);
FD_SET(myfd, &fdset);
to.tv_sec = 1;
- to.tv_usec = 0;
- if (select(myfd + 1, &fdset, NULL, NULL, &to) != 1)
+ to.tv_nsec = 0;
+ if (pselect(myfd + 1, &fdset, NULL, NULL, &to, NULL) != 1)
break;
if (generic_get(session) >= 0) {
if (session->lexer.type == GEOSTAR_PACKET) {
diff --git a/driver_tsip.c b/driver_tsip.c
index 70adbd7c..e6252027 100644
--- a/driver_tsip.c
+++ b/driver_tsip.c
@@ -23,7 +23,7 @@
#endif /* __linux__ */
-#include <sys/time.h> /* for select() */
+#include <sys/time.h> /* for pselect() */
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
@@ -83,7 +83,7 @@ static bool tsip_detect(struct gps_device_t *session)
bool ret = false;
int myfd;
fd_set fdset;
- struct timeval to;
+ struct timespec to;
speed_t old_baudrate;
char old_parity;
unsigned int old_stopbits;
@@ -105,8 +105,8 @@ static bool tsip_detect(struct gps_device_t *session)
FD_ZERO(&fdset);
FD_SET(myfd, &fdset);
to.tv_sec = 1;
- to.tv_usec = 0;
- if (select(myfd + 1, &fdset, NULL, NULL, &to) != 1)
+ to.tv_nsec = 0;
+ if (pselect(myfd + 1, &fdset, NULL, NULL, &to, NULL) != 1)
break;
if (generic_get(session) >= 0) {
if (session->lexer.type == TSIP_PACKET) {
diff --git a/gps2udp.c b/gps2udp.c
index 4e79b729..467919bf 100644
--- a/gps2udp.c
+++ b/gps2udp.c
@@ -15,6 +15,11 @@
/* strsep() needs _DEFAULT_SOURCE */
#define _DEFAULT_SOURCE
+#ifdef __linux__
+/* isfinite() and pselect() needs _POSIX_C_SOURCE >= 200112L */
+#define _POSIX_C_SOURCE 200112L
+#endif /* __linux__ */
+
#include <time.h>
#include "gpsd_config.h"
@@ -230,7 +235,7 @@ static void connect2gpsd(bool restart)
static ssize_t read_gpsd(char *message, size_t len)
/* get data from gpsd */
{
- struct timeval tv;
+ struct timespec tv;
fd_set fds,master;
int ind;
char c;
@@ -248,9 +253,9 @@ static ssize_t read_gpsd(char *message, size_t len)
int result;
/* prepare for a blocking read with a 10s timeout */
tv.tv_sec = 10;
- tv.tv_usec = 0;
+ tv.tv_nsec = 0;
fds = master;
- result = select(gpsdata.gps_fd+1, &fds, NULL, NULL, &tv);
+ result = pselect(gpsdata.gps_fd+1, &fds, NULL, NULL, &tv, NULL);
switch (result)
{
diff --git a/gpsd.c b/gpsd.c
index 68cacafd..6d3c14de 100644
--- a/gpsd.c
+++ b/gpsd.c
@@ -23,7 +23,7 @@
#include <sys/stat.h>
#include <sys/types.h>
-#include <sys/time.h> /* for select() */
+#include <sys/time.h> /* for pselect() */
#include <sys/select.h>
#include <stdio.h>
#include <stdint.h> /* for uint32_t, etc. */
@@ -735,7 +735,7 @@ static bool open_device( struct gps_device_t *device)
gpsd_log(&context.errout, LOG_INF,
"device %s activated\n", device->gpsdata.dev.path);
if ( PLACEHOLDING_FD == activated ) {
- /* it is a /dev/ppsX, no need to select() it */
+ /* it is a /dev/ppsX, no need to pselect() it */
return true;
}
FD_SET(device->gpsdata.gps_fd, &all_fds);
diff --git a/gpsmon.c b/gpsmon.c
index ed1e33b6..ff2a54dd 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -20,7 +20,7 @@
#include <stdarg.h>
#include <time.h>
#include <math.h>
-#include <sys/time.h> /* expected to declare select(2) a la SuS */
+#include <sys/time.h> /* expected to declare pselect(2) a la SuS */
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
@@ -1492,7 +1492,7 @@ int main(int argc, char **argv)
explanation = NULL;
switch (bailout) {
case TERM_SELECT_FAILED:
- explanation = "select(2) failed\n";
+ explanation = "pselect(2) failed\n";
break;
case TERM_DRIVER_SWITCH:
explanation = "Driver type switch failed\n";
diff --git a/gpspipe.c b/gpspipe.c
index 1e8d822f..39f6c301 100644
--- a/gpspipe.c
+++ b/gpspipe.c
@@ -26,6 +26,10 @@
/* cfmakeraw() needs _DEFAULT_SOURCE */
#define _DEFAULT_SOURCE
+#ifdef __linux__
+/* isfinite() and pselect() needs _POSIX_C_SOURCE >= 200112L */
+#define _POSIX_C_SOURCE 200112L
+#endif /* __linux__ */
#include <time.h> /* for time_t */
#include "gpsd_config.h"
@@ -327,14 +331,14 @@ int main(int argc, char **argv)
for (;;) {
int r = 0;
- struct timeval tv;
+ struct timespec tv;
tv.tv_sec = 0;
- tv.tv_usec = 100000;
+ tv.tv_nsec = 100000000;
FD_ZERO(&fds);
FD_SET(gpsdata.gps_fd, &fds);
errno = 0;
- r = select(gpsdata.gps_fd+1, &fds, NULL, NULL, &tv);
+ r = pselect(gpsdata.gps_fd+1, &fds, NULL, NULL, &tv, NULL);
if (r >= 0 && exit_timer && time(NULL) >= exit_timer)
break;
if (r == -1 && errno != EINTR) {
diff --git a/libgps_sock.c b/libgps_sock.c
index 7c19c639..923703c7 100644
--- a/libgps_sock.c
+++ b/libgps_sock.c
@@ -13,7 +13,7 @@
#include <math.h>
#include <locale.h>
#include <assert.h>
-#include <sys/time.h> /* expected to have a select(2) prototype a la SuS */
+#include <sys/time.h> /* expected to have a pselect(2) prototype a la SuS */
#include <sys/types.h>
#include <sys/stat.h>
#include "gpsd_config.h"
@@ -132,7 +132,7 @@ bool gps_sock_waiting(const struct gps_data_t *gpsdata, int timeout)
{
#ifndef USE_QT
fd_set rfds;
- struct timeval tv;
+ struct timespec tv;
libgps_debug_trace((DEBUG_CALLS, "gps_waiting(%d): %d\n", timeout, PRIVATE(gpsdata)->waitcount++));
if (PRIVATE(gpsdata)->waiting > 0)
@@ -144,9 +144,9 @@ bool gps_sock_waiting(const struct gps_data_t *gpsdata, int timeout)
FD_ZERO(&rfds);
FD_SET(gpsdata->gps_fd, &rfds);
tv.tv_sec = timeout / 1000000;
- tv.tv_usec = timeout % 1000000;
+ tv.tv_nsec = timeout % 1000000000;
/* all error conditions return "not waiting" -- crude but effective */
- return (select(gpsdata->gps_fd + 1, &rfds, NULL, NULL, &tv) == 1);
+ return (pselect(gpsdata->gps_fd + 1, &rfds, NULL, NULL, &tv, NULL) == 1);
#else
return ((QTcpSocket *) (gpsdata->gps_fd))->waitForReadyRead(timeout / 1000);
#endif
diff --git a/libgpsd_core.c b/libgpsd_core.c
index a752f10f..15fa8070 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -1054,7 +1054,7 @@ int gpsd_await_data(fd_set *rfds,
* actually matter here since select returns whenever one of
* the file descriptors in the set goes ready. The point
* of tracking maxfd is to keep the set of descriptors that
- * select(2) has to poll here as small as possible (for
+ * pselect(2) has to poll here as small as possible (for
* low-clock-rate SBCs and the like).
*
* pselect() is preferable to vanilla select, to eliminate
@@ -1098,7 +1098,7 @@ int gpsd_await_data(fd_set *rfds,
if (FD_ISSET(i, rfds))
str_appendf(dbuf, sizeof(dbuf), " %d ", i);
gpsd_log(errout, LOG_SPIN,
- "select() {%s} at %f (errno %d)\n",
+ "pselect() {%s} at %f (errno %d)\n",
dbuf, timestamp(), errno);
}
diff --git a/timehint.c b/timehint.c
index 5df8b992..fd9fe70a 100644
--- a/timehint.c
+++ b/timehint.c
@@ -333,7 +333,7 @@ static void chrony_send(struct gps_device_t *session, struct timedelta_t *td)
* NTP expects leap pending for only 1 month prior to insertion
* Per http://bugs.ntp.org/1090
*
- * ITU-R TF.460-6, Section 2.1, says lappe seconds can be primarily
+ * ITU-R TF.460-6, Section 2.1, says leap seconds can be primarily
* in Jun/Dec but may be in March or September
*/
(void)gmtime_r( &(td->real.tv_sec), &tm);