]> git.proxmox.com Git - systemd.git/blobdiff - src/libsystemd/sd-bus/bus-internal.h
New upstream version 242
[systemd.git] / src / libsystemd / sd-bus / bus-internal.h
index f208b294d8f1dcb01978405b842624172103fe7f..d7fcb9329b91ce7b4235344db13cf3cccafe0377 100644 (file)
 #include "hashmap.h"
 #include "list.h"
 #include "prioq.h"
-#include "refcnt.h"
 #include "socket-util.h"
-#include "util.h"
+#include "time-util.h"
+
+/* Note that we use the new /run prefix here (instead of /var/run) since we require them to be aliases and
+ * that way we become independent of /var being mounted */
+#define DEFAULT_SYSTEM_BUS_ADDRESS "unix:path=/run/dbus/system_bus_socket"
+#define DEFAULT_USER_BUS_ADDRESS_FMT "unix:path=%s/bus"
 
 struct reply_callback {
         sd_bus_message_handler_t callback;
@@ -60,11 +64,11 @@ struct node {
 struct node_callback {
         struct node *node;
 
-        bool is_fallback;
-        sd_bus_message_handler_t callback;
-
+        bool is_fallback:1;
         unsigned last_iteration;
 
+        sd_bus_message_handler_t callback;
+
         LIST_FIELDS(struct node_callback, callbacks);
 };
 
@@ -87,13 +91,13 @@ struct node_object_manager {
 struct node_vtable {
         struct node *node;
 
+        bool is_fallback:1;
+        unsigned last_iteration;
+
         char *interface;
-        bool is_fallback;
         const sd_bus_vtable *vtable;
         sd_bus_object_find_t find;
 
-        unsigned last_iteration;
-
         LIST_FIELDS(struct node_vtable, vtables);
 };
 
@@ -119,9 +123,6 @@ typedef enum BusSlotType {
 
 struct sd_bus_slot {
         unsigned n_ref;
-        sd_bus *bus;
-        void *userdata;
-        sd_bus_destroy_t destroy_callback;
         BusSlotType type:5;
 
         /* Slots can be "floating" or not. If they are not floating (the usual case) then they reference the bus object
@@ -133,6 +134,11 @@ struct sd_bus_slot {
         bool floating:1;
 
         bool match_added:1;
+
+        sd_bus *bus;
+        void *userdata;
+        sd_bus_destroy_t destroy_callback;
+
         char *description;
 
         LIST_FIELDS(sd_bus_slot, slots);
@@ -171,15 +177,7 @@ enum bus_auth {
 };
 
 struct sd_bus {
-        /* 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;
+        unsigned n_ref;
 
         enum bus_state state;
         int input_fd, output_fd;
@@ -213,17 +211,17 @@ struct sd_bus {
         bool connected_signal:1;
         bool close_on_exit:1;
 
-        int use_memfd;
+        signed int use_memfd:2;
 
         void *rbuffer;
         size_t rbuffer_size;
 
         sd_bus_message **rqueue;
-        unsigned rqueue_size;
+        size_t rqueue_size;
         size_t rqueue_allocated;
 
         sd_bus_message **wqueue;
-        unsigned wqueue_size;
+        size_t wqueue_size;
         size_t windex;
         size_t wqueue_allocated;
 
@@ -244,8 +242,8 @@ struct sd_bus {
         union sockaddr_union sockaddr;
         socklen_t sockaddr_size;
 
-        char *machine;
         pid_t nspid;
+        char *machine;
 
         sd_id128_t server_id;
 
@@ -255,9 +253,9 @@ struct sd_bus {
         int last_connect_error;
 
         enum bus_auth auth;
-        size_t auth_rbegin;
-        struct iovec auth_iovec[3];
         unsigned auth_index;
+        struct iovec auth_iovec[3];
+        size_t auth_rbegin;
         char *auth_buffer;
         usec_t auth_timeout;
 
@@ -274,8 +272,6 @@ struct sd_bus {
         char *exec_path;
         char **exec_argv;
 
-        unsigned iteration_counter;
-
         /* 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
@@ -289,6 +285,8 @@ struct sd_bus {
         pid_t original_pid;
         pid_t busexec_pid;
 
+        unsigned iteration_counter;
+
         sd_event_source *input_io_event_source;
         sd_event_source *output_io_event_source;
         sd_event_source *time_event_source;
@@ -297,13 +295,14 @@ struct sd_bus {
         sd_event *event;
         int event_priority;
 
+        pid_t tid;
+
         sd_bus_message *current_message;
         sd_bus_slot *current_slot;
         sd_bus_message_handler_t current_handler;
         void *current_userdata;
 
         sd_bus **default_bus_ptr;
-        pid_t tid;
 
         char *description;
         char *patch_sender;
@@ -332,6 +331,10 @@ struct sd_bus {
 
 #define BUS_MESSAGE_SIZE_MAX (128*1024*1024)
 #define BUS_AUTH_SIZE_MAX (64*1024)
+/* Note that the D-Bus specification states that bus paths shall have no size limit. We enforce here one
+ * anyway, since truly unbounded strings are a security problem. The limit we pick is relatively large however,
+ * to not clash unnecessarily with real-life applications. */
+#define BUS_PATH_SIZE_MAX (64*1024)
 
 #define BUS_CONTAINER_DEPTH 128