chiark / gitweb /
core: add new AcceptFD= setting to .busname units
authorLennart Poettering <lennart@poettering.net>
Tue, 18 Mar 2014 19:54:32 +0000 (20:54 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 18 Mar 2014 19:54:32 +0000 (20:54 +0100)
AcceptFD= defaults to true, thus making sure that by default fd passing
is enabled for all activatable names. Since for normal bus connections
fd passing is enabled too by default this makes sure fd passing works
correctly regardless whether a service is already activated or not.

Making this configurable on both busname units and in bus connections is
messy, but unavoidable since busnames are established and may queue
messages before the connection feature negotiation is done by the
service eventually activated. Conversely, feature negotiation on bus
connections takes place before the connection acquires its names.

Of course, this means developers really should make sure to keep the
settings in .busname units in sync with what they later intend to
negotiate.

src/core/busname.c
src/core/busname.h
src/core/load-fragment-gperf.gperf.m4
src/libsystemd/sd-bus/bus-kernel.c
src/libsystemd/sd-bus/bus-kernel.h

index 9d7a7965380a22d06d6622e58e30c1abced55c9b..ccef32e9e7daea96536399d01be4da73939cd104 100644 (file)
@@ -43,6 +43,7 @@ static void busname_init(Unit *u) {
         assert(u->load_state == UNIT_STUB);
 
         n->starter_fd = -1;
+        n->accept_fd = true;
 }
 
 static void busname_done(Unit *u) {
@@ -170,10 +171,12 @@ static void busname_dump(Unit *u, FILE *f, const char *prefix) {
         fprintf(f,
                 "%sBus Name State: %s\n"
                 "%sResult: %s\n"
-                "%sName: %s\n",
+                "%sName: %s\n"
+                "%sAccept FD: %s\n",
                 prefix, busname_state_to_string(n->state),
                 prefix, busname_result_to_string(n->result),
-                prefix, n->name);
+                prefix, n->name,
+                prefix, yes_no(n->accept_fd));
 }
 
 static void busname_unwatch_fd(BusName *n) {
@@ -226,8 +229,10 @@ static int busname_open_fd(BusName *n) {
         if (n->starter_fd >= 0)
                 return 0;
 
-        n->starter_fd = bus_kernel_create_starter(UNIT(n)->manager->running_as == SYSTEMD_SYSTEM ? "system" : "user",
-                                                  n->name, n->policy);
+        n->starter_fd = bus_kernel_create_starter(
+                        UNIT(n)->manager->running_as == SYSTEMD_SYSTEM ? "system" : "user",
+                        n->name, n->accept_fd, n->policy);
+
         if (n->starter_fd < 0) {
                 log_warning_unit(UNIT(n)->id, "Failed to create starter fd: %s", strerror(-n->starter_fd));
                 return n->starter_fd;
index f79f510ea2da880194b1d1f043a8c3a238af4c99..7f591974de03cbe0e4c28be8d4df8c40b0f6234c 100644 (file)
@@ -56,6 +56,8 @@ struct BusName {
 
         sd_event_source *event_source;
 
+        bool accept_fd;
+
         LIST_HEAD(BusNamePolicy, policy);
 };
 
index f85d868043a282f10853a65460874ba69a604420..c793a1e25f361baba0fb572d6e5f8e5a86b43073 100644 (file)
@@ -256,6 +256,7 @@ BusName.AllowUser,               config_parse_bus_policy,            0,
 BusName.AllowGroup,              config_parse_bus_policy,            0,                             0
 BusName.AllowWorld,              config_parse_bus_policy,            0,                             0
 BusName.SELinuxContext,          config_parse_exec_selinux_context,  0,                             0
+BusName.AcceptFileDescriptors,   config_parse_bool,                  0,                             offsetof(BusName, accept_fd)
 m4_dnl
 Mount.What,                      config_parse_string,                0,                             offsetof(Mount, parameters_fragment.what)
 Mount.Where,                     config_parse_path,                  0,                             offsetof(Mount, where)
index 445bd7f3d16bd397000620fb557b3d559a3ac8db..64a74d6edd42de9ed784e18d2ecc282729650ff2 100644 (file)
@@ -1378,7 +1378,7 @@ static void bus_kernel_translate_policy(const BusNamePolicy *policy, struct kdbu
         }
 }
 
-int bus_kernel_create_starter(const char *bus, const char *name, BusNamePolicy *policy) {
+int bus_kernel_create_starter(const char *bus, const char *name, bool accept_fd, BusNamePolicy *policy) {
         struct kdbus_cmd_hello *hello;
         struct kdbus_item *n;
         size_t policy_cnt = 0;
@@ -1420,7 +1420,7 @@ int bus_kernel_create_starter(const char *bus, const char *name, BusNamePolicy *
         }
 
         hello->size = size;
-        hello->conn_flags = KDBUS_HELLO_ACTIVATOR|KDBUS_HELLO_ACCEPT_FD;
+        hello->conn_flags = KDBUS_HELLO_ACTIVATOR | (accept_fd ? KDBUS_HELLO_ACCEPT_FD : 0);
         hello->pool_size = KDBUS_POOL_SIZE;
 
         if (ioctl(fd, KDBUS_CMD_HELLO, hello) < 0) {
index a1e9691f1d3cab4da88f67ac384c4ca14e661b36..3a9794fbe3384351a195c8283f8569598d67e1a4 100644 (file)
@@ -67,7 +67,7 @@ int bus_kernel_read_message(sd_bus *bus, bool hint_priority, int64_t priority);
 
 int bus_kernel_create_bus(const char *name, bool world, char **s);
 int bus_kernel_create_domain(const char *name, char **s);
-int bus_kernel_create_starter(const char *bus, const char *name, BusNamePolicy *policy);
+int bus_kernel_create_starter(const char *bus, const char *name, bool accept_fd, BusNamePolicy *policy);
 int bus_kernel_create_monitor(const char *bus);
 
 int bus_kernel_pop_memfd(sd_bus *bus, void **address, size_t *mapped, size_t *allocated);