avoid using 99% CPU in case gpsd dies

This addresses and issue when gpsdate is running and the gpsd will be
killed (testing coredump handling).

The issue is within the libgps cod itself that doesn't handle the
result(0) of the recv syscall correctly and keeps on looping. Now in a
normal system gpsdate should only execute at the beginning and exit once
there is a date. So the window for this runtime failure is quite low.

Bug reported by Holger Freyther.
This commit is contained in:
Harald Welte 2013-08-29 17:12:25 +02:00
parent 0db898e4b8
commit cb65bc5348
1 changed files with 21 additions and 1 deletions

View File

@ -123,6 +123,26 @@ static int osmo_daemonize(void)
return 0;
/* local copy, as the libgps official version ignores gps_read() result */
static int my_gps_mainloop(struct gps_data_t *gdata,
int timeout,
void (*hook)(struct gps_data_t *gdata))
int rc;
for (;;) {
if (!gps_waiting(gdata, timeout)) {
return -1;
} else {
rc = gps_read(gdata);
if (rc < 0)
return rc;
return 0;
int main(int argc, char **argv)
char *host = "localhost";
@ -155,7 +175,7 @@ int main(int argc, char **argv)
/* We run in an endless loop. The only reasonable way to exit is after
* a correct GPS timestamp has been received in callback() */
while (1)
gps_mainloop(&gpsdata, INT_MAX, callback);
my_gps_mainloop(&gpsdata, INT_MAX, callback);