Magellan Linux

Contents of /trunk/dbus/patches/dbus-1.6.16-systemd-user-session.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2312 - (show annotations) (download)
Mon Oct 21 13:05:31 2013 UTC (10 years, 6 months ago) by niro
File size: 5575 byte(s)
-fixed systemd issues
1 commit d728fdc655f17031da3bb129ab2fd17dadf0fe3a
2 Author: Simon Peeters <peeters.simon@gmail.com>
3 Date: 8 weeks ago
4
5 Set correct address when using --address=systemd:
6
7 When dbus gets launched through systemd, we need to create an address
8 string based on the sockets passed.
9
10 The _dbus_append_addres_from_socket() function is responsible for
11 extracting the address information from the file-descriptor and
12 formatting it in a dbus friendly way.
13
14 This fixes bus activation when running dbus under a systemd session.
15
16 https://bugs.freedesktop.org/show_bug.cgi?id=50962
17
18 Signed-off-by: Simon Peeters <peeters.simon@gmail.com>
19
20 diff --git a/dbus/dbus-server-unix.c b/dbus/dbus-server-unix.c
21 index 130f66e..d995240 100644
22 --- a/dbus/dbus-server-unix.c
23 +++ b/dbus/dbus-server-unix.c
24 @@ -149,7 +149,7 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
25 }
26 else if (strcmp (method, "systemd") == 0)
27 {
28 - int n, *fds;
29 + int i, n, *fds;
30 DBusString address;
31
32 n = _dbus_listen_systemd_sockets (&fds, error);
33 @@ -159,27 +159,39 @@ _dbus_server_listen_platform_specific (DBusAddressEntry *entry,
34 return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
35 }
36
37 - _dbus_string_init_const (&address, "systemd:");
38 + if (!_dbus_string_init (&address))
39 + goto systemd_oom;
40
41 - *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL);
42 - if (*server_p == NULL)
43 + for (i = 0; i < n; i++)
44 {
45 - int i;
46 -
47 - for (i = 0; i < n; i++)
48 + if (i > 0)
49 {
50 - _dbus_close_socket (fds[i], NULL);
51 + if (!_dbus_string_append (&address, ";"))
52 + goto systemd_oom;
53 }
54 - dbus_free (fds);
55 -
56 - dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
57 - return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
58 + if (!_dbus_append_address_from_socket (fds[i], &address, error))
59 + goto systemd_err;
60 }
61
62 + *server_p = _dbus_server_new_for_socket (fds, n, &address, NULL);
63 + if (*server_p == NULL)
64 + goto systemd_oom;
65 +
66 dbus_free (fds);
67
68 return DBUS_SERVER_LISTEN_OK;
69 - }
70 + systemd_oom:
71 + _DBUS_SET_OOM (error);
72 + systemd_err:
73 + for (i = 0; i < n; i++)
74 + {
75 + _dbus_close_socket (fds[i], NULL);
76 + }
77 + dbus_free (fds);
78 + _dbus_string_free (&address);
79 +
80 + return DBUS_SERVER_LISTEN_DID_NOT_CONNECT;
81 + }
82 #ifdef DBUS_ENABLE_LAUNCHD
83 else if (strcmp (method, "launchd") == 0)
84 {
85 diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c
86 index b4ecc96..55743b1 100644
87 --- a/dbus/dbus-sysdeps-unix.c
88 +++ b/dbus/dbus-sysdeps-unix.c
89 @@ -55,6 +55,7 @@
90 #include <netinet/in.h>
91 #include <netdb.h>
92 #include <grp.h>
93 +#include <arpa/inet.h>
94
95 #ifdef HAVE_ERRNO_H
96 #include <errno.h>
97 @@ -4160,4 +4161,71 @@ _dbus_check_setuid (void)
98 #endif
99 }
100
101 +/**
102 + * Read the address from the socket and append it to the string
103 + *
104 + * @param fd the socket
105 + * @param address
106 + * @param error return location for error code
107 + */
108 +dbus_bool_t
109 +_dbus_append_address_from_socket (int fd,
110 + DBusString *address,
111 + DBusError *error)
112 +{
113 + union {
114 + struct sockaddr sa;
115 + struct sockaddr_storage storage;
116 + struct sockaddr_un un;
117 + struct sockaddr_in ipv4;
118 + struct sockaddr_in6 ipv6;
119 + } socket;
120 + char hostip[INET6_ADDRSTRLEN];
121 + int size = sizeof (socket);
122 +
123 + if (getsockname (fd, &socket.sa, &size))
124 + goto err;
125 +
126 + switch (socket.sa.sa_family)
127 + {
128 + case AF_UNIX:
129 + if (socket.un.sun_path[0]=='\0')
130 + {
131 + if (_dbus_string_append_printf (address, "unix:abstract=%s", &(socket.un.sun_path[1])))
132 + return TRUE;
133 + }
134 + else
135 + {
136 + if (_dbus_string_append_printf (address, "unix:path=%s", socket.un.sun_path))
137 + return TRUE;
138 + }
139 + break;
140 + case AF_INET:
141 + if (inet_ntop (AF_INET, &socket.ipv4.sin_addr, hostip, sizeof (hostip)))
142 + if (_dbus_string_append_printf (address, "tcp:family=ipv4,host=%s,port=%u",
143 + hostip, ntohs (socket.ipv4.sin_port)))
144 + return TRUE;
145 + break;
146 +#ifdef AF_INET6
147 + case AF_INET6:
148 + if (inet_ntop (AF_INET6, &socket.ipv6.sin6_addr, hostip, sizeof (hostip)))
149 + if (_dbus_string_append_printf (address, "tcp:family=ipv6,host=%s,port=%u",
150 + hostip, ntohs (socket.ipv6.sin6_port)))
151 + return TRUE;
152 + break;
153 +#endif
154 + default:
155 + dbus_set_error (error,
156 + _dbus_error_from_errno (EINVAL),
157 + "Failed to read address from socket: Unknown socket type.");
158 + return FALSE;
159 + }
160 + err:
161 + dbus_set_error (error,
162 + _dbus_error_from_errno (errno),
163 + "Failed to open socket: %s",
164 + _dbus_strerror (errno));
165 + return FALSE;
166 +}
167 +
168 /* tests in dbus-sysdeps-util.c */
169 diff --git a/dbus/dbus-sysdeps-unix.h b/dbus/dbus-sysdeps-unix.h
170 index 9b70896..a265b33 100644
171 --- a/dbus/dbus-sysdeps-unix.h
172 +++ b/dbus/dbus-sysdeps-unix.h
173 @@ -138,6 +138,10 @@ dbus_bool_t _dbus_parse_uid (const DBusString *uid_str,
174
175 void _dbus_close_all (void);
176
177 +dbus_bool_t _dbus_append_address_from_socket (int fd,
178 + DBusString *address,
179 + DBusError *error);
180 +
181 /** @} */
182
183 DBUS_END_DECLS