chiark / gitweb /
dbus: hookup runtime property changes for mouns, services, sockets, swaps too
[elogind.git] / src / core / dbus-socket.c
index 887c80eb893605a54a47f1960a8771174da1cbe5..7ef55ec711cfaf41d36a4abe5848a825e748d82b 100644 (file)
 #include <errno.h>
 
 #include "dbus-unit.h"
-#include "dbus-socket.h"
 #include "dbus-execute.h"
 #include "dbus-kill.h"
+#include "dbus-cgroup.h"
 #include "dbus-common.h"
 #include "selinux-access.h"
+#include "dbus-socket.h"
 
 #define BUS_SOCKET_INTERFACE                                            \
         " <interface name=\"org.freedesktop.systemd1.Socket\">\n"       \
@@ -43,8 +44,6 @@
         "  <property name=\"BindToDevice\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"DirectoryMode\" type=\"u\" access=\"read\"/>\n" \
         "  <property name=\"SocketMode\" type=\"u\" access=\"read\"/>\n" \
-        "  <property name=\"SocketUser\" type=\"s\" access=\"read\"/>\n" \
-        "  <property name=\"SocketGroup\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"Accept\" type=\"b\" access=\"read\"/>\n"    \
         "  <property name=\"KeepAlive\" type=\"b\" access=\"read\"/>\n" \
         "  <property name=\"Priority\" type=\"i\" access=\"read\"/>\n"  \
@@ -64,6 +63,7 @@
         "  <property name=\"NConnections\" type=\"u\" access=\"read\"/>\n" \
         "  <property name=\"MessageQueueMaxMessages\" type=\"x\" access=\"read\"/>\n" \
         "  <property name=\"MessageQueueMessageSize\" type=\"x\" access=\"read\"/>\n" \
+        "  <property name=\"Listen\" type=\"a(ss)\" access=\"read\"/>\n"    \
         "  <property name=\"Result\" type=\"s\" access=\"read\"/>\n"    \
         "  <property name=\"SmackLabel\" type=\"s\" access=\"read\"/>\n" \
         "  <property name=\"SmackLabelIPIn\" type=\"s\" access=\"read\"/>\n" \
@@ -99,6 +99,66 @@ const char bus_socket_invalidating_properties[] =
 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_bind_ipv6_only, socket_address_bind_ipv6_only, SocketAddressBindIPv6Only);
 static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_socket_append_socket_result, socket_result, SocketResult);
 
