diff options
| author | Jonathan Liu <net147@gmail.com> | 2014-04-02 02:50:08 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2014-04-04 11:53:50 +0100 |
| commit | ed7afe2f6b004ecc3164517ee3c2e8c25ea0de93 (patch) | |
| tree | 4978bc99c1f3e74595f7349e938246c2d5fe8b0e | |
| parent | cd13b76fb56f0c1b28cdc25caefbcb04bc6b7bda (diff) | |
| download | poky-ed7afe2f6b004ecc3164517ee3c2e8c25ea0de93.tar.gz | |
dbus: backport fix for bus activation under systemd session
(From OE-Core rev: 8f191a37625ba6fe2e109555fa99658c4fcd7a37)
Signed-off-by: Jonathan Liu <net147@gmail.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/recipes-core/dbus/dbus.inc | 1 | ||||
| -rw-r--r-- | meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch | 193 |
2 files changed, 194 insertions, 0 deletions
diff --git a/meta/recipes-core/dbus/dbus.inc b/meta/recipes-core/dbus/dbus.inc index 677ff78146..5d57ff4bb4 100644 --- a/meta/recipes-core/dbus/dbus.inc +++ b/meta/recipes-core/dbus/dbus.inc | |||
| @@ -15,6 +15,7 @@ SRC_URI = "http://dbus.freedesktop.org/releases/dbus/dbus-${PV}.tar.gz \ | |||
| 15 | file://dbus-1.init \ | 15 | file://dbus-1.init \ |
| 16 | file://os-test.patch \ | 16 | file://os-test.patch \ |
| 17 | file://clear-guid_from_server-if-send_negotiate_unix_f.patch \ | 17 | file://clear-guid_from_server-if-send_negotiate_unix_f.patch \ |
| 18 | file://Set-correct-address-when-using-address-systemd.patch \ | ||
| 18 | " | 19 | " |
| 19 | 20 | ||
| 20 | inherit useradd autotools pkgconfig gettext update-rc.d | 21 | inherit useradd autotools pkgconfig gettext update-rc.d |
diff --git a/meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch b/meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch new file mode 100644 index 0000000000..1fca9bb254 --- /dev/null +++ b/meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch | |||
| @@ -0,0 +1,193 @@ | |||
| 1 | From d728fdc655f17031da3bb129ab2fd17dadf0fe3a Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Simon Peeters <peeters.simon@gmail.com> | ||
| 3 | Date: Sun, 7 Oct 2012 16:59:30 +0200 | ||
| 4 | Subject: [PATCH] Set correct address when using --address=systemd: | ||
| 5 | |||
| 6 | When dbus gets launched through systemd, we need to create an address | ||
| 7 | string based on the sockets passed. | ||
| 8 | |||
| 9 | The _dbus_append_addres_from_socket() function is responsible for | ||
| 10 | extracting the address information from the file-descriptor and | ||
| 11 | formatting it in a dbus friendly way. | ||
| 12 | |||
| 13 | This fixes bus activation when running dbus under a systemd session. | ||
| 14 | |||
| 15 | https://bugs.freedesktop.org/show_bug.cgi?id=50962 | ||
| 16 | |||
| 17 | Upstream-Status: Backport | ||
| 18 | |||
| 19 | Signed-off-by: Simon Peeters <peeters.simon@gmail.com> | ||
| 20 | Signed-off-by: Jonathan Liu <net147@gmail.com> | ||
| 21 | --- | ||
| 22 | dbus/dbus-server-unix.c | 38 ++++++++++++++++++--------- | ||
| 23 | dbus/dbus-sysdeps-unix.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ | ||
| 24 | dbus/dbus-sysdeps-unix.h | 4 +++ | ||
| 25 | 3 files changed, 97 insertions(+), 13 deletions(-) | ||
| 26 | |||
| 27 | diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c | ||
| 28 | index 130f66e..d995240 100644 | ||
| 29 | --- a/dbus/dbus-server-unix.c | ||
| 30 | +++ b/dbus/dbus-server-unix.c | ||
| 31 | @@ -149,7 +149,7 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, | ||
| 32 | } | ||
| 33 | else if (strcmp (method, "systemd") == 0) | ||
| 34 | { | ||
| 35 | - int n, *fds; | ||
| 36 | + int i, n, *fds; | ||
| 37 | DBusString address; | ||
| 38 | |||
| 39 | n = _dbus_listen_systemd_sockets (&fds, error); | ||
| 40 | @@ -159,27 +159,39 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry, | ||
| 41 | return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; | ||
| 42 | } | ||
| 43 | |||
| 44 | - _dbus_string_init_const (&address, "systemd:"); | ||
| 45 | + if (!_dbus_string_init (&address)) | ||
| 46 | + goto systemd_oom; | ||
| 47 | |||
| 48 | - *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL); | ||
| 49 | - if (*server_p == NULL) | ||
| 50 | + for (i = 0; i < n; i++) | ||
| 51 | { | ||
| 52 | - int i; | ||
| 53 | - | ||
| 54 | - for (i = 0; i < n; i++) | ||
| 55 | + if (i > 0) | ||
| 56 | { | ||
| 57 | - _dbus_close_socket (fds[i], NULL); | ||
| 58 | + if (!_dbus_string_append (&address, ";")) | ||
| 59 | + goto systemd_oom; | ||
| 60 | } | ||
| 61 | - dbus_free (fds); | ||
| 62 | - | ||
| 63 | - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL); | ||
| 64 | - return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; | ||
| 65 | + if (!_dbus_append_address_from_socket (fds[i], &address, error)) | ||
| 66 | + goto systemd_err; | ||
| 67 | } | ||
| 68 | |||
| 69 | + *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL); | ||
| 70 | + if (*server_p == NULL) | ||
| 71 | + goto systemd_oom; | ||
| 72 | + | ||
| 73 | dbus_free (fds); | ||
| 74 | |||
| 75 | return DBUS_SERVER_LISTEN_OK; | ||
| 76 | - } | ||
| 77 | + systemd_oom: | ||
| 78 | + _DBUS_SET_OOM (error); | ||
| 79 | + systemd_err: | ||
| 80 | + for (i = 0; i < n; i++) | ||
| 81 | + { | ||
| 82 | + _dbus_close_socket (fds[i], NULL); | ||
| 83 | + } | ||
| 84 | + dbus_free (fds); | ||
| 85 | + _dbus_string_free (&address); | ||
| 86 | + | ||
| 87 | + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT; | ||
| 88 | + } | ||
| 89 | #ifdef DBUS_ENABLE_LAUNCHD | ||
| 90 | else if (strcmp (method, "launchd") == 0) | ||
| 91 | { | ||
| 92 | diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c | ||
| 93 | index b4ecc96..55743b1 100644 | ||
| 94 | --- a/dbus/dbus-sysdeps-unix.c | ||
| 95 | +++ b/dbus/dbus-sysdeps-unix.c | ||
| 96 | @@ -55,6 +55,7 @@ | ||
| 97 | #include <netinet/in.h> | ||
| 98 | #include <netdb.h> | ||
| 99 | #include <grp.h> | ||
| 100 | +#include <arpa/inet.h> | ||
| 101 | |||
| 102 | #ifdef HAVE_ERRNO_H | ||
| 103 | #include <errno.h> | ||
| 104 | @@ -4160,4 +4161,71 @@ _dbus_check_setuid (void) | ||
| 105 | #endif | ||
| 106 | } | ||
| 107 | |||
| 108 | +/** | ||
| 109 | + * Read the address from the socket and append it to the string | ||
| 110 | + * | ||
| 111 | + * @param fd the socket | ||
| 112 | + * @param address | ||
| 113 | + * @param error return location for error code | ||
| 114 | + */ | ||
| 115 | +dbus_bool_t | ||
| 116 | +_dbus_append_address_from_socket (int fd, | ||
| 117 | + DBusString *address, | ||
| 118 | + DBusError *error) | ||
| 119 | +{ | ||
| 120 | + union { | ||
| 121 | + struct sockaddr sa; | ||
| 122 | + struct sockaddr_storage storage; | ||
| 123 | + struct sockaddr_un un; | ||
| 124 | + struct sockaddr_in ipv4; | ||
| 125 | + struct sockaddr_in6 ipv6; | ||
| 126 | + } socket; | ||
| 127 | + char hostip[INET6_ADDRSTRLEN]; | ||
| 128 | + int size = sizeof (socket); | ||
| 129 | + | ||
| 130 | + if (getsockname (fd, &socket.sa, &size)) | ||
| 131 | + goto err; | ||
| 132 | + | ||
| 133 | + switch (socket.sa.sa_family) | ||
| 134 | + { | ||
| 135 | + case AF_UNIX: | ||
| 136 | + if (socket.un.sun_path[0]=='\0') | ||
| 137 | + { | ||
| 138 | + if (_dbus_string_append_printf (address, "unix:abstract=%s", &(socket.un.sun_path[1]))) | ||
| 139 | + return TRUE; | ||
| 140 | + } | ||
| 141 | + else | ||
| 142 | + { | ||
| 143 | + if (_dbus_string_append_printf (address, "unix:path=%s", socket.un.sun_path)) | ||
| 144 | + return TRUE; | ||
| 145 | + } | ||
| 146 | + break; | ||
| 147 | + case AF_INET: | ||
| 148 | + if (inet_ntop (AF_INET, &socket.ipv4.sin_addr, hostip, sizeof (hostip))) | ||
| 149 | + if (_dbus_string_append_printf (address, "tcp:family=ipv4,host=%s,port=%u", | ||
| 150 | + hostip, ntohs (socket.ipv4.sin_port))) | ||
| 151 | + return TRUE; | ||
| 152 | + break; | ||
| 153 | +#ifdef AF_INET6 | ||
| 154 | + case AF_INET6: | ||
| 155 | + if (inet_ntop (AF_INET6, &socket.ipv6.sin6_addr, hostip, sizeof (hostip))) | ||
| 156 | + if (_dbus_string_append_printf (address, "tcp:family=ipv6,host=%s,port=%u", | ||
| 157 | + hostip, ntohs (socket.ipv6.sin6_port))) | ||
| 158 | + return TRUE; | ||
| 159 | + break; | ||
| 160 | +#endif | ||
| 161 | + default: | ||
| 162 | + dbus_set_error (error, | ||
| 163 | + _dbus_error_from_errno (EINVAL), | ||
| 164 | + "Failed to read address from socket: Unknown socket type."); | ||
| 165 | + return FALSE; | ||
| 166 | + } | ||
| 167 | + err: | ||
| 168 | + dbus_set_error (error, | ||
| 169 | + _dbus_error_from_errno (errno), | ||
| 170 | + "Failed to open socket: %s", | ||
| 171 | + _dbus_strerror (errno)); | ||
| 172 | + return FALSE; | ||
| 173 | +} | ||
| 174 | + | ||
| 175 | /* tests in dbus-sysdeps-util.c */ | ||
| 176 | diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h | ||
| 177 | index 9b70896..a265b33 100644 | ||
| 178 | --- a/dbus/dbus-sysdeps-unix.h | ||
| 179 | +++ b/dbus/dbus-sysdeps-unix.h | ||
| 180 | @@ -138,6 +138,10 @@ dbus_bool_t _dbus_parse_uid (const DBusString *uid_str, | ||
| 181 | |||
| 182 | void _dbus_close_all (void); | ||
| 183 | |||
| 184 | +dbus_bool_t _dbus_append_address_from_socket (int fd, | ||
| 185 | + DBusString *address, | ||
| 186 | + DBusError *error); | ||
| 187 | + | ||
| 188 | /** @} */ | ||
| 189 | |||
| 190 | DBUS_END_DECLS | ||
| 191 | -- | ||
| 192 | 1.9.0 | ||
| 193 | |||
