summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch')
-rw-r--r--meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch193
1 files changed, 193 insertions, 0 deletions
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 0000000..1fca9bb
--- /dev/null
+++ b/meta/recipes-core/dbus/dbus/Set-correct-address-when-using-address-systemd.patch
@@ -0,0 +1,193 @@
1From d728fdc655f17031da3bb129ab2fd17dadf0fe3a Mon Sep 17 00:00:00 2001
2From: Simon Peeters <peeters.simon@gmail.com>
3Date: Sun, 7 Oct 2012 16:59:30 +0200
4Subject: [PATCH] Set correct address when using --address=systemd:
5
6When dbus gets launched through systemd, we need to create an address
7string based on the sockets passed.
8
9The _dbus_append_addres_from_socket() function is responsible for
10extracting the address information from the file-descriptor and
11formatting it in a dbus friendly way.
12
13This fixes bus activation when running dbus under a systemd session.
14
15https://bugs.freedesktop.org/show_bug.cgi?id=50962
16
17Upstream-Status: Backport
18
19Signed-off-by: Simon Peeters <peeters.simon@gmail.com>
20Signed-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
27diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c
28index 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 {
92diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
93index 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 */
176diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h
177index 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--
1921.9.0
193