2017-11-18 17:09:20 +01:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2013-03-19 20:03:16 +01:00
|
|
|
#pragma once
|
|
|
|
|
2013-05-17 03:13:58 +02:00
|
|
|
#include <pthread.h>
|
2015-10-24 22:58:24 +02:00
|
|
|
#include <sys/socket.h>
|
2013-03-19 20:03:16 +01:00
|
|
|
|
|
|
|
#include "sd-bus.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
|
2013-03-19 20:03:16 +01:00
|
|
|
#include "bus-error.h"
|
2013-05-14 22:24:26 +02:00
|
|
|
#include "bus-kernel.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "bus-match.h"
|
2017-09-13 19:08:26 +02:00
|
|
|
#include "def.h"
|
2015-10-24 22:58:24 +02:00
|
|
|
#include "hashmap.h"
|
|
|
|
#include "list.h"
|
|
|
|
#include "prioq.h"
|
|
|
|
#include "refcnt.h"
|
|
|
|
#include "socket-util.h"
|
|
|
|
#include "util.h"
|
2013-03-19 20:03:16 +01:00
|
|
|
|
|
|
|
struct reply_callback {
|
2013-03-31 16:26:14 +02:00
|
|
|
sd_bus_message_handler_t callback;
|
sd-bus: start reply callback timeouts only when the connection is established
Currently, reply callback timeouts are started the instant the method
calls are enqueued, which can be very early on. For example, the Hello()
method call is enqueued right when sd_bus_start() is called, i.e. before
the socket connection and everything is established.
With this change we instead start the method timeout the moment we
actually leave the authentication phase of the connection. This way, the
timeout the kernel applies on socket connecting, and we apply on the
authentication phase no longer runs in parallel to the Hello() method
call, but all three run serially one after the other, which is
definitely a cleaner approach.
Moreover, this makes the "watch bind" feature a lot more useful, as it
allows enqueuing method calls while we are still waiting for inotify
events, without them timeouting until the connection is actually
established, i.e. when the method call actually has a chance of being
actually run.
This is a change of behaviour of course, but I think the new behaviour
is much better than the old one, since we don't race timeouts against
each other anymore...
2017-12-18 13:53:12 +01:00
|
|
|
usec_t timeout_usec; /* this is a relative timeout until we reach the BUS_HELLO state, and an absolute one right after */
|
2013-12-25 17:46:45 +01:00
|
|
|
uint64_t cookie;
|
2013-03-21 22:50:25 +01:00
|
|
|
unsigned prioq_idx;
|
2013-03-19 20:03:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
struct filter_callback {
|
2013-03-31 16:26:14 +02:00
|
|
|
sd_bus_message_handler_t callback;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
2013-04-05 03:55:58 +02:00
|
|
|
unsigned last_iteration;
|
|
|
|
|
2013-03-19 20:03:16 +01:00
|
|
|
LIST_FIELDS(struct filter_callback, callbacks);
|
|
|
|
};
|
|
|
|
|
2014-05-15 01:15:30 +02:00
|
|
|
struct match_callback {
|
|
|
|
sd_bus_message_handler_t callback;
|
2017-12-18 21:37:03 +01:00
|
|
|
sd_bus_message_handler_t install_callback;
|
|
|
|
|
|
|
|
sd_bus_slot *install_slot; /* The AddMatch() call */
|
2014-05-15 01:15:30 +02:00
|
|
|
|
|
|
|
unsigned last_iteration;
|
|
|
|
|
|
|
|
char *match_string;
|
|
|
|
|
|
|
|
struct bus_match_node *match_node;
|
|
|
|
};
|
|
|
|
|
2013-10-09 02:37:10 +02:00
|
|
|
struct node {
|
|
|
|
char *path;
|
|
|
|
struct node *parent;
|
|
|
|
LIST_HEAD(struct node, child);
|
|
|
|
LIST_FIELDS(struct node, siblings);
|
|
|
|
|
|
|
|
LIST_HEAD(struct node_callback, callbacks);
|
|
|
|
LIST_HEAD(struct node_vtable, vtables);
|
|
|
|
LIST_HEAD(struct node_enumerator, enumerators);
|
2014-05-15 01:15:30 +02:00
|
|
|
LIST_HEAD(struct node_object_manager, object_managers);
|
2013-10-09 02:37:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct node_callback {
|
|
|
|
struct node *node;
|
|
|
|
|
|
|
|
bool is_fallback;
|
2013-03-31 16:26:14 +02:00
|
|
|
sd_bus_message_handler_t callback;
|
2013-03-22 05:58:47 +01:00
|
|
|
|
2013-10-09 02:37:10 +02:00
|
|
|
unsigned last_iteration;
|
|
|
|
|
|
|
|
LIST_FIELDS(struct node_callback, callbacks);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct node_enumerator {
|
|
|
|
struct node *node;
|
|
|
|
|
|
|
|
sd_bus_node_enumerator_t callback;
|
|
|
|
|
|
|
|
unsigned last_iteration;
|
|
|
|
|
|
|
|
LIST_FIELDS(struct node_enumerator, enumerators);
|
|
|
|
};
|
|
|
|
|
2014-05-15 01:15:30 +02:00
|
|
|
struct node_object_manager {
|
|
|
|
struct node *node;
|
|
|
|
|
|
|
|
LIST_FIELDS(struct node_object_manager, object_managers);
|
|
|
|
};
|
|
|
|
|
2013-10-09 02:37:10 +02:00
|
|
|
struct node_vtable {
|
|
|
|
struct node *node;
|
|
|
|
|
|
|
|
char *interface;
|
2013-03-22 05:58:47 +01:00
|
|
|
bool is_fallback;
|
2013-10-09 02:37:10 +02:00
|
|
|
const sd_bus_vtable *vtable;
|
|
|
|
sd_bus_object_find_t find;
|
2013-04-05 03:55:58 +02:00
|
|
|
|
|
|
|
unsigned last_iteration;
|
2013-10-09 02:37:10 +02:00
|
|
|
|
|
|
|
LIST_FIELDS(struct node_vtable, vtables);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vtable_member {
|
|
|
|
const char *path;
|
|
|
|
const char *interface;
|
|
|
|
const char *member;
|
|
|
|
struct node_vtable *parent;
|
|
|
|
unsigned last_iteration;
|
|
|
|
const sd_bus_vtable *vtable;
|
2013-03-22 05:58:47 +01:00
|
|
|
};
|
|
|
|
|
2014-05-15 01:15:30 +02:00
|
|
|
typedef enum BusSlotType {
|
|
|
|
BUS_REPLY_CALLBACK,
|
|
|
|
BUS_FILTER_CALLBACK,
|
|
|
|
BUS_MATCH_CALLBACK,
|
|
|
|
BUS_NODE_CALLBACK,
|
|
|
|
BUS_NODE_ENUMERATOR,
|
|
|
|
BUS_NODE_VTABLE,
|
|
|
|
BUS_NODE_OBJECT_MANAGER,
|
2014-05-15 01:55:18 +02:00
|
|
|
_BUS_SLOT_INVALID = -1,
|
2014-05-15 01:15:30 +02:00
|
|
|
} BusSlotType;
|
|
|
|
|
|
|
|
struct sd_bus_slot {
|
|
|
|
unsigned n_ref;
|
|
|
|
sd_bus *bus;
|
|
|
|
void *userdata;
|
2018-06-06 11:07:02 +02:00
|
|
|
sd_bus_destroy_t destroy_callback;
|
2014-05-15 01:55:18 +02:00
|
|
|
BusSlotType type:5;
|
2018-05-30 16:29:33 +02:00
|
|
|
|
|
|
|
/* Slots can be "floating" or not. If they are not floating (the usual case) then they reference the bus object
|
|
|
|
* they are associated with. This means the bus object stays allocated at least as long as there is a slot
|
|
|
|
* around associated with it. If it is floating, then the slot's lifecycle is bound to the lifecycle of the
|
|
|
|
* bus: it will be disconnected from the bus when the bus is destroyed, and it keeping the slot reffed hence
|
|
|
|
* won't mean the bus stays reffed too. Internally this means the reference direction is reversed: floating
|
|
|
|
* slots objects are referenced by the bus object, and not vice versa. */
|
2014-05-15 01:55:18 +02:00
|
|
|
bool floating:1;
|
2018-05-30 16:29:33 +02:00
|
|
|
|
2015-06-17 11:42:39 +02:00
|
|
|
bool match_added:1;
|
2014-11-04 16:57:38 +01:00
|
|
|
char *description;
|
2014-05-15 01:15:30 +02:00
|
|
|
|
|
|
|
LIST_FIELDS(sd_bus_slot, slots);
|
|
|
|
|
|
|
|
union {
|
|
|
|
struct reply_callback reply_callback;
|
|
|
|
struct filter_callback filter_callback;
|
|
|
|
struct match_callback match_callback;
|
|
|
|
struct node_callback node_callback;
|
|
|
|
struct node_enumerator node_enumerator;
|
|
|
|
struct node_object_manager node_object_manager;
|
|
|
|
struct node_vtable node_vtable;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2013-03-19 20:03:16 +01:00
|
|
|
enum bus_state {
|
2013-03-24 23:55:03 +01:00
|
|
|
BUS_UNSET,
|
sd-bus: start reply callback timeouts only when the connection is established
Currently, reply callback timeouts are started the instant the method
calls are enqueued, which can be very early on. For example, the Hello()
method call is enqueued right when sd_bus_start() is called, i.e. before
the socket connection and everything is established.
With this change we instead start the method timeout the moment we
actually leave the authentication phase of the connection. This way, the
timeout the kernel applies on socket connecting, and we apply on the
authentication phase no longer runs in parallel to the Hello() method
call, but all three run serially one after the other, which is
definitely a cleaner approach.
Moreover, this makes the "watch bind" feature a lot more useful, as it
allows enqueuing method calls while we are still waiting for inotify
events, without them timeouting until the connection is actually
established, i.e. when the method call actually has a chance of being
actually run.
This is a change of behaviour of course, but I think the new behaviour
is much better than the old one, since we don't race timeouts against
each other anymore...
2017-12-18 13:53:12 +01:00
|
|
|
BUS_WATCH_BIND, /* waiting for the socket to appear via inotify */
|
|
|
|
BUS_OPENING, /* the kernel's connect() is still not ready */
|
|
|
|
BUS_AUTHENTICATING, /* we are currently in the "SASL" authorization phase of dbus */
|
|
|
|
BUS_HELLO, /* we are waiting for the Hello() response */
|
2013-05-17 02:22:37 +02:00
|
|
|
BUS_RUNNING,
|
2013-11-19 21:12:59 +01:00
|
|
|
BUS_CLOSING,
|
2017-12-20 12:50:43 +01:00
|
|
|
BUS_CLOSED,
|
|
|
|
_BUS_STATE_MAX,
|
2013-03-19 20:03:16 +01:00
|
|
|
};
|
|
|
|
|
2013-05-17 02:22:37 +02:00
|
|
|
static inline bool BUS_IS_OPEN(enum bus_state state) {
|
2013-11-19 21:12:59 +01:00
|
|
|
return state > BUS_UNSET && state < BUS_CLOSING;
|
2013-05-17 02:22:37 +02:00
|
|
|
}
|
|
|
|
|
2013-03-30 15:21:06 +01:00
|
|
|
enum bus_auth {
|
|
|
|
_BUS_AUTH_INVALID,
|
|
|
|
BUS_AUTH_EXTERNAL,
|
|
|
|
BUS_AUTH_ANONYMOUS
|
|
|
|
};
|
|
|
|
|
2013-03-19 20:03:16 +01:00
|
|
|
struct sd_bus {
|
2013-05-16 21:52:35 +02:00
|
|
|
/* We use atomic ref counting here since sd_bus_message
|
|
|
|
objects retain references to their originating sd_bus but
|
|
|
|
we want to allow them to be processed in a different
|
|
|
|
thread. We won't provide full thread safety, but only the
|
|
|
|
bare minimum that makes it possible to use sd_bus and
|
|
|
|
sd_bus_message objects independently and on different
|
|
|
|
threads as long as each object is used only once at the
|
|
|
|
same time. */
|
|
|
|
RefCount n_ref;
|
|
|
|
|
2013-03-19 20:03:16 +01:00
|
|
|
enum bus_state state;
|
2013-03-31 19:10:49 +02:00
|
|
|
int input_fd, output_fd;
|
2017-12-15 22:24:52 +01:00
|
|
|
int inotify_fd;
|
2013-03-19 20:03:16 +01:00
|
|
|
int message_version;
|
2013-12-12 19:58:46 +01:00
|
|
|
int message_endian;
|
2013-03-24 23:55:03 +01:00
|
|
|
|
2013-03-19 20:03:16 +01:00
|
|
|
bool can_fds:1;
|
2013-03-26 00:36:43 +01:00
|
|
|
bool bus_client:1;
|
2013-03-22 03:36:58 +01:00
|
|
|
bool ucred_valid:1;
|
2013-03-30 15:21:06 +01:00
|
|
|
bool is_server:1;
|
|
|
|
bool anonymous_auth:1;
|
2013-03-31 20:19:18 +02:00
|
|
|
bool prefer_readv:1;
|
|
|
|
bool prefer_writev:1;
|
2013-04-05 03:55:58 +02:00
|
|
|
bool match_callbacks_modified:1;
|
|
|
|
bool filter_callbacks_modified:1;
|
2013-10-09 02:37:10 +02:00
|
|
|
bool nodes_modified:1;
|
2013-12-10 17:41:39 +01:00
|
|
|
bool trusted:1;
|
2013-12-26 03:08:52 +01:00
|
|
|
bool manual_peer_interface:1;
|
2014-01-22 16:09:59 +01:00
|
|
|
bool is_system:1;
|
|
|
|
bool is_user:1;
|
2015-02-17 20:30:33 +01:00
|
|
|
bool allow_interactive_authorization:1;
|
2016-08-22 17:19:12 +02:00
|
|
|
bool exit_on_disconnect:1;
|
|
|
|
bool exited:1;
|
|
|
|
bool exit_triggered:1;
|
2017-06-28 19:20:16 +02:00
|
|
|
bool is_local:1;
|
2017-12-15 22:24:52 +01:00
|
|
|
bool watch_bind:1;
|
2017-12-18 14:21:34 +01:00
|
|
|
bool is_monitor:1;
|
|
|
|
bool accept_fd:1;
|
|
|
|
bool attach_timestamp:1;
|
2017-12-19 15:50:05 +01:00
|
|
|
bool connected_signal:1;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
2013-05-22 16:02:21 +02:00
|
|
|
int use_memfd;
|
|
|
|
|
2013-03-19 20:03:16 +01:00
|
|
|
void *rbuffer;
|
|
|
|
size_t rbuffer_size;
|
|
|
|
|
|
|
|
sd_bus_message **rqueue;
|
2013-12-16 20:32:37 +01:00
|
|
|
unsigned rqueue_size;
|
|
|
|
size_t rqueue_allocated;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
|
|
|
sd_bus_message **wqueue;
|
|
|
|
unsigned wqueue_size;
|
|
|
|
size_t windex;
|
2013-12-16 20:32:37 +01:00
|
|
|
size_t wqueue_allocated;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
2013-12-25 17:46:45 +01:00
|
|
|
uint64_t cookie;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
|
|
|
char *unique_name;
|
2013-11-29 22:02:43 +01:00
|
|
|
uint64_t unique_id;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
2013-03-31 16:16:37 +02:00
|
|
|
struct bus_match_node match_callbacks;
|
2013-03-21 22:50:25 +01:00
|
|
|
Prioq *reply_callbacks_prioq;
|
2014-10-14 18:27:55 +02:00
|
|
|
OrderedHashmap *reply_callbacks;
|
2013-03-19 20:03:16 +01:00
|
|
|
LIST_HEAD(struct filter_callback, filter_callbacks);
|
2013-10-09 02:37:10 +02:00
|
|
|
|
|
|
|
Hashmap *nodes;
|
|
|
|
Hashmap *vtable_methods;
|
|
|
|
Hashmap *vtable_properties;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
2014-07-10 21:16:40 +02:00
|
|
|
union sockaddr_union sockaddr;
|
2013-03-19 20:03:16 +01:00
|
|
|
socklen_t sockaddr_size;
|
|
|
|
|
2013-10-30 15:34:50 +01:00
|
|
|
char *machine;
|
2014-12-23 19:11:48 +01:00
|
|
|
pid_t nspid;
|
2013-04-11 23:09:29 +02:00
|
|
|
|
2013-03-31 16:46:21 +02:00
|
|
|
sd_id128_t server_id;
|
2013-03-19 20:03:16 +01:00
|
|
|
|
|
|
|
char *address;
|
|
|
|
unsigned address_index;
|
|
|
|
|
|
|
|
int last_connect_error;
|
|
|
|
|
2013-03-30 15:21:06 +01:00
|
|
|
enum bus_auth auth;
|
|
|
|
size_t auth_rbegin;
|
2013-03-19 20:03:16 +01:00
|
|
|
struct iovec auth_iovec[3];
|
|
|
|
unsigned auth_index;
|
2013-03-30 15:21:06 +01:00
|
|
|
char *auth_buffer;
|
2013-03-21 22:50:25 +01:00
|
|
|
usec_t auth_timeout;
|
2013-03-22 03:36:58 +01:00
|
|
|
|
|
|
|
struct ucred ucred;
|
2015-06-07 03:24:45 +02:00
|
|
|
char *label;
|
2017-12-30 15:19:15 +01:00
|
|
|
gid_t *groups;
|
|
|
|
size_t n_groups;
|
2013-03-24 22:02:05 +01:00
|
|
|
|
2013-11-28 17:50:02 +01:00
|
|
|
uint64_t creds_mask;
|
|
|
|
|
2013-03-24 22:02:05 +01:00
|
|
|
int *fds;
|
tree-wide: be more careful with the type of array sizes
Previously we were a bit sloppy with the index and size types of arrays,
we'd regularly use unsigned. While I don't think this ever resulted in
real issues I think we should be more careful there and follow a
stricter regime: unless there's a strong reason not to use size_t for
array sizes and indexes, size_t it should be. Any allocations we do
ultimately will use size_t anyway, and converting forth and back between
unsigned and size_t will always be a source of problems.
Note that on 32bit machines "unsigned" and "size_t" are equivalent, and
on 64bit machines our arrays shouldn't grow that large anyway, and if
they do we have a problem, however that kind of overly large allocation
we have protections for usually, but for overflows we do not have that
so much, hence let's add it.
So yeah, it's a story of the current code being already "good enough",
but I think some extra type hygiene is better.
This patch tries to be comprehensive, but it probably isn't and I missed
a few cases. But I guess we can cover that later as we notice it. Among
smaller fixes, this changes:
1. strv_length()' return type becomes size_t
2. the unit file changes array size becomes size_t
3. DNS answer and query array sizes become size_t
Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=76745
2018-04-27 14:09:31 +02:00
|
|
|
size_t n_fds;
|
2013-03-25 02:30:32 +01:00
|
|
|
|
|
|
|
char *exec_path;
|
|
|
|
char **exec_argv;
|
2013-03-29 23:44:11 +01:00
|
|
|
|
2013-04-05 03:55:58 +02:00
|
|
|
unsigned iteration_counter;
|
2013-05-10 03:36:55 +02:00
|
|
|
|
2013-05-17 03:13:58 +02:00
|
|
|
/* We do locking around the memfd cache, since we want to
|
|
|
|
* allow people to process a sd_bus_message in a different
|
|
|
|
* thread then it was generated on and free it there. Since
|
|
|
|
* adding something to the memfd cache might happen when a
|
|
|
|
* message is released, we hence need to protect this bit with
|
|
|
|
* a mutex. */
|
|
|
|
pthread_mutex_t memfd_cache_mutex;
|
2013-05-14 22:24:26 +02:00
|
|
|
struct memfd_cache memfd_cache[MEMFD_CACHE_MAX];
|
|
|
|
unsigned n_memfd_cache;
|
2013-05-17 02:50:00 +02:00
|
|
|
|
|
|
|
pid_t original_pid;
|
2018-02-03 19:16:33 +01:00
|
|
|
pid_t busexec_pid;
|
2013-05-17 04:25:56 +02:00
|
|
|
|
2013-10-16 06:10:04 +02:00
|
|
|
sd_event_source *input_io_event_source;
|
|
|
|
sd_event_source *output_io_event_source;
|
|
|
|
sd_event_source *time_event_source;
|
2013-10-18 01:43:11 +02:00
|
|
|
sd_event_source *quit_event_source;
|
2017-12-15 22:24:52 +01:00
|
|
|
sd_event_source *inotify_event_source;
|
2013-10-16 06:10:04 +02:00
|
|
|
sd_event *event;
|
2013-12-13 05:12:46 +01:00
|
|
|
int event_priority;
|
2013-11-05 20:51:49 +01:00
|
|
|
|
2014-05-15 01:15:30 +02:00
|
|
|
sd_bus_message *current_message;
|
|
|
|
sd_bus_slot *current_slot;
|
2014-08-18 17:41:56 +02:00
|
|
|
sd_bus_message_handler_t current_handler;
|
|
|
|
void *current_userdata;
|
2013-11-11 22:00:48 +01:00
|
|
|
|
|
|
|
sd_bus **default_bus_ptr;
|
|
|
|
pid_t tid;
|
2013-12-24 15:03:32 +01:00
|
|
|
|
2013-12-24 19:31:44 +01:00
|
|
|
char *cgroup_root;
|
2014-01-22 16:09:59 +01:00
|
|
|
|
2014-11-04 16:13:49 +01:00
|
|
|
char *description;
|
2017-12-20 19:41:06 +01:00
|
|
|
char *patch_sender;
|
2014-01-28 00:57:38 +01:00
|
|
|
|
2014-03-03 01:33:45 +01:00
|
|
|
sd_bus_track *track_queue;
|
2014-05-15 01:15:30 +02:00
|
|
|
|
|
|
|
LIST_HEAD(sd_bus_slot, slots);
|
2016-08-22 16:11:54 +02:00
|
|
|
LIST_HEAD(sd_bus_track, tracks);
|
2017-12-15 22:24:52 +01:00
|
|
|
|
|
|
|
int *inotify_watches;
|
|
|
|
size_t n_inotify_watches;
|
2018-07-13 10:38:47 +02:00
|
|
|
|
|
|
|
/* zero means use value specified by $SYSTEMD_BUS_TIMEOUT= environment variable or built-in default */
|
|
|
|
usec_t method_call_timeout;
|
2013-10-16 06:10:04 +02:00
|
|
|
};
|
2013-03-21 22:50:25 +01:00
|
|
|
|
2017-09-13 19:08:26 +02:00
|
|
|
/* For method calls we time-out at 25s, like in the D-Bus reference implementation */
|
2013-03-21 22:50:25 +01:00
|
|
|
#define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
|
2013-03-21 23:20:25 +01:00
|
|
|
|
2017-09-13 19:08:26 +02:00
|
|
|
/* For the authentication phase we grant 90s, to provide extra room during boot, when RNGs and such are not filled up
|
|
|
|
* with enough entropy yet and might delay the boot */
|
|
|
|
#define BUS_AUTH_TIMEOUT ((usec_t) DEFAULT_TIMEOUT_USEC)
|
|
|
|
|
2016-08-31 20:09:31 +02:00
|
|
|
#define BUS_WQUEUE_MAX (192*1024)
|
|
|
|
#define BUS_RQUEUE_MAX (192*1024)
|
2013-03-21 23:20:25 +01:00
|
|
|
|
2018-05-09 10:33:28 +02:00
|
|
|
#define BUS_MESSAGE_SIZE_MAX (128*1024*1024)
|
2013-03-21 23:20:25 +01:00
|
|
|
#define BUS_AUTH_SIZE_MAX (64*1024)
|
2013-03-22 00:42:53 +01:00
|
|
|
|
2013-03-22 02:32:34 +01:00
|
|
|
#define BUS_CONTAINER_DEPTH 128
|
|
|
|
|
2018-07-13 10:38:47 +02:00
|
|
|
/* Defined by the specification as maximum size of an array in bytes */
|
2013-03-22 00:42:53 +01:00
|
|
|
#define BUS_ARRAY_MAX_SIZE 67108864
|
|
|
|
|
2013-03-24 22:02:05 +01:00
|
|
|
#define BUS_FDS_MAX 1024
|
|
|
|
|
2013-03-25 02:30:32 +01:00
|
|
|
#define BUS_EXEC_ARGV_MAX 256
|
|
|
|
|
2013-12-25 18:26:51 +01:00
|
|
|
bool interface_name_is_valid(const char *p) _pure_;
|
|
|
|
bool service_name_is_valid(const char *p) _pure_;
|
2014-11-14 20:06:01 +01:00
|
|
|
char* service_name_startswith(const char *a, const char *b);
|
2013-12-25 18:26:51 +01:00
|
|
|
bool member_name_is_valid(const char *p) _pure_;
|
|
|
|
bool object_path_is_valid(const char *p) _pure_;
|
|
|
|
char *object_path_startswith(const char *a, const char *b) _pure_;
|
2013-03-22 01:15:20 +01:00
|
|
|
|
2013-12-25 18:26:51 +01:00
|
|
|
bool namespace_complex_pattern(const char *pattern, const char *value) _pure_;
|
|
|
|
bool path_complex_pattern(const char *pattern, const char *value) _pure_;
|
2013-03-31 16:16:37 +02:00
|
|
|
|
2013-12-25 18:26:51 +01:00
|
|
|
bool namespace_simple_pattern(const char *pattern, const char *value) _pure_;
|
|
|
|
bool path_simple_pattern(const char *pattern, const char *value) _pure_;
|
2013-03-31 16:16:37 +02:00
|
|
|
|
2013-12-25 18:26:51 +01:00
|
|
|
int bus_message_type_from_string(const char *s, uint8_t *u) _pure_;
|
|
|
|
const char *bus_message_type_to_string(uint8_t u) _pure_;
|
2013-03-31 16:16:37 +02:00
|
|
|
|
2013-03-22 01:15:20 +01:00
|
|
|
#define error_name_is_valid interface_name_is_valid
|
2013-03-22 03:34:29 +01:00
|
|
|
|
2018-01-22 22:26:44 +01:00
|
|
|
sd_bus *bus_resolve(sd_bus *bus);
|
|
|
|
|
2013-03-22 03:34:29 +01:00
|
|
|
int bus_ensure_running(sd_bus *bus);
|
2013-03-25 03:04:03 +01:00
|
|
|
int bus_start_running(sd_bus *bus);
|
|
|
|
int bus_next_address(sd_bus *bus);
|
2013-05-17 02:50:00 +02:00
|
|
|
|
2013-11-30 00:19:01 +01:00
|
|
|
int bus_seal_synthetic_message(sd_bus *b, sd_bus_message *m);
|
2013-11-29 20:07:56 +01:00
|
|
|
|
2013-11-30 00:19:01 +01:00
|
|
|
int bus_rqueue_make_room(sd_bus *bus);
|
2013-11-29 21:29:16 +01:00
|
|
|
|
2013-05-17 02:50:00 +02:00
|
|
|
bool bus_pid_changed(sd_bus *bus);
|
2013-10-11 23:20:54 +02:00
|
|
|
|
2013-10-30 13:52:40 +01:00
|
|
|
char *bus_address_escape(const char *v);
|
|
|
|
|
2017-12-15 22:24:52 +01:00
|
|
|
int bus_attach_io_events(sd_bus *b);
|
|
|
|
int bus_attach_inotify_event(sd_bus *b);
|
|
|
|
|
|
|
|
void bus_close_inotify_fd(sd_bus *b);
|
|
|
|
void bus_close_io_fds(sd_bus *b);
|
|
|
|
|
2013-10-11 23:20:54 +02:00
|
|
|
#define OBJECT_PATH_FOREACH_PREFIX(prefix, path) \
|
|
|
|
for (char *_slash = ({ strcpy((prefix), (path)); streq((prefix), "/") ? NULL : strrchr((prefix), '/'); }) ; \
|
2018-06-26 04:32:44 +02:00
|
|
|
_slash && ((_slash[(_slash) == (prefix)] = 0), true); \
|
2013-10-11 23:20:54 +02:00
|
|
|
_slash = streq((prefix), "/") ? NULL : strrchr((prefix), '/'))
|
2013-10-14 19:53:56 +02:00
|
|
|
|
|
|
|
/* If we are invoking callbacks of a bus object, ensure unreffing the
|
2018-07-13 10:38:47 +02:00
|
|
|
* bus from the callback doesn't destroy the object we are working on */
|
2013-10-14 19:53:56 +02:00
|
|
|
#define BUS_DONT_DESTROY(bus) \
|
tree-wide: expose "p"-suffix unref calls in public APIs to make gcc cleanup easy
GLIB has recently started to officially support the gcc cleanup
attribute in its public API, hence let's do the same for our APIs.
With this patch we'll define an xyz_unrefp() call for each public
xyz_unref() call, to make it easy to use inside a
__attribute__((cleanup())) expression. Then, all code is ported over to
make use of this.
The new calls are also documented in the man pages, with examples how to
use them (well, I only added docs where the _unref() call itself already
had docs, and the examples, only cover sd_bus_unrefp() and
sd_event_unrefp()).
This also renames sd_lldp_free() to sd_lldp_unref(), since that's how we
tend to call our destructors these days.
Note that this defines no public macro that wraps gcc's attribute and
makes it easier to use. While I think it's our duty in the library to
make our stuff easy to use, I figure it's not our duty to make gcc's own
features easy to use on its own. Most likely, client code which wants to
make use of this should define its own:
#define _cleanup_(function) __attribute__((cleanup(function)))
Or similar, to make the gcc feature easier to use.
Making this logic public has the benefit that we can remove three header
files whose only purpose was to define these functions internally.
See #2008.
2015-11-27 19:13:45 +01:00
|
|
|
_cleanup_(sd_bus_unrefp) _unused_ sd_bus *_dont_destroy_##bus = sd_bus_ref(bus)
|
2014-03-19 04:17:00 +01:00
|
|
|
|
|
|
|
int bus_set_address_system(sd_bus *bus);
|
|
|
|
int bus_set_address_user(sd_bus *bus);
|
|
|
|
int bus_set_address_system_remote(sd_bus *b, const char *host);
|
2014-12-23 23:38:13 +01:00
|
|
|
int bus_set_address_system_machine(sd_bus *b, const char *machine);
|
2014-05-15 01:15:30 +02:00
|
|
|
|
2014-08-18 20:21:55 +02:00
|
|
|
int bus_get_root_path(sd_bus *bus);
|
2015-06-09 14:27:33 +02:00
|
|
|
|
|
|
|
int bus_maybe_reply_error(sd_bus_message *m, int r, sd_bus_error *error);
|
2015-08-11 20:46:05 +02:00
|
|
|
|
2015-08-16 22:13:34 +02:00
|
|
|
#define bus_assert_return(expr, r, error) \
|
|
|
|
do { \
|
basic: nicer assert messages
Make sure the assert expression is not macro-expanded before
stringification. This makes several assertion failure messages more
readable.
As an example:
assert(streq("foo", "bar"));
I'd rather see this:
Assertion 'streq("foo", "bar")' failed at foo.c:5, function main(). Aborting.
...than this, though awesome, incomprehensible truncated mess:
Assertion '(__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p ((
"foo")) && __builtin_constant_p (("bar")) && (__s1_len = strlen (("foo")), __s2_
len = strlen (("bar")), (!((size_t)(const void *)((("foo")) + 1) - (size_t)(cons
t void *)(("foo")) == 1) || __s1_len >= 4) && (!((size_t)(const void *)((("bar")
) + 1) - (size_t)(const void *)(("bar")) == 1) || __s2_len >= 4)) ? __builtin_st
rcmp (("foo"), ("bar")) : (__builtin_constant_p (("foo")) && ((size_t)(const voi
d *)((("foo")) + 1) - (size_t)(const void *)(("foo")) == 1) && (__s1_len = strle
n (("foo")), __s1_len < 4) ? (__builtin_constant_p (("bar")) && ((size_t)(const
void *)((("bar")) + 1) - (size_t)(const void *)(("bar")) == 1) ? __builtin_strcm
p (("foo"), ("bar")) : (__extension__ ({ const unsigned char *__s2 = (const unsi
gned char *) (const char *) (("bar")); int __result = (((const unsigned char *)
(const char *) (("foo")))[0] - __s2[0]); if (__s1_len > 0 && __result == 0) { __
result = (((const unsigned char *) (const char *) (("foo")))[1] - __s2[1]); if (
__s1_len > 1 && __result == 0) { __result = (((const unsigned char *) (const cha
r *) (("foo")))[2] - __s2[2]); if (__s1_len > 2 && __result == 0) __result = (((
const unsigned char *) (const char *) (("foo")))[3] - __s2[3]); } } __result; })
)) : (__builtin_constant_p (("bar")) && ((size_t)(const void *)((("bar")) + 1) -
(size_t)(const void *)(("bar")) == 1) && (__s2_len = strlen (("bar")), __s2_len
< 4) ? (__builtin_constant_p (("foo")) && ((size_t)(const void *)((("foo")) + 1
) - (size_t)(const void *)(("foo")) == 1) ? __builtin_strcmp (("foo"), ("bar"))
: (- (__extension__ ({ const unsigned char *__s2 = (const unsigned char *) (cons
t char *) (("foo")); int __result = (((const unsigned char *) (const char *) (("
bar")))[0] - __s2[0]); if (__s2_len > 0 && __result == 0) { __result = (((const
unsigned char *) (const char *) (("bar")))[1] - __s2[1]); if (__s2_len > 1 && __
result == 0) { __result = (((const unsigned char *) (const char *) (("bar")))[2]
- __s2[2]); if (__s2_len > 2 && __result == 0)
2015-09-14 15:53:36 +02:00
|
|
|
if (!assert_log(expr, #expr)) \
|
2015-08-16 22:13:34 +02:00
|
|
|
return sd_bus_error_set_errno(error, r); \
|
|
|
|
} while (false)
|
2017-12-18 20:10:13 +01:00
|
|
|
|
|
|
|
void bus_enter_closing(sd_bus *bus);
|
2017-12-20 12:50:43 +01:00
|
|
|
|
|
|
|
void bus_set_state(sd_bus *bus, enum bus_state state);
|