Lines Matching refs:b
65 static void bus_detach_io_events(sd_bus *b);
129 void bus_close_io_fds(sd_bus *b) { in bus_close_io_fds() argument
130 assert(b); in bus_close_io_fds()
132 bus_detach_io_events(b); in bus_close_io_fds()
134 if (b->input_fd != b->output_fd) in bus_close_io_fds()
135 safe_close(b->output_fd); in bus_close_io_fds()
136 b->output_fd = b->input_fd = safe_close(b->input_fd); in bus_close_io_fds()
139 void bus_close_inotify_fd(sd_bus *b) { in bus_close_inotify_fd() argument
140 assert(b); in bus_close_inotify_fd()
142 b->inotify_event_source = sd_event_source_disable_unref(b->inotify_event_source); in bus_close_inotify_fd()
144 b->inotify_fd = safe_close(b->inotify_fd); in bus_close_inotify_fd()
145 b->inotify_watches = mfree(b->inotify_watches); in bus_close_inotify_fd()
146 b->n_inotify_watches = 0; in bus_close_inotify_fd()
149 static void bus_reset_queues(sd_bus *b) { in bus_reset_queues() argument
150 assert(b); in bus_reset_queues()
152 while (b->rqueue_size > 0) in bus_reset_queues()
153 bus_message_unref_queued(b->rqueue[--b->rqueue_size], b); in bus_reset_queues()
155 b->rqueue = mfree(b->rqueue); in bus_reset_queues()
157 while (b->wqueue_size > 0) in bus_reset_queues()
158 bus_message_unref_queued(b->wqueue[--b->wqueue_size], b); in bus_reset_queues()
160 b->wqueue = mfree(b->wqueue); in bus_reset_queues()
163 static sd_bus* bus_free(sd_bus *b) { in bus_free() argument
166 assert(b); in bus_free()
167 assert(!b->track_queue); in bus_free()
168 assert(!b->tracks); in bus_free()
170 b->state = BUS_CLOSED; in bus_free()
172 sd_bus_detach_event(b); in bus_free()
174 while ((s = b->slots)) { in bus_free()
186 if (b->default_bus_ptr) in bus_free()
187 *b->default_bus_ptr = NULL; in bus_free()
189 bus_close_io_fds(b); in bus_free()
190 bus_close_inotify_fd(b); in bus_free()
192 free(b->label); in bus_free()
193 free(b->groups); in bus_free()
194 free(b->rbuffer); in bus_free()
195 free(b->unique_name); in bus_free()
196 free(b->auth_buffer); in bus_free()
197 free(b->address); in bus_free()
198 free(b->machine); in bus_free()
199 free(b->description); in bus_free()
200 free(b->patch_sender); in bus_free()
202 free(b->exec_path); in bus_free()
203 strv_free(b->exec_argv); in bus_free()
205 close_many(b->fds, b->n_fds); in bus_free()
206 free(b->fds); in bus_free()
208 bus_reset_queues(b); in bus_free()
210 ordered_hashmap_free_free(b->reply_callbacks); in bus_free()
211 prioq_free(b->reply_callbacks_prioq); in bus_free()
213 assert(b->match_callbacks.type == BUS_MATCH_ROOT); in bus_free()
214 bus_match_free(&b->match_callbacks); in bus_free()
216 hashmap_free_free(b->vtable_methods); in bus_free()
217 hashmap_free_free(b->vtable_properties); in bus_free()
219 assert(hashmap_isempty(b->nodes)); in bus_free()
220 hashmap_free(b->nodes); in bus_free()
222 bus_flush_memfd(b); in bus_free()
224 assert_se(pthread_mutex_destroy(&b->memfd_cache_mutex) == 0); in bus_free()
226 return mfree(b); in bus_free()
232 _cleanup_free_ sd_bus *b = NULL; in sd_bus_new() local
236 b = new(sd_bus, 1); in sd_bus_new()
237 if (!b) in sd_bus_new()
240 *b = (sd_bus) { in sd_bus_new()
255 if (!GREEDY_REALLOC(b->wqueue, 1)) in sd_bus_new()
258 assert_se(pthread_mutex_init(&b->memfd_cache_mutex, NULL) == 0); in sd_bus_new()
260 *ret = TAKE_PTR(b); in sd_bus_new()
309 _public_ int sd_bus_set_bus_client(sd_bus *bus, int b) { in sd_bus_set_bus_client() argument
316 bus->bus_client = !!b; in sd_bus_set_bus_client()
320 _public_ int sd_bus_set_monitor(sd_bus *bus, int b) { in sd_bus_set_monitor() argument
326 bus->is_monitor = !!b; in sd_bus_set_monitor()
330 _public_ int sd_bus_negotiate_fds(sd_bus *bus, int b) { in sd_bus_negotiate_fds() argument
336 bus->accept_fd = !!b; in sd_bus_negotiate_fds()
340 _public_ int sd_bus_negotiate_timestamp(sd_bus *bus, int b) { in sd_bus_negotiate_timestamp() argument
348 bus->attach_timestamp = !!b; in sd_bus_negotiate_timestamp()
353 _public_ int sd_bus_negotiate_creds(sd_bus *bus, int b, uint64_t mask) { in sd_bus_negotiate_creds() argument
360 SET_FLAG(bus->creds_mask, mask, b); in sd_bus_negotiate_creds()
368 _public_ int sd_bus_set_server(sd_bus *bus, int b, sd_id128_t server_id) { in sd_bus_set_server() argument
371 assert_return(b || sd_id128_equal(server_id, SD_ID128_NULL), -EINVAL); in sd_bus_set_server()
375 bus->is_server = !!b; in sd_bus_set_server()
380 _public_ int sd_bus_set_anonymous(sd_bus *bus, int b) { in sd_bus_set_anonymous() argument
386 bus->anonymous_auth = !!b; in sd_bus_set_anonymous()
390 _public_ int sd_bus_set_trusted(sd_bus *bus, int b) { in sd_bus_set_trusted() argument
396 bus->trusted = !!b; in sd_bus_set_trusted()
409 _public_ int sd_bus_set_allow_interactive_authorization(sd_bus *bus, int b) { in sd_bus_set_allow_interactive_authorization() argument
414 bus->allow_interactive_authorization = !!b; in sd_bus_set_allow_interactive_authorization()
426 _public_ int sd_bus_set_watch_bind(sd_bus *bus, int b) { in sd_bus_set_watch_bind() argument
432 bus->watch_bind = !!b; in sd_bus_set_watch_bind()
444 _public_ int sd_bus_set_connected_signal(sd_bus *bus, int b) { in sd_bus_set_connected_signal() argument
450 bus->connected_signal = !!b; in sd_bus_set_connected_signal()
710 static int parse_unix_address(sd_bus *b, const char **p, char **guid) { in parse_unix_address() argument
715 assert(b); in parse_unix_address()
750 if (l >= sizeof(b->sockaddr.un.sun_path)) /* We insist on NUL termination */ in parse_unix_address()
753 b->sockaddr.un = (struct sockaddr_un) { in parse_unix_address()
757 memcpy(b->sockaddr.un.sun_path, path, l); in parse_unix_address()
758 b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l + 1; in parse_unix_address()
764 if (l >= sizeof(b->sockaddr.un.sun_path) - 1) /* We insist on NUL termination */ in parse_unix_address()
767 b->sockaddr.un = (struct sockaddr_un) { in parse_unix_address()
771 memcpy(b->sockaddr.un.sun_path+1, abstract, l); in parse_unix_address()
772 b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + 1 + l; in parse_unix_address()
775 b->is_local = true; in parse_unix_address()
780 static int parse_tcp_address(sd_bus *b, const char **p, char **guid) { in parse_tcp_address() argument
787 assert(b); in parse_tcp_address()
835 memcpy(&b->sockaddr, result->ai_addr, result->ai_addrlen); in parse_tcp_address()
836 b->sockaddr_size = result->ai_addrlen; in parse_tcp_address()
840 b->is_local = false; in parse_tcp_address()
845 static int parse_exec_address(sd_bus *b, const char **p, char **guid) { in parse_exec_address() argument
851 assert(b); in parse_exec_address()
921 b->exec_path = path; in parse_exec_address()
922 b->exec_argv = argv; in parse_exec_address()
924 b->is_local = false; in parse_exec_address()
937 static int parse_container_unix_address(sd_bus *b, const char **p, char **guid) { in parse_container_unix_address() argument
941 assert(b); in parse_container_unix_address()
975 free_and_replace(b->machine, machine); in parse_container_unix_address()
977 b->machine = mfree(b->machine); in parse_container_unix_address()
980 r = parse_pid(pid, &b->nspid); in parse_container_unix_address()
984 b->nspid = 0; in parse_container_unix_address()
986 b->sockaddr.un = (struct sockaddr_un) { in parse_container_unix_address()
991 b->sockaddr_size = SOCKADDR_UN_LEN(b->sockaddr.un); in parse_container_unix_address()
992 b->is_local = false; in parse_container_unix_address()
997 static void bus_reset_parsed_address(sd_bus *b) { in bus_reset_parsed_address() argument
998 assert(b); in bus_reset_parsed_address()
1000 zero(b->sockaddr); in bus_reset_parsed_address()
1001 b->sockaddr_size = 0; in bus_reset_parsed_address()
1002 b->exec_argv = strv_free(b->exec_argv); in bus_reset_parsed_address()
1003 b->exec_path = mfree(b->exec_path); in bus_reset_parsed_address()
1004 b->server_id = SD_ID128_NULL; in bus_reset_parsed_address()
1005 b->machine = mfree(b->machine); in bus_reset_parsed_address()
1006 b->nspid = 0; in bus_reset_parsed_address()
1009 static int bus_parse_next_address(sd_bus *b) { in bus_parse_next_address() argument
1014 assert(b); in bus_parse_next_address()
1016 if (!b->address) in bus_parse_next_address()
1018 if (b->address[b->address_index] == 0) in bus_parse_next_address()
1021 bus_reset_parsed_address(b); in bus_parse_next_address()
1023 a = b->address + b->address_index; in bus_parse_next_address()
1035 r = parse_unix_address(b, &a, &guid); in bus_parse_next_address()
1043 r = parse_tcp_address(b, &a, &guid); in bus_parse_next_address()
1052 r = parse_exec_address(b, &a, &guid); in bus_parse_next_address()
1061 r = parse_container_unix_address(b, &a, &guid); in bus_parse_next_address()
1074 r = sd_id128_from_string(guid, &b->server_id); in bus_parse_next_address()
1079 b->address_index = a - b->address; in bus_parse_next_address()
1090 static int bus_start_address(sd_bus *b) { in bus_start_address() argument
1093 assert(b); in bus_start_address()
1096 bus_close_io_fds(b); in bus_start_address()
1097 bus_close_inotify_fd(b); in bus_start_address()
1099 bus_kill_exec(b); in bus_start_address()
1105 if (b->exec_path) in bus_start_address()
1106 r = bus_socket_exec(b); in bus_start_address()
1107 else if ((b->nspid > 0 || b->machine) && b->sockaddr.sa.sa_family != AF_UNSPEC) in bus_start_address()
1108 r = bus_container_connect_socket(b); in bus_start_address()
1109 else if (b->sockaddr.sa.sa_family != AF_UNSPEC) in bus_start_address()
1110 r = bus_socket_connect(b); in bus_start_address()
1117 q = bus_attach_io_events(b); in bus_start_address()
1121 q = bus_attach_inotify_event(b); in bus_start_address()
1128 b->last_connect_error = -r; in bus_start_address()
1131 r = bus_parse_next_address(b); in bus_start_address()
1135 return b->last_connect_error > 0 ? -b->last_connect_error : -ECONNREFUSED; in bus_start_address()
1139 int bus_next_address(sd_bus *b) { in bus_next_address() argument
1140 assert(b); in bus_next_address()
1142 bus_reset_parsed_address(b); in bus_next_address()
1143 return bus_start_address(b); in bus_next_address()
1146 static int bus_start_fd(sd_bus *b) { in bus_start_fd() argument
1150 assert(b); in bus_start_fd()
1151 assert(b->input_fd >= 0); in bus_start_fd()
1152 assert(b->output_fd >= 0); in bus_start_fd()
1156 (void) fd_get_path(b->input_fd, &pi); in bus_start_fd()
1157 (void) fd_get_path(b->output_fd, &po); in bus_start_fd()
1159 b->description ? " " : "", strempty(b->description), in bus_start_fd()
1160 b->input_fd, b->output_fd, in bus_start_fd()
1164 r = fd_nonblock(b->input_fd, true); in bus_start_fd()
1168 r = fd_cloexec(b->input_fd, true); in bus_start_fd()
1172 if (b->input_fd != b->output_fd) { in bus_start_fd()
1173 r = fd_nonblock(b->output_fd, true); in bus_start_fd()
1177 r = fd_cloexec(b->output_fd, true); in bus_start_fd()
1182 if (fstat(b->input_fd, &st) < 0) in bus_start_fd()
1185 return bus_socket_take_fd(b); in bus_start_fd()
1218 _cleanup_(bus_freep) sd_bus *b = NULL; in sd_bus_open_with_description()
1243 r = sd_bus_new(&b); in sd_bus_open_with_description()
1247 r = sd_bus_set_address(b, e); in sd_bus_open_with_description()
1251 b->bus_client = true; in sd_bus_open_with_description()
1255 b->trusted = false; in sd_bus_open_with_description()
1256 b->is_local = false; in sd_bus_open_with_description()
1257 b->creds_mask |= SD_BUS_CREDS_UID | SD_BUS_CREDS_EUID | SD_BUS_CREDS_EFFECTIVE_CAPS; in sd_bus_open_with_description()
1259 r = sd_bus_start(b); in sd_bus_open_with_description()
1263 *ret = TAKE_PTR(b); in sd_bus_open_with_description()
1271 int bus_set_address_system(sd_bus *b) { in bus_set_address_system() argument
1275 assert(b); in bus_set_address_system()
1279 r = sd_bus_set_address(b, e ?: DEFAULT_SYSTEM_BUS_ADDRESS); in bus_set_address_system()
1281 b->is_system = true; in bus_set_address_system()
1286 _cleanup_(bus_freep) sd_bus *b = NULL; in sd_bus_open_system_with_description()
1291 r = sd_bus_new(&b); in sd_bus_open_system_with_description()
1296 r = sd_bus_set_description(b, description); in sd_bus_open_system_with_description()
1301 r = bus_set_address_system(b); in sd_bus_open_system_with_description()
1305 b->bus_client = true; in sd_bus_open_system_with_description()
1309 b->trusted = false; in sd_bus_open_system_with_description()
1310 b->creds_mask |= SD_BUS_CREDS_UID | SD_BUS_CREDS_EUID | SD_BUS_CREDS_EFFECTIVE_CAPS; in sd_bus_open_system_with_description()
1311 b->is_local = true; in sd_bus_open_system_with_description()
1313 r = sd_bus_start(b); in sd_bus_open_system_with_description()
1317 *ret = TAKE_PTR(b); in sd_bus_open_system_with_description()
1325 int bus_set_address_user(sd_bus *b) { in bus_set_address_user() argument
1330 assert(b); in bus_set_address_user()
1351 r = sd_bus_set_address(b, a); in bus_set_address_user()
1353 b->is_user = true; in bus_set_address_user()
1358 _cleanup_(bus_freep) sd_bus *b = NULL; in sd_bus_open_user_with_description()
1363 r = sd_bus_new(&b); in sd_bus_open_user_with_description()
1368 r = sd_bus_set_description(b, description); in sd_bus_open_user_with_description()
1373 r = bus_set_address_user(b); in sd_bus_open_user_with_description()
1377 b->bus_client = true; in sd_bus_open_user_with_description()
1380 b->trusted = true; in sd_bus_open_user_with_description()
1381 b->is_local = true; in sd_bus_open_user_with_description()
1383 r = sd_bus_start(b); in sd_bus_open_user_with_description()
1387 *ret = TAKE_PTR(b); in sd_bus_open_user_with_description()
1395 int bus_set_address_system_remote(sd_bus *b, const char *host) { in bus_set_address_system_remote() argument
1399 assert(b); in bus_set_address_system_remote()
1482 return free_and_replace(b->address, a); in bus_set_address_system_remote()
1486 _cleanup_(bus_freep) sd_bus *b = NULL; in sd_bus_open_system_remote()
1492 r = sd_bus_new(&b); in sd_bus_open_system_remote()
1496 r = bus_set_address_system_remote(b, host); in sd_bus_open_system_remote()
1500 b->bus_client = true; in sd_bus_open_system_remote()
1501 b->trusted = false; in sd_bus_open_system_remote()
1502 b->is_system = true; in sd_bus_open_system_remote()
1503 b->is_local = false; in sd_bus_open_system_remote()
1505 r = sd_bus_start(b); in sd_bus_open_system_remote()
1509 *ret = TAKE_PTR(b); in sd_bus_open_system_remote()
1513 int bus_set_address_machine(sd_bus *b, bool user, const char *machine) { in bus_set_address_machine() argument
1517 assert(b); in bus_set_address_machine()
1600 return free_and_replace(b->address, a); in bus_set_address_machine()
1676 _cleanup_(bus_freep) sd_bus *b = NULL; in sd_bus_open_system_machine()
1691 r = sd_bus_new(&b); in sd_bus_open_system_machine()
1695 r = bus_set_address_machine(b, false, user_and_machine); in sd_bus_open_system_machine()
1699 b->bus_client = true; in sd_bus_open_system_machine()
1700 b->is_system = true; in sd_bus_open_system_machine()
1702 r = sd_bus_start(b); in sd_bus_open_system_machine()
1706 *ret = TAKE_PTR(b); in sd_bus_open_system_machine()
1711 _cleanup_(bus_freep) sd_bus *b = NULL; in sd_bus_open_user_machine()
1727 r = sd_bus_new(&b); in sd_bus_open_user_machine()
1731 r = bus_set_address_machine(b, true, user_and_machine); in sd_bus_open_user_machine()
1735 b->bus_client = true; in sd_bus_open_user_machine()
1736 b->trusted = true; in sd_bus_open_user_machine()
1738 r = sd_bus_start(b); in sd_bus_open_user_machine()
1742 *ret = TAKE_PTR(b); in sd_bus_open_user_machine()
1873 static int next_cookie(sd_bus *b) { in next_cookie() argument
1876 assert(b); in next_cookie()
1878 new_cookie = cookie_inc(b->cookie); in next_cookie()
1887 if (!ordered_hashmap_contains(b->reply_callbacks, &new_cookie)) in next_cookie()
1898 b->cookie = new_cookie; in next_cookie()
1902 static int bus_seal_message(sd_bus *b, sd_bus_message *m, usec_t timeout) { in bus_seal_message() argument
1905 assert(b); in bus_seal_message()
1912 b->cookie = MAX(b->cookie, BUS_MESSAGE_COOKIE(m)); in bus_seal_message()
1917 r = sd_bus_get_method_call_timeout(b, &timeout); in bus_seal_message()
1922 if (!m->sender && b->patch_sender) { in bus_seal_message()
1923 r = sd_bus_message_set_sender(m, b->patch_sender); in bus_seal_message()
1928 r = next_cookie(b); in bus_seal_message()
1932 return sd_bus_message_seal(m, b->cookie, timeout); in bus_seal_message()
1935 static int bus_remarshal_message(sd_bus *b, sd_bus_message **m) { in bus_remarshal_message() argument
1938 assert(b); in bus_remarshal_message()
1941 if (b->message_version != 0 && b->message_version != (*m)->header->version) in bus_remarshal_message()
1945 if (b->message_endian != 0 && b->message_endian != (*m)->header->endian) in bus_remarshal_message()
1948 return remarshal ? bus_message_remarshal(b, m) : 0; in bus_remarshal_message()
1951 int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m) { in bus_seal_synthetic_message() argument
1952 assert(b); in bus_seal_synthetic_message()
1957 if (b->attach_timestamp) { in bus_seal_synthetic_message()
2225 static int timeout_compare(const void *a, const void *b) { in timeout_compare() argument
2226 const struct reply_callback *x = a, *y = b; in timeout_compare()
3884 sd_bus *b = NULL; in bus_default() local
3898 r = bus_open(&b); in bus_default()
3902 b->default_bus_ptr = default_bus; in bus_default()
3903 b->tid = gettid(); in bus_default()
3904 *default_bus = b; in bus_default()
3906 *ret = b; in bus_default()
3926 _public_ int sd_bus_get_tid(sd_bus *b, pid_t *tid) { in sd_bus_get_tid() argument
3927 assert_return(b, -EINVAL); in sd_bus_get_tid()
3929 assert_return(!bus_pid_changed(b), -ECHILD); in sd_bus_get_tid()
3931 if (b->tid != 0) { in sd_bus_get_tid()
3932 *tid = b->tid; in sd_bus_get_tid()
3936 if (b->event) in sd_bus_get_tid()
3937 return sd_event_get_tid(b->event, tid); in sd_bus_get_tid()
4279 _public_ int sd_bus_set_exit_on_disconnect(sd_bus *bus, int b) { in sd_bus_set_exit_on_disconnect() argument
4286 bus->exit_on_disconnect = b; in sd_bus_set_exit_on_disconnect()
4373 _public_ int sd_bus_set_close_on_exit(sd_bus *bus, int b) { in sd_bus_set_close_on_exit() argument
4377 bus->close_on_exit = b; in sd_bus_set_close_on_exit()