]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/shared/bus-util.h
Merge pull request #17185 from yuwata/ethtool-update
[thirdparty/systemd.git] / src / shared / bus-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 #include <stdbool.h>
5 #include <stddef.h>
6 #include <stdint.h>
7 #include <sys/types.h>
8
9 #include "sd-bus.h"
10 #include "sd-event.h"
11
12 #include "macro.h"
13 #include "string-util.h"
14 #include "time-util.h"
15
16 typedef enum BusTransport {
17 BUS_TRANSPORT_LOCAL,
18 BUS_TRANSPORT_REMOTE,
19 BUS_TRANSPORT_MACHINE,
20 _BUS_TRANSPORT_MAX,
21 _BUS_TRANSPORT_INVALID = -1
22 } BusTransport;
23
24 int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name);
25
26 typedef bool (*check_idle_t)(void *userdata);
27
28 int bus_event_loop_with_idle(sd_event *e, sd_bus *bus, const char *name, usec_t timeout, check_idle_t check_idle, void *userdata);
29
30 int bus_name_has_owner(sd_bus *c, const char *name, sd_bus_error *error);
31 bool bus_error_is_unknown_service(const sd_bus_error *error);
32
33 int bus_check_peercred(sd_bus *c);
34
35 int bus_connect_system_systemd(sd_bus **_bus);
36 int bus_connect_user_systemd(sd_bus **_bus);
37
38 int bus_connect_transport(BusTransport transport, const char *host, bool user, sd_bus **bus);
39 int bus_connect_transport_systemd(BusTransport transport, const char *host, bool user, sd_bus **bus);
40
41 #define bus_log_address_error(r) \
42 log_error_errno(r, \
43 r == -ENOMEDIUM ? "Failed to set bus address: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined" : \
44 "Failed to set bus address: %m")
45 #define bus_log_connect_error(r) \
46 log_error_errno(r, \
47 r == -ENOMEDIUM ? "Failed to connect to bus: $DBUS_SESSION_BUS_ADDRESS and $XDG_RUNTIME_DIR not defined" : \
48 "Failed to connect to bus: %m")
49
50 #define bus_log_parse_error(r) \
51 log_error_errno(r, "Failed to parse bus message: %m")
52
53 #define bus_log_create_error(r) \
54 log_error_errno(r, "Failed to create bus message: %m")
55
56 int bus_path_encode_unique(sd_bus *b, const char *prefix, const char *sender_id, const char *external_id, char **ret_path);
57 int bus_path_decode_unique(const char *path, const char *prefix, char **ret_sender, char **ret_external);
58
59 int bus_track_add_name_many(sd_bus_track *t, char **l);
60
61 int bus_open_system_watch_bind_with_description(sd_bus **ret, const char *description);
62 static inline int bus_open_system_watch_bind(sd_bus **ret) {
63 return bus_open_system_watch_bind_with_description(ret, NULL);
64 }
65
66 int bus_reply_pair_array(sd_bus_message *m, char **l);
67
68 extern const struct hash_ops bus_message_hash_ops;