+static int bus_socket_append_listen(DBusMessageIter *i, const char *property, void *data) {
+
+        Socket *s = SOCKET(data);
+        SocketPort *p;
+        DBusMessageIter array, stru;
+
+        assert(data);
+        assert(property);
+        assert(s);
+
+        if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "(ss)", &array))
+                return log_oom();
+
+        LIST_FOREACH(port, p, s->ports) {
+                const char *type = socket_port_type_to_string(p);
+                _cleanup_free_ char *address = NULL;
+                const char *a;
+
+                if (!dbus_message_iter_open_container(&array, DBUS_TYPE_STRUCT, NULL, &stru))
+                        return log_oom();
+
+                if (!dbus_message_iter_append_basic(&stru, DBUS_TYPE_STRING, &type))
+                        return log_oom();
+
+                switch (p->type) {
+                        case SOCKET_SOCKET: {
+                                int r;
+
+                                r = socket_address_print(&p->address, &address);
+                                if (r) {
+                                        log_error("socket_address_print failed: %s", strerror(-r));
+                                        return r;
+                                }
+                                a = address;
+                                break;
+                        }
+
+                        case SOCKET_SPECIAL:
+                        case SOCKET_MQUEUE:
+                        case SOCKET_FIFO:
+                                a = p->path;
+                                break;
+
+                        default:
+                                a = type;
+                }
+
+                if (!dbus_message_iter_append_basic(&stru, DBUS_TYPE_STRING, &a))
+                        return -ENOMEM;
+
+                if (!dbus_message_iter_close_container(&array, &stru))
+                        return -ENOMEM;
+        }
+
+        if (!dbus_message_iter_close_container(i, &array))
+                return -ENOMEM;
+
+        return 0;
+}
+
 static const BusProperty bus_socket_properties[] = {
         { "BindIPv6Only",   bus_socket_append_bind_ipv6_only,  "s", offsetof(Socket, bind_ipv6_only)  },
         { "Backlog",        bus_property_append_unsigned,      "u", offsetof(Socket, backlog)         },
@@ -111,8 +171,6 @@ static const BusProperty bus_socket_properties[] = {
         { "BindToDevice",   bus_property_append_string,        "s", offsetof(Socket, bind_to_device), true },
         { "DirectoryMode",  bus_property_append_mode,          "u", offsetof(Socket, directory_mode)  },
         { "SocketMode",     bus_property_append_mode,          "u", offsetof(Socket, socket_mode)     },
-        { "SocketUser",     bus_property_append_string,        "s", offsetof(Socket, socket_user),    true },
-        { "SocketGroup",    bus_property_append_string,        "s", offsetof(Socket, socket_group),   true },
         { "Accept",         bus_property_append_bool,          "b", offsetof(Socket, accept)          },
         { "KeepAlive",      bus_property_append_bool,          "b", offsetof(Socket, keep_alive)      },
         { "Priority",       bus_property_append_int,           "i", offsetof(Socket, priority)        },
@@ -126,6 +184,7 @@ static const BusProperty bus_socket_properties[] = {
         { "Broadcast",      bus_property_append_bool,          "b", offsetof(Socket, broadcast)       },
         { "PassCredentials",bus_property_append_bool,          "b", offsetof(Socket, pass_cred)       },
         { "PassSecurity",   bus_property_append_bool,          "b", offsetof(Socket, pass_sec)        },
+        { "Listen",         bus_socket_append_listen,      "a(ss)", 0,                                },
         { "Mark",           bus_property_append_int,           "i", offsetof(Socket, mark)            },
         { "MaxConnections", bus_property_append_unsigned,      "u", offsetof(Socket, max_connections) },
         { "NConnections",   bus_property_append_unsigned,      "u", offsetof(Socket, n_connections)   },
@@ -142,10 +201,11 @@ static const BusProperty bus_socket_properties[] = {
 DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
         Socket *s = SOCKET(u);
         const BusBoundProperties bps[] = {
-                { "org.freedesktop.systemd1.Unit",   bus_unit_properties,         u },
-                { "org.freedesktop.systemd1.Socket", bus_socket_properties,       s },
-                { "org.freedesktop.systemd1.Socket", bus_exec_context_properties, &s->exec_context },
-                { "org.freedesktop.systemd1.Socket", bus_kill_context_properties, &s->kill_context },
+                { "org.freedesktop.systemd1.Unit",   bus_unit_properties,           u },
+                { "org.freedesktop.systemd1.Socket", bus_socket_properties,         s },
+                { "org.freedesktop.systemd1.Socket", bus_exec_context_properties,   &s->exec_context },
+                { "org.freedesktop.systemd1.Socket", bus_kill_context_properties,   &s->kill_context },
+                { "org.freedesktop.systemd1.Socket", bus_cgroup_context_properties, &s->cgroup_context },
                 { NULL, }
         };
 
@@ -153,3 +213,31 @@ DBusHandlerResult bus_socket_message_handler(Unit *u, DBusConnection *c, DBusMes
 
         return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, bps);
 }
+
+int bus_socket_set_property(
+                Unit *u,
+                const char *name,
+                DBusMessageIter *i,
+                UnitSetPropertiesMode mode,
+                DBusError *error) {
+
+        Socket *s = SOCKET(u);
+        int r;
+
+        assert(name);
+        assert(u);
+        assert(i);
+
+        r = bus_cgroup_set_property(u, &s->cgroup_context, name, i, mode, error);
+        if (r != 0)
+                return r;
+
+        return 0;
+}
+
+int bus_socket_commit_properties(Unit *u) {
+        assert(u);
+
+        unit_realize_cgroup(u);
+        return 0;
+}