From 898d7ae0a41df483d32ca010732d912436986fdd Mon Sep 17 00:00:00 2001 From: Sascha Wessel Date: Tue, 25 Nov 2008 00:44:15 +0100 Subject: [PATCH] Fixed a possible race condition --- ChangeLog | 1 + fso-gpsd.c | 117 +++++++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 76 insertions(+), 42 deletions(-) diff --git a/ChangeLog b/ChangeLog index bc43e7e..173357b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ fso-gpsd 0.8 * Improved Gypsy compatibility * Made device, service and server path configurable * Made TCP address configurable + * Fixed a possible race condition fso-gpsd 0.7 - 2008-10-25 * Fixed speed for frameworkd 2008-09-28 and newer diff --git a/fso-gpsd.c b/fso-gpsd.c index 87a160b..d105c8f 100644 --- a/fso-gpsd.c +++ b/fso-gpsd.c @@ -48,35 +48,35 @@ #define CRITICAL(...) \ do { \ - if (log_level & G_LOG_LEVEL_CRITICAL) { \ + if (G_UNLIKELY(log_level & G_LOG_LEVEL_CRITICAL)) { \ g_log(NULL, G_LOG_LEVEL_CRITICAL, __VA_ARGS__); \ } \ } while (0) #define WARNING(...) \ do { \ - if (log_level & G_LOG_LEVEL_WARNING) { \ + if (G_UNLIKELY(log_level & G_LOG_LEVEL_WARNING)) { \ g_log(NULL, G_LOG_LEVEL_WARNING, __VA_ARGS__); \ } \ } while (0) #define MESSAGE(...) \ do { \ - if (log_level & G_LOG_LEVEL_MESSAGE) { \ + if (G_UNLIKELY(log_level & G_LOG_LEVEL_MESSAGE)) { \ g_log(NULL, G_LOG_LEVEL_MESSAGE, __VA_ARGS__); \ } \ } while (0) #define INFO(...) \ do { \ - if (log_level & G_LOG_LEVEL_INFO) { \ + if (G_UNLIKELY(log_level & G_LOG_LEVEL_INFO)) { \ g_log(NULL, G_LOG_LEVEL_INFO, __VA_ARGS__); \ } \ } while (0) #define DEBUG(...) \ do { \ - if (log_level & G_LOG_LEVEL_DEBUG) { \ + if (G_UNLIKELY(log_level & G_LOG_LEVEL_DEBUG)) { \ g_log(NULL, G_LOG_LEVEL_DEBUG, __VA_ARGS__); \ } \ } while (0) @@ -1172,7 +1172,10 @@ get_connection_status_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer d g_error_free(error); } else { DEBUG(GYPSY_DEVICE": GetConnectionStatus: OK"); - connection_status_changed(NULL, connectionstatus, NULL); + + if (proxy == device_proxy) { + connection_status_changed(NULL, connectionstatus, NULL); + } } } @@ -1193,7 +1196,10 @@ get_fix_status_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data) g_error_free(error); } else { DEBUG(GYPSY_DEVICE": GetFixStatus: OK"); - fix_status_changed(NULL, fixstatus, NULL); + + if (proxy == device_proxy) { + fix_status_changed(NULL, fixstatus, NULL); + } } } @@ -1214,7 +1220,10 @@ get_time_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data) g_error_free(error); } else { DEBUG(GYPSY_TIME": GetTime: OK"); - time_changed(NULL, seconds, NULL); + + if (proxy == time_proxy) { + time_changed(NULL, seconds, NULL); + } } } @@ -1240,8 +1249,11 @@ get_position_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data) g_error_free(error); } else { DEBUG(GYPSY_POSITION": GetPosition: OK"); - position_changed(NULL, fields, timestamp, latitude, longitude, - altitude, NULL); + + if (proxy == position_proxy) { + position_changed(NULL, fields, timestamp, latitude, + longitude, altitude, NULL); + } } } @@ -1266,7 +1278,10 @@ get_accuracy_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data) g_error_free(error); } else { DEBUG(GYPSY_ACCURACY": GetAccuracy: OK"); - accuracy_changed(NULL, fields, pdop, hdop, vdop, NULL); + + if (proxy == accuracy_proxy) { + accuracy_changed(NULL, fields, pdop, hdop, vdop, NULL); + } } } @@ -1292,8 +1307,11 @@ get_course_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data) g_error_free(error); } else { DEBUG(GYPSY_COURSE": GetCourse: OK"); - course_changed(NULL, fields, timestamp, speed, direction, - climb, NULL); + + if (proxy == course_proxy) { + course_changed(NULL, fields, timestamp, speed, + direction, climb, NULL); + } } } @@ -1322,7 +1340,10 @@ get_satellites_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data) g_error_free(error); } else { DEBUG(GYPSY_SATELLITE": GetSatellites: OK"); - satellites_changed(NULL, satellites, NULL); + + if (proxy == satellite_proxy) { + satellites_changed(NULL, satellites, NULL); + } } } @@ -1345,40 +1366,52 @@ device_start_notify(DBusGProxy *proxy, DBusGProxyCall *call, gpointer data) DEBUG(GYPSY_DEVICE": Start: OK"); gypsy_device_start_failed = FALSE; - DEBUG(GYPSY_DEVICE": GetConnectionStatus"); - dbus_g_proxy_begin_call(device_proxy, "GetConnectionStatus", - get_connection_status_notify, NULL, NULL, - G_TYPE_INVALID); + if (device_proxy) { + DEBUG(GYPSY_DEVICE": GetConnectionStatus"); + dbus_g_proxy_begin_call(device_proxy, "GetConnectionStatus", + get_connection_status_notify, NULL, NULL, + G_TYPE_INVALID); - DEBUG(GYPSY_DEVICE": GetFixStatus"); - dbus_g_proxy_begin_call(device_proxy, "GetFixStatus", - get_fix_status_notify, NULL, NULL, - G_TYPE_INVALID); + DEBUG(GYPSY_DEVICE": GetFixStatus"); + dbus_g_proxy_begin_call(device_proxy, "GetFixStatus", + get_fix_status_notify, NULL, NULL, + G_TYPE_INVALID); + } - DEBUG(GYPSY_TIME": GetTime"); - dbus_g_proxy_begin_call(time_proxy, "GetTime", - get_time_notify, NULL, NULL, - G_TYPE_INVALID); + if (time_proxy) { + DEBUG(GYPSY_TIME": GetTime"); + dbus_g_proxy_begin_call(time_proxy, "GetTime", + get_time_notify, NULL, NULL, + G_TYPE_INVALID); + } - DEBUG(GYPSY_POSITION": GetPosition"); - dbus_g_proxy_begin_call(position_proxy, "GetPosition", - get_position_notify, NULL, NULL, - G_TYPE_INVALID); + if (position_proxy) { + DEBUG(GYPSY_POSITION": GetPosition"); + dbus_g_proxy_begin_call(position_proxy, "GetPosition", + get_position_notify, NULL, NULL, + G_TYPE_INVALID); + } - DEBUG(GYPSY_ACCURACY": GetAccuracy"); - dbus_g_proxy_begin_call(accuracy_proxy, "GetAccuracy", - get_accuracy_notify, NULL, NULL, - G_TYPE_INVALID); + if (accuracy_proxy) { + DEBUG(GYPSY_ACCURACY": GetAccuracy"); + dbus_g_proxy_begin_call(accuracy_proxy, "GetAccuracy", + get_accuracy_notify, NULL, NULL, + G_TYPE_INVALID); + } - DEBUG(GYPSY_COURSE": GetCourse"); - dbus_g_proxy_begin_call(course_proxy, "GetCourse", - get_course_notify, NULL, NULL, - G_TYPE_INVALID); + if (course_proxy) { + DEBUG(GYPSY_COURSE": GetCourse"); + dbus_g_proxy_begin_call(course_proxy, "GetCourse", + get_course_notify, NULL, NULL, + G_TYPE_INVALID); + } - DEBUG(GYPSY_SATELLITE": GetSatellites"); - dbus_g_proxy_begin_call(satellite_proxy, "GetSatellites", - get_satellites_notify, NULL, NULL, - G_TYPE_INVALID); + if (satellite_proxy) { + DEBUG(GYPSY_SATELLITE": GetSatellites"); + dbus_g_proxy_begin_call(satellite_proxy, "GetSatellites", + get_satellites_notify, NULL, NULL, + G_TYPE_INVALID); + } } } -- 2.11.4.GIT