X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dbus%2Fdbus-server-unix.c;h=d995240480b23e8aed56b5173d1025c30d5891eb;hb=3ccb027c907f9ee2890028e83b60296204bbf478;hp=597d0f8ef65a4401328c6fb836d228a18b24710a;hpb=e1c31c73074513d96fa22b5c0355107c42720597;p=platform%2Fupstream%2Fdbus.git diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c index 597d0f8..d995240 100644 --- a/dbus/dbus-server-unix.c +++ b/dbus/dbus-server-unix.c @@ -4,7 +4,7 @@ * Copyright (C) 2002, 2003, 2004 Red Hat Inc. * * Licensed under the Academic Free License version 2.1 - * + * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or @@ -14,16 +14,18 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * */ +#include #include "dbus-internals.h" #include "dbus-server-unix.h" #include "dbus-server-socket.h" +#include "dbus-server-launchd.h" #include "dbus-transport-unix.h" #include "dbus-connection-internal.h" #include "dbus-sysdeps-unix.h" @@ -41,12 +43,12 @@ * Tries to interpret the address entry in a platform-specific * way, creating a platform-specific server type if appropriate. * Sets error if the result is not OK. - * + * * @param entry an address entry * @param server_p location to store a new DBusServer, or #NULL on failure. * @param error location to store rationale for failure on bad address * @returns the outcome - * + * */ DBusServerListenResult _dbus_server_listen_platform_specific (DBusAddressEntry *entry, @@ -56,7 +58,7 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, const char *method; *server_p = NULL; - + method = dbus_address_entry_get_method (entry); if (strcmp (method, "unix") == 0) @@ -64,7 +66,7 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, const char *path = dbus_address_entry_get_value (entry, "path"); const char *tmpdir = dbus_address_entry_get_value (entry, "tmpdir"); const char *abstract = dbus_address_entry_get_value (entry, "abstract"); - + if (path == NULL && tmpdir == NULL && abstract == NULL) { _dbus_set_bad_address(error, "unix", @@ -86,20 +88,20 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, { DBusString full_path; DBusString filename; - + if (!_dbus_string_init (&full_path)) { dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; } - + if (!_dbus_string_init (&filename)) { _dbus_string_free (&full_path); dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; } - + if (!_dbus_string_append (&filename, "dbus-") || !_dbus_generate_random_ascii (&filename, 10) || @@ -111,9 +113,9 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; } - + /* Always use abstract namespace if possible with tmpdir */ - + *server_p = _dbus_server_new_for_domain_socket (_dbus_string_get_const_data (&full_path), #ifdef HAVE_ABSTRACT_SOCKETS @@ -145,6 +147,74 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; } } + else if (strcmp (method, "systemd") == 0) + { + int i, n, *fds; + DBusString address; + + n = _dbus_listen_systemd_sockets (&fds, error); + if (n < 0) + { + _DBUS_ASSERT_ERROR_IS_SET (error); + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; + } + + if (!_dbus_string_init (&address)) + goto systemd_oom; + + for (i = 0; i < n; i++) + { + if (i > 0) + { + if (!_dbus_string_append (&address, ";")) + goto systemd_oom; + } + if (!_dbus_append_address_from_socket (fds[i], &address, error)) + goto systemd_err; + } + + *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL); + if (*server_p == NULL) + goto systemd_oom; + + dbus_free (fds); + + return DBUS_SERVER_LISTEN_OK; + systemd_oom: + _DBUS_SET_OOM (error); + systemd_err: + for (i = 0; i < n; i++) + { + _dbus_close_socket (fds[i], NULL); + } + dbus_free (fds); + _dbus_string_free (&address); + + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; + } +#ifdef DBUS_ENABLE_LAUNCHD + else if (strcmp (method, "launchd") == 0) + { + const char *launchd_env_var = dbus_address_entry_get_value (entry, "env"); + if (launchd_env_var == NULL) + { + _dbus_set_bad_address (error, "launchd", "env", NULL); + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; + } + *server_p = _dbus_server_new_for_launchd (launchd_env_var, error); + + if (*server_p != NULL) + { + _DBUS_ASSERT_ERROR_IS_CLEAR(error); + return DBUS_SERVER_LISTEN_OK; + } + else + { + _DBUS_ASSERT_ERROR_IS_SET(error); + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; + } + } +#endif else { /* If we don't handle the method, we return NULL with the @@ -173,7 +243,7 @@ _dbus_server_new_for_domain_socket (const char *path, DBusString address; char *path_copy; DBusString path_str; - + _DBUS_ASSERT_ERROR_IS_CLEAR (error); if (!_dbus_string_init (&address)) @@ -193,13 +263,20 @@ _dbus_server_new_for_domain_socket (const char *path, goto failed_0; } - path_copy = _dbus_strdup (path); - if (path_copy == NULL) + if (abstract) { - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); - goto failed_0; + path_copy = NULL; + } + else + { + path_copy = _dbus_strdup (path); + if (path_copy == NULL) + { + dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); + goto failed_0; + } } - + listen_fd = _dbus_listen_unix_socket (path, abstract, error); if (listen_fd < 0) @@ -207,7 +284,7 @@ _dbus_server_new_for_domain_socket (const char *path, _DBUS_ASSERT_ERROR_IS_SET (error); goto failed_1; } - + server = _dbus_server_new_for_socket (&listen_fd, 1, &address, 0); if (server == NULL) { @@ -215,10 +292,11 @@ _dbus_server_new_for_domain_socket (const char *path, goto failed_2; } - _dbus_server_socket_own_filename(server, path_copy); - + if (path_copy != NULL) + _dbus_server_socket_own_filename(server, path_copy); + _dbus_string_free (&address); - + return server; failed_2: @@ -232,4 +310,3 @@ _dbus_server_new_for_domain_socket (const char *path, } /** @} */ -