From e28dffca0bf6a1d0dcc69e4abb52a22e0b0578be Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Fri, 15 Jun 2012 14:13:47 +0300 Subject: [PATCH] technology: Disable technology when the last device is unpowered Reply via D-Bus to the caller and send the technology 'Powered' property set to FALSE only after the last device has been powered off. Update code but not behavior in __connman_technology_enabled() so that the logic looks the same as in __connman_technology_disabled(). --- src/technology.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/technology.c b/src/technology.c index 635c7b0..be688f2 100644 --- a/src/technology.c +++ b/src/technology.c @@ -1131,8 +1131,10 @@ int __connman_technology_enabled(enum connman_service_type type) if (technology == NULL) return -ENXIO; - if (__sync_fetch_and_add(&technology->enabled, 1) == 0) - powered_changed(technology); + if (__sync_fetch_and_add(&technology->enabled, 1) != 0) + return -EALREADY; + + powered_changed(technology); if (technology->pending_reply != NULL) { g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID); @@ -1153,6 +1155,9 @@ int __connman_technology_disabled(enum connman_service_type type) if (technology == NULL) return -ENXIO; + if (__sync_fetch_and_sub(&technology->enabled, 1) != 1) + return -EINPROGRESS; + if (technology->pending_reply != NULL) { g_dbus_send_reply(connection, technology->pending_reply, DBUS_TYPE_INVALID); dbus_message_unref(technology->pending_reply); @@ -1161,8 +1166,7 @@ int __connman_technology_disabled(enum connman_service_type type) technology->pending_timeout = 0; } - if (__sync_fetch_and_sub(&technology->enabled, 1) == 1) - powered_changed(technology); + powered_changed(technology); return 0; } -- 2.7.4