Don't add useless domain and search entries to resolv.conf
[connman] / gdbus / mainloop.c
index b50d83c..eaba42e 100644 (file)
@@ -2,7 +2,7 @@
  *
  *  D-Bus helper library
  *
- *  Copyright (C) 2004-2008  Marcel Holtmann <marcel@holtmann.org>
+ *  Copyright (C) 2004-2009  Marcel Holtmann <marcel@holtmann.org>
  *
  *
  *  This program is free software; you can redistribute it and/or modify
@@ -60,7 +60,7 @@ struct server_info {
 };
 
 struct disconnect_data {
-       void (*disconnect_cb)(void *);
+       GDBusWatchFunction disconnect_cb;
        void *user_data;
 };
 
@@ -72,8 +72,8 @@ static DBusHandlerResult disconnect_filter(DBusConnection *conn,
        if (dbus_message_is_signal(msg,
                        DBUS_INTERFACE_LOCAL, "Disconnected") == TRUE) {
                error("Got disconnected from the system message bus");
+               dc_data->disconnect_cb(conn, dc_data->user_data);
                dbus_connection_unref(conn);
-               dc_data->disconnect_cb(dc_data->user_data);
        }
 
        return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
@@ -281,6 +281,49 @@ gboolean g_dbus_request_name(DBusConnection *connection, const char *name,
        return TRUE;
 }
 
+gboolean g_dbus_check_service(DBusConnection *connection, const char *name)
+{
+       DBusMessage *message, *reply;
+       const char **names;
+       int i, count;
+       gboolean result = FALSE;
+
+       message = dbus_message_new_method_call(DBUS_SERVICE_DBUS,
+                       DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "ListNames");
+       if (message == NULL) {
+               error("Can't allocate new message");
+               return FALSE;
+       }
+
+       reply = dbus_connection_send_with_reply_and_block(connection,
+                                                       message, -1, NULL);
+
+       dbus_message_unref(message);
+
+       if (reply == NULL) {
+               error("Failed to execute method call");
+               return FALSE;
+       }
+
+       if (dbus_message_get_args(reply, NULL,
+                               DBUS_TYPE_ARRAY, DBUS_TYPE_STRING,
+                               &names, &count, DBUS_TYPE_INVALID) == FALSE) {
+               error("Failed to read name list");
+               goto done;
+       }
+
+       for (i = 0; i < count; i++)
+               if (g_str_equal(names[i], name) == TRUE) {
+                       result = TRUE;
+                       break;
+               }
+
+done:
+       dbus_message_unref(reply);
+
+       return result;
+}
+
 gboolean g_dbus_set_disconnect_function(DBusConnection *connection,
                                GDBusWatchFunction function,
                                void *user_data, DBusFreeFunction destroy)