-static void * gps_collectd_thread (void * pData)
-{
- struct gps_data_t conn;
-
- while (1)
- {
- int status = gps_open (config.host, config.port, &conn);
- if (status < 0)
- {
- WARNING ("gps plugin: Connecting to %s:%s failed: %s",
- config.host, config.port, gps_errstr (status));
- sleep (60);
+static void *cgps_thread(void *pData) {
+ struct gps_data_t gpsd_conn;
+ unsigned int err_count;
+ cgps_thread_running = CGPS_TRUE;
+
+ while (CGPS_TRUE) {
+ pthread_mutex_lock(&cgps_thread_lock);
+ if (cgps_thread_shutdown == CGPS_TRUE) {
+ goto quit;
+ }
+ pthread_mutex_unlock(&cgps_thread_lock);
+
+ err_count = 0;
+
+#if GPSD_API_MAJOR_VERSION > 4
+ int status =
+ gps_open(cgps_config_data.host, cgps_config_data.port, &gpsd_conn);
+#else
+ int status =
+ gps_open_r(cgps_config_data.host, cgps_config_data.port, &gpsd_conn);
+#endif
+ if (status < 0) {
+ WARNING("gps plugin: connecting to %s:%s failed: %s",
+ cgps_config_data.host, cgps_config_data.port, gps_errstr(status));
+
+ // Here we make a pause until a new tentative to connect, we check also if
+ // the thread does not need to stop.
+ if (cgps_thread_pause(cgps_config_data.pause_connect) == CGPS_FALSE) {
+ goto quit;
+ }
+