Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(677)

Unified Diff: dhcpcd-dbus.c

Issue 3060016: Added a D-Bus filter to find out when flimflamd dies, so that we can clean up and exit. (Closed) Base URL: ssh://git@chromiumos-git/dhcpcd.git
Patch Set: Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: dhcpcd-dbus.c
diff --git a/dhcpcd-dbus.c b/dhcpcd-dbus.c
index c597e16d3ce09d62ab416947362b2560fef36e12..5600fbf59c74a336bc30d13c3cc3c14eecbe6304 100644
--- a/dhcpcd-dbus.c
+++ b/dhcpcd-dbus.c
@@ -473,7 +473,7 @@ msg_handler(DBusConnection *con, DBusMessage *msg, _unused void *data)
#define IsMethod(msg, method) \
dbus_message_is_method_call(msg, DHCPCD_SERVICE, method)
if (dbus_message_is_method_call(msg, DBUS_INTERFACE_INTROSPECTABLE,
- "Introspect")) {
+ "Introspect")) {
return introspect(con, msg);
} else if (IsMethod(msg, "GetVersion")) {
return version(con, msg, VERSION);
@@ -552,10 +552,47 @@ remove_watch(DBusWatch *watch, _unused void *data)
delete_event(fd);
}
+static DBusHandlerResult dhcpcd_dbus_filter(DBusConnection *conn,
+ DBusMessage *msg,
+ void *user_data)
+{
+ const char *service = NULL;
+ const char *old_owner = NULL;
+ const char *new_owner = NULL;
+
+ if (!dbus_message_is_signal(msg, DBUS_INTERFACE_DBUS,
+ "NameOwnerChanged"))
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (!dbus_message_get_args(msg, NULL,
+ DBUS_TYPE_STRING, &service,
+ DBUS_TYPE_STRING, &old_owner,
+ DBUS_TYPE_STRING, &new_owner,
+ DBUS_TYPE_INVALID)) {
+ syslog(LOG_ERR,
+ "Invalid arguments for NameOwnerChanged signal");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+ if (strcmp(service, "org.chromium.flimflam") == 0 &&
+ strlen(new_owner) == 0) {
kobi 2010/07/27 18:07:02 I think it is better to check new_owner against nu
+ syslog(LOG_INFO, "exiting because flimflamd has died");
+ stop_interface(ifaces);
+ exit(EXIT_FAILURE);
+ }
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+}
+
+static const char *service_watch_rule = "interface=" DBUS_INTERFACE_DBUS
+ ",type=signal,member=NameOwnerChanged";
+
void
dhcpcd_dbus_close(void)
{
if (connection) {
+ dbus_bus_remove_match(connection, service_watch_rule, NULL);
+ dbus_connection_remove_filter(connection,
+ dhcpcd_dbus_filter,
+ NULL);
dbus_connection_unref(connection);
connection = NULL;
}
@@ -593,6 +630,12 @@ dhcpcd_dbus_init(void)
syslog(LOG_ERR, "dbus: failed to register object path");
return -1;
}
+ dbus_connection_add_filter(connection, dhcpcd_dbus_filter, NULL, NULL);
+ dbus_bus_add_match(connection, service_watch_rule, &err);
+ if (dbus_error_is_set(&err)) {
+ syslog(LOG_ERR, "Cannot add rule: %s", err.message);
+ return -1;
+ }
return 0;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698