1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
6 This file is part of systemd.
8 Copyright 2013 Lennart Poettering
10 systemd is free software; you can redistribute it and/or modify it
11 under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
15 systemd is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
24 #include <sys/socket.h>
26 #include <netinet/in.h>
36 #include "bus-error.h"
37 #include "bus-match.h"
38 #include "bus-kernel.h"
40 struct reply_callback {
41 sd_bus_message_handler_t callback;
48 struct filter_callback {
49 sd_bus_message_handler_t callback;
52 unsigned last_iteration;
54 LIST_FIELDS(struct filter_callback, callbacks);
57 struct object_callback {
58 sd_bus_message_handler_t callback;
64 unsigned last_iteration;
76 static inline bool BUS_IS_OPEN(enum bus_state state) {
77 return state > BUS_UNSET && state < BUS_CLOSED;
87 /* We use atomic ref counting here since sd_bus_message
88 objects retain references to their originating sd_bus but
89 we want to allow them to be processed in a different
90 thread. We won't provide full thread safety, but only the
91 bare minimum that makes it possible to use sd_bus and
92 sd_bus_message objects independently and on different
93 threads as long as each object is used only once at the
98 int input_fd, output_fd;
106 bool anonymous_auth:1;
108 bool prefer_writev:1;
110 bool match_callbacks_modified:1;
111 bool filter_callbacks_modified:1;
112 bool object_callbacks_modified:1;
119 sd_bus_message **rqueue;
120 unsigned rqueue_size;
122 sd_bus_message **wqueue;
123 unsigned wqueue_size;
130 struct bus_match_node match_callbacks;
131 Prioq *reply_callbacks_prioq;
132 Hashmap *reply_callbacks;
133 LIST_HEAD(struct filter_callback, filter_callbacks);
134 Hashmap *object_callbacks;
138 struct sockaddr_un un;
139 struct sockaddr_in in;
140 struct sockaddr_in6 in6;
142 socklen_t sockaddr_size;
146 sd_id128_t server_id;
149 unsigned address_index;
151 int last_connect_error;
155 struct iovec auth_iovec[3];
161 char label[NAME_MAX];
169 uint64_t hello_serial;
170 unsigned iteration_counter;
174 /* We do locking around the memfd cache, since we want to
175 * allow people to process a sd_bus_message in a different
176 * thread then it was generated on and free it there. Since
177 * adding something to the memfd cache might happen when a
178 * message is released, we hence need to protect this bit with
180 pthread_mutex_t memfd_cache_mutex;
181 struct memfd_cache memfd_cache[MEMFD_CACHE_MAX];
182 unsigned n_memfd_cache;
186 uint64_t hello_flags;
188 uint64_t match_cookie;
191 static inline void bus_unrefp(sd_bus **b) {
195 #define _cleanup_bus_unref_ __attribute__((cleanup(bus_unrefp)))
196 #define _cleanup_bus_error_free_ __attribute__((cleanup(sd_bus_error_free)))
198 #define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
200 #define BUS_WQUEUE_MAX 128
201 #define BUS_RQUEUE_MAX 128
203 #define BUS_MESSAGE_SIZE_MAX (64*1024*1024)
204 #define BUS_AUTH_SIZE_MAX (64*1024)
206 #define BUS_CONTAINER_DEPTH 128
208 /* Defined by the specification as maximum size of an array in
210 #define BUS_ARRAY_MAX_SIZE 67108864
212 #define BUS_FDS_MAX 1024
214 #define BUS_EXEC_ARGV_MAX 256
216 bool object_path_is_valid(const char *p);
217 bool interface_name_is_valid(const char *p);
218 bool service_name_is_valid(const char *p);
219 bool member_name_is_valid(const char *p);
221 bool namespace_complex_pattern(const char *pattern, const char *value);
222 bool path_complex_pattern(const char *pattern, const char *value);
224 bool namespace_simple_pattern(const char *pattern, const char *value);
225 bool path_simple_pattern(const char *pattern, const char *value);
227 int bus_message_type_from_string(const char *s, uint8_t *u);
228 const char *bus_message_type_to_string(uint8_t u);
230 #define error_name_is_valid interface_name_is_valid
232 int bus_ensure_running(sd_bus *bus);
233 int bus_start_running(sd_bus *bus);
234 int bus_next_address(sd_bus *bus);
236 bool bus_pid_changed(sd_bus *bus);