X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-daemon%2Fdbus-protocol.c;h=9bfc15113d0fd6d406f39aa08655b93ed6eb0542;hb=758381efbaa40d604253259cd43f194db1162859;hp=e74caa328ec7213c056b76de994d168351550dd2;hpb=59f3e8bef545762113c041a1ef5868e08b353045;p=catta diff --git a/avahi-daemon/dbus-protocol.c b/avahi-daemon/dbus-protocol.c index e74caa3..9bfc151 100644 --- a/avahi-daemon/dbus-protocol.c +++ b/avahi-daemon/dbus-protocol.c @@ -189,7 +189,7 @@ static DBusHandlerResult msg_signal_filter_impl(AVAHI_GCC_UNUSED DBusConnection struct timeval tv; if (server->reconnect) { - avahi_log_warn("Disconnnected from D-BUS, trying to reconnect in %ims...", RECONNECT_MSEC); + avahi_log_warn("Disconnnected from D-Bus, trying to reconnect in %ims...", RECONNECT_MSEC); dbus_disconnect(); @@ -200,7 +200,7 @@ static DBusHandlerResult msg_signal_filter_impl(AVAHI_GCC_UNUSED DBusConnection else server->reconnect_timeout = server->poll_api->timeout_new(server->poll_api, &tv, reconnect_callback, NULL); } else { - avahi_log_warn("Disconnnected from D-BUS, exiting."); + avahi_log_warn("Disconnnected from D-Bus, exiting."); raise(SIGQUIT); } @@ -346,9 +346,7 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceNameByIndex")) { int32_t idx; - int fd; char name[IF_NAMESIZE]; - if (!(dbus_message_get_args(m, &error, DBUS_TYPE_INT32, &idx, DBUS_TYPE_INVALID))) { avahi_log_warn("Error parsing Server::GetNetworkInterfaceNameByIndex message"); @@ -358,29 +356,17 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH #ifdef VALGRIND_WORKAROUND return respond_string(c, m, "blah"); #else - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - char txt[256]; - snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno)); - return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt); - } - if ((!if_indextoname(idx, name))) { char txt[256]; snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno)); - close(fd); return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt); } - - close(fd); return avahi_dbus_respond_string(c, m, name); #endif } else if (dbus_message_is_method_call(m, AVAHI_DBUS_INTERFACE_SERVER, "GetNetworkInterfaceIndexByName")) { char *n; - int fd; int32_t idx; if (!(dbus_message_get_args(m, &error, DBUS_TYPE_STRING, &n, DBUS_TYPE_INVALID)) || !n) { @@ -391,21 +377,11 @@ static DBusHandlerResult msg_server_impl(DBusConnection *c, DBusMessage *m, AVAH #ifdef VALGRIND_WORKAROUND return respond_int32(c, m, 1); #else - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) - if ((fd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - char txt[256]; - snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno)); - return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt); - } - if (!(idx = if_nametoindex(n))) { char txt[256]; snprintf(txt, sizeof(txt), "OS Error: %s", strerror(errno)); - close(fd); return avahi_dbus_respond_error(c, m, AVAHI_ERR_OS, txt); } - - close(fd); return avahi_dbus_respond_int32(c, m, idx); #endif @@ -1075,12 +1051,34 @@ static int dbus_connect(void) { assert(!server->bus); dbus_error_init(&error); - - if (!(server->bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error))) { + +#ifdef HAVE_DBUS_BUS_GET_PRIVATE + if (!(server->bus = dbus_bus_get_private(DBUS_BUS_SYSTEM, &error))) { assert(dbus_error_is_set(&error)); - avahi_log_error("dbus_bus_get(): %s", error.message); + avahi_log_error("dbus_bus_get_private(): %s", error.message); goto fail; } +#else + { + const char *a; + + if (!(a = getenv("DBUS_SYSTEM_BUS_ADDRESS")) || !*a) + a = DBUS_SYSTEM_BUS_DEFAULT_ADDRESS; + + if (!(server->bus = dbus_connection_open_private(a, &error))) { + assert(dbus_error_is_set(&error)); + avahi_log_error("dbus_bus_open_private(): %s", error.message); + goto fail; + } + + if (!dbus_bus_register(server->bus, &error)) { + assert(dbus_error_is_set(&error)); + avahi_log_error("dbus_bus_register(): %s", error.message); + goto fail; + } + } +#endif + if (avahi_dbus_connection_glue(server->bus, server->poll_api) < 0) { avahi_log_error("avahi_dbus_connection_glue() failed"); goto fail; @@ -1091,10 +1089,10 @@ static int dbus_connect(void) { if (dbus_bus_request_name( server->bus, AVAHI_DBUS_NAME, -#if (DBUS_VERSION_MAJOR == 0) && (DBUS_VERSION_MINOR >= 60) - DBUS_NAME_FLAG_DO_NOT_QUEUE, -#else +#if (DBUS_VERSION_MAJOR == 0) && (DBUS_VERSION_MINOR < 60) DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT, +#else + DBUS_NAME_FLAG_DO_NOT_QUEUE, #endif &error) != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { if (dbus_error_is_set(&error)) { @@ -1102,7 +1100,7 @@ static int dbus_connect(void) { goto fail; } - avahi_log_error("Failed to acquire DBUS name '"AVAHI_DBUS_NAME"'"); + avahi_log_error("Failed to acquire D-Bus name '"AVAHI_DBUS_NAME"'"); goto fail; } @@ -1195,6 +1193,7 @@ fail: #else dbus_connection_disconnect(server->bus); #endif + dbus_connection_unref(server->bus); }