2013-03-19 20:03:16 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/***
|
|
|
|
This file is part of systemd.
|
|
|
|
|
|
|
|
Copyright 2013 Lennart Poettering
|
|
|
|
|
|
|
|
systemd is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
systemd is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
***/
|
|
|
|
|
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"
|
|
|
|
#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;
|
2013-03-19 20:03:16 +01:00
|
|
|
usec_t timeout;
|
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;
|
|
|
|
|
|
|
|
uint64_t cookie;
|
|
|
|
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;
|
2014-05-15 01:55:18 +02:00
|
|
|
BusSlotType type:5;
|
|
|
|
bool floating:1;
|
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,
|
2013-03-19 20:03:16 +01:00
|
|
|
BUS_OPENING,
|
|
|
|
BUS_AUTHENTICATING,
|
|
|
|
BUS_HELLO,
|
2013-05-17 02:22:37 +02:00
|
|
|
BUS_RUNNING,
|
2013-11-19 21:12:59 +01:00
|
|
|
BUS_CLOSING,
|
2013-05-17 02:22:37 +02:00
|
|
|
BUS_CLOSED
|
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;
|
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;
|
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;
|
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;
|
|
|
|
unsigned 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;
|
2013-05-17 04:25:56 +02:00
|
|
|
|
|
|
|
uint64_t hello_flags;
|
2013-11-29 15:36:37 +01:00
|
|
|
uint64_t attach_flags;
|
2013-05-19 18:39:08 +02:00
|
|
|
|
|
|
|
uint64_t match_cookie;
|
2013-03-20 22:56:25 +01: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;
|
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;
|
2014-01-28 00:57:38 +01:00
|
|
|
|
|
|
|
size_t bloom_size;
|
|
|
|
unsigned bloom_n_hash;
|
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);
|
2013-10-16 06:10:04 +02:00
|
|
|
};
|
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
|
|
|
|
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
|
|
|
|
|
|
|
#define BUS_MESSAGE_SIZE_MAX (64*1024*1024)
|
|
|
|
#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
|
|
|
|
|
2013-03-22 00:42:53 +01:00
|
|
|
/* Defined by the specification as maximum size of an array in
|
|
|
|
* bytes */
|
|
|
|
#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
|
|
|
|
|
|
|
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);
|
|
|
|
|
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), '/'); }) ; \
|
|
|
|
_slash && !(_slash[(_slash) == (prefix)] = 0); \
|
|
|
|
_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
|
|
|
|
* bus from the callback doesn't destroy the object we are working
|
|
|
|
* on */
|
|
|
|
#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
|
|
|
|
|
|
|
int bus_remove_match_by_string(sd_bus *bus, const char *match, sd_bus_message_handler_t callback, void *userdata);
|
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-07-23 17:45:57 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* enum kdbus_attach_flags - flags for metadata attachments
|
|
|
|
* @KDBUS_ATTACH_TIMESTAMP: Timestamp
|
|
|
|
* @KDBUS_ATTACH_CREDS: Credentials
|
|
|
|
* @KDBUS_ATTACH_PIDS: PIDs
|
|
|
|
* @KDBUS_ATTACH_AUXGROUPS: Auxiliary groups
|
|
|
|
* @KDBUS_ATTACH_NAMES: Well-known names
|
|
|
|
* @KDBUS_ATTACH_TID_COMM: The "comm" process identifier of the TID
|
|
|
|
* @KDBUS_ATTACH_PID_COMM: The "comm" process identifier of the PID
|
|
|
|
* @KDBUS_ATTACH_EXE: The path of the executable
|
|
|
|
* @KDBUS_ATTACH_CMDLINE: The process command line
|
|
|
|
* @KDBUS_ATTACH_CGROUP: The croup membership
|
|
|
|
* @KDBUS_ATTACH_CAPS: The process capabilities
|
|
|
|
* @KDBUS_ATTACH_SECLABEL: The security label
|
|
|
|
* @KDBUS_ATTACH_AUDIT: The audit IDs
|
|
|
|
* @KDBUS_ATTACH_CONN_DESCRIPTION: The human-readable connection name
|
|
|
|
* @_KDBUS_ATTACH_ALL: All of the above
|
|
|
|
* @_KDBUS_ATTACH_ANY: Wildcard match to enable any kind of
|
|
|
|
* metatdata.
|
|
|
|
*/
|
|
|
|
enum kdbus_attach_flags {
|
|
|
|
KDBUS_ATTACH_TIMESTAMP = 1ULL << 0,
|
|
|
|
KDBUS_ATTACH_CREDS = 1ULL << 1,
|
|
|
|
KDBUS_ATTACH_PIDS = 1ULL << 2,
|
|
|
|
KDBUS_ATTACH_AUXGROUPS = 1ULL << 3,
|
|
|
|
KDBUS_ATTACH_NAMES = 1ULL << 4,
|
|
|
|
KDBUS_ATTACH_TID_COMM = 1ULL << 5,
|
|
|
|
KDBUS_ATTACH_PID_COMM = 1ULL << 6,
|
|
|
|
KDBUS_ATTACH_EXE = 1ULL << 7,
|
|
|
|
KDBUS_ATTACH_CMDLINE = 1ULL << 8,
|
|
|
|
KDBUS_ATTACH_CGROUP = 1ULL << 9,
|
|
|
|
KDBUS_ATTACH_CAPS = 1ULL << 10,
|
|
|
|
KDBUS_ATTACH_SECLABEL = 1ULL << 11,
|
|
|
|
KDBUS_ATTACH_AUDIT = 1ULL << 12,
|
|
|
|
KDBUS_ATTACH_CONN_DESCRIPTION = 1ULL << 13,
|
|
|
|
_KDBUS_ATTACH_ALL = (1ULL << 14) - 1,
|
|
|
|
_KDBUS_ATTACH_ANY = ~0ULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* enum kdbus_hello_flags - flags for struct kdbus_cmd_hello
|
|
|
|
* @KDBUS_HELLO_ACCEPT_FD: The connection allows the reception of
|
|
|
|
* any passed file descriptors
|
|
|
|
* @KDBUS_HELLO_ACTIVATOR: Special-purpose connection which registers
|
|
|
|
* a well-know name for a process to be started
|
|
|
|
* when traffic arrives
|
|
|
|
* @KDBUS_HELLO_POLICY_HOLDER: Special-purpose connection which registers
|
|
|
|
* policy entries for a name. The provided name
|
|
|
|
* is not activated and not registered with the
|
|
|
|
* name database, it only allows unprivileged
|
|
|
|
* connections to acquire a name, talk or discover
|
|
|
|
* a service
|
|
|
|
* @KDBUS_HELLO_MONITOR: Special-purpose connection to monitor
|
|
|
|
* bus traffic
|
|
|
|
*/
|
|
|
|
enum kdbus_hello_flags {
|
|
|
|
KDBUS_HELLO_ACCEPT_FD = 1ULL << 0,
|
|
|
|
KDBUS_HELLO_ACTIVATOR = 1ULL << 1,
|
|
|
|
KDBUS_HELLO_POLICY_HOLDER = 1ULL << 2,
|
|
|
|
KDBUS_HELLO_MONITOR = 1ULL << 3,
|
|
|
|
};
|