src/namespace.c \
src/tcpwrap.c \
src/cgroup-util.c \
- src/condition.c
+ src/condition.c \
+ src/dbus-common.c
libsystemd_core_la_CFLAGS = \
$(AM_CFLAGS) \
#include "dbus-unit.h"
#include "dbus-automount.h"
+#include "dbus-common.h"
#define BUS_AUTOMOUNT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Automount\">\n" \
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include <stdio.h>
#include <stdlib.h>
#include <dbus/dbus.h>
+#include <string.h>
#include "log.h"
#include "dbus-common.h"
#include "util.h"
#include "def.h"
+#include "strv.h"
int bus_check_peercred(DBusConnection *c) {
int fd;
return error->message;
}
+
+DBusHandlerResult bus_default_message_handler(
+ DBusConnection *c,
+ DBusMessage *message,
+ const char *introspection,
+ const char *interfaces,
+ const BusProperty *properties) {
+
+ DBusError error;
+ DBusMessage *reply = NULL;
+ int r;
+
+ assert(c);
+ assert(message);
+
+ dbus_error_init(&error);
+
+ if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") && introspection) {
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID))
+ goto oom;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Get") && properties) {
+ const char *interface, *property;
+ const BusProperty *p;
+
+ if (!dbus_message_get_args(
+ message,
+ &error,
+ DBUS_TYPE_STRING, &interface,
+ DBUS_TYPE_STRING, &property,
+ DBUS_TYPE_INVALID))
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+
+ for (p = properties; p->property; p++)
+ if (streq(p->interface, interface) && streq(p->property, property))
+ break;
+
+ if (p->property) {
+ DBusMessageIter iter, sub;
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->signature, &sub))
+ goto oom;
+
+ if ((r = p->append(&sub, property, (void*) p->data)) < 0) {
+
+ if (r == -ENOMEM)
+ goto oom;
+
+ dbus_message_unref(reply);
+ return bus_send_error_reply(c, message, NULL, r);
+ }
+
+ if (!dbus_message_iter_close_container(&iter, &sub))
+ goto oom;
+ } else {
+ if (!nulstr_contains(interfaces, interface))
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ else
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
+
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "GetAll") && properties) {
+ const char *interface;
+ const BusProperty *p;
+ DBusMessageIter iter, sub, sub2, sub3;
+
+ if (!dbus_message_get_args(
+ message,
+ &error,
+ DBUS_TYPE_STRING, &interface,
+ DBUS_TYPE_INVALID))
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+
+ if (interface[0] && !nulstr_contains(interfaces, interface)) {
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+
+ dbus_message_iter_init_append(reply, &iter);
+
+ if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub))
+ goto oom;
+
+ for (p = properties; p->property; p++) {
+ if (interface[0] && !streq(p->interface, interface))
+ continue;
+
+ if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &sub2) ||
+ !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &p->property) ||
+ !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, p->signature, &sub3))
+ goto oom;
+
+ if ((r = p->append(&sub3, p->property, (void*) p->data)) < 0) {
+
+ if (r == -ENOMEM)
+ goto oom;
+
+ dbus_message_unref(reply);
+ return bus_send_error_reply(c, message, NULL, r);
+ }
+
+ if (!dbus_message_iter_close_container(&sub2, &sub3) ||
+ !dbus_message_iter_close_container(&sub, &sub2))
+ goto oom;
+ }
+
+ if (!dbus_message_iter_close_container(&iter, &sub))
+ goto oom;
+
+ } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set") && properties) {
+ const char *interface, *property;
+ DBusMessageIter iter;
+ const BusProperty *p;
+
+ if (!dbus_message_iter_init(message, &iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+
+ dbus_message_iter_get_basic(&iter, &interface);
+
+ if (!dbus_message_iter_next(&iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+
+ dbus_message_iter_get_basic(&iter, &property);
+
+ if (!dbus_message_iter_next(&iter) ||
+ dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT ||
+ dbus_message_iter_has_next(&iter))
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+
+ for (p = properties; p->property; p++)
+ if (streq(p->interface, interface) && streq(p->property, property))
+ break;
+
+ if (p->set) {
+ DBusMessageIter sub;
+ char *sig;
+
+ dbus_message_iter_recurse(&iter, &sub);
+
+ if (!(sig = dbus_message_iter_get_signature(&sub)))
+ goto oom;
+
+ if (!streq(sig, p->signature)) {
+ dbus_free(sig);
+ return bus_send_error_reply(c, message, NULL, -EINVAL);
+ }
+
+ dbus_free(sig);
+
+ if ((r = p->set(&sub, property)) < 0) {
+ if (r == -ENOMEM)
+ goto oom;
+ return bus_send_error_reply(c, message, NULL, r);
+ }
+
+ if (!(reply = dbus_message_new_method_return(message)))
+ goto oom;
+ } else {
+ if (p->property)
+ dbus_set_error_const(&error, DBUS_ERROR_PROPERTY_READ_ONLY, "Property read-only");
+ else if (!nulstr_contains(interfaces, interface))
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ else
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
+
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ } else if (!nulstr_contains(interfaces, dbus_message_get_interface(message))) {
+ dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
+ return bus_send_error_reply(c, message, &error, -EINVAL);
+ }
+
+ if (reply) {
+ if (!dbus_connection_send(c, reply, NULL))
+ goto oom;
+
+ dbus_message_unref(reply);
+ return DBUS_HANDLER_RESULT_HANDLED;
+ }
+
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+oom:
+ if (reply)
+ dbus_message_unref(reply);
+
+ dbus_error_free(&error);
+
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+int bus_property_append_string(DBusMessageIter *i, const char *property, void *data) {
+ const char *t = data;
+
+ assert(i);
+ assert(property);
+
+ if (!t)
+ t = "";
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_strv(DBusMessageIter *i, const char *property, void *data) {
+ DBusMessageIter sub;
+ char **t = data;
+
+ assert(i);
+ assert(property);
+
+ if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub))
+ return -ENOMEM;
+
+ STRV_FOREACH(t, t)
+ if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t))
+ return -ENOMEM;
+
+ if (!dbus_message_iter_close_container(i, &sub))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_bool(DBusMessageIter *i, const char *property, void *data) {
+ bool *b = data;
+ dbus_bool_t db;
+
+ assert(i);
+ assert(property);
+ assert(b);
+
+ db = *b;
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &db))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data) {
+ assert(i);
+ assert(property);
+ assert(data);
+
+ /* Let's ensure that pid_t is actually 64bit, and hence this
+ * function can be used for usec_t */
+ assert_cc(sizeof(uint64_t) == sizeof(usec_t));
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, data))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_uint32(DBusMessageIter *i, const char *property, void *data) {
+ assert(i);
+ assert(property);
+ assert(data);
+
+ /* Let's ensure that pid_t and mode_t is actually 32bit, and
+ * hence this function can be used for pid_t/mode_t */
+ assert_cc(sizeof(uint32_t) == sizeof(pid_t));
+ assert_cc(sizeof(uint32_t) == sizeof(mode_t));
+ assert_cc(sizeof(uint32_t) == sizeof(unsigned));
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, data))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_int32(DBusMessageIter *i, const char *property, void *data) {
+ assert(i);
+ assert(property);
+ assert(data);
+
+ assert_cc(sizeof(int32_t) == sizeof(int));
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, data))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_size(DBusMessageIter *i, const char *property, void *data) {
+ uint64_t u;
+
+ assert(i);
+ assert(property);
+ assert(data);
+
+ u = (uint64_t) *(size_t*) data;
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
+ return -ENOMEM;
+
+ return 0;
+}
+
+int bus_property_append_ul(DBusMessageIter *i, const char *property, void *data) {
+ uint64_t u;
+
+ assert(i);
+ assert(property);
+ assert(data);
+
+ u = (uint64_t) *(unsigned long*) data;
+
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
+ return -ENOMEM;
+
+ return 0;
+}
+
+const char *bus_errno_to_dbus(int error) {
+
+ switch(error) {
+
+ case -EINVAL:
+ return DBUS_ERROR_INVALID_ARGS;
+
+ case -ENOMEM:
+ return DBUS_ERROR_NO_MEMORY;
+
+ case -EPERM:
+ case -EACCES:
+ return DBUS_ERROR_ACCESS_DENIED;
+
+ case -ESRCH:
+ return DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN;
+
+ case -ENOENT:
+ return DBUS_ERROR_FILE_NOT_FOUND;
+
+ case -EEXIST:
+ return DBUS_ERROR_FILE_EXISTS;
+
+ case -ETIMEDOUT:
+ case -ETIME:
+ return DBUS_ERROR_TIMEOUT;
+
+ case -EIO:
+ return DBUS_ERROR_IO_ERROR;
+
+ case -ENETRESET:
+ case -ECONNABORTED:
+ case -ECONNRESET:
+ return DBUS_ERROR_DISCONNECTED;
+ }
+
+ return DBUS_ERROR_FAILED;
+}
+
+DBusHandlerResult bus_send_error_reply(DBusConnection *c, DBusMessage *message, DBusError *berror, int error) {
+ DBusMessage *reply = NULL;
+ const char *name, *text;
+
+ if (berror && dbus_error_is_set(berror)) {
+ name = berror->name;
+ text = berror->message;
+ } else {
+ name = bus_errno_to_dbus(error);
+ text = strerror(-error);
+ }
+
+ if (!(reply = dbus_message_new_error(message, name, text)))
+ goto oom;
+
+ if (!dbus_connection_send(c, reply, NULL))
+ goto oom;
+
+ dbus_message_unref(reply);
+
+ if (berror)
+ dbus_error_free(berror);
+
+ return DBUS_HANDLER_RESULT_HANDLED;
+
+oom:
+ if (reply)
+ dbus_message_unref(reply);
+
+ if (berror)
+ dbus_error_free(berror);
+
+ return DBUS_HANDLER_RESULT_NEED_MEMORY;
+}
+
+DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties) {
+ DBusMessage *m;
+ DBusMessageIter iter, sub;
+ const char *i;
+
+ assert(interface);
+ assert(properties);
+
+ if (!(m = dbus_message_new_signal(path, "org.freedesktop.DBus.Properties", "PropertiesChanged")))
+ goto oom;
+
+ dbus_message_iter_init_append(m, &iter);
+
+ /* We won't send any property values, since they might be
+ * large and sometimes not cheap to generated */
+
+ if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface) ||
+ !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub) ||
+ !dbus_message_iter_close_container(&iter, &sub) ||
+ !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub))
+ goto oom;
+
+ NULSTR_FOREACH(i, properties)
+ if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &i))
+ goto oom;
+
+ if (!dbus_message_iter_close_container(&iter, &sub))
+ goto oom;
+
+ return m;
+
+oom:
+ if (m)
+ dbus_message_unref(m);
+
+ return NULL;
+}
#include <dbus/dbus.h>
+#ifndef DBUS_ERROR_UNKNOWN_OBJECT
+#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
+#endif
+
+#ifndef DBUS_ERROR_UNKNOWN_INTERFACE
+#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
+#endif
+
+#ifndef DBUS_ERROR_UNKNOWN_PROPERTY
+#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
+#endif
+
+#ifndef DBUS_ERROR_PROPERTY_READ_ONLY
+#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
+#endif
+
+#define BUS_PROPERTIES_INTERFACE \
+ " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
+ " <method name=\"Get\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
+ " </method>\n" \
+ " <method name=\"GetAll\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
+ " </method>\n" \
+ " <method name=\"Set\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"value\" direction=\"in\" type=\"v\"/>\n" \
+ " </method>\n" \
+ " <signal name=\"PropertiesChanged\">\n" \
+ " <arg type=\"s\" name=\"interface\"/>\n" \
+ " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
+ " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
+ " </signal>\n" \
+ " </interface>\n"
+
+#define BUS_INTROSPECTABLE_INTERFACE \
+ " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
+ " <method name=\"Introspect\">\n" \
+ " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " </interface>\n"
+
+#define BUS_PEER_INTERFACE \
+ "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
+ " <method name=\"Ping\"/>\n" \
+ " <method name=\"GetMachineId\">\n" \
+ " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ "</interface>\n"
+
+#define BUS_GENERIC_INTERFACES_LIST \
+ "org.freedesktop.DBus.Properties\0" \
+ "org.freedesktop.DBus.Introspectable\0" \
+ "org.freedesktop.DBus.Peer\0"
+
int bus_check_peercred(DBusConnection *c);
int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private_bus, DBusError *error);
const char *bus_error_message(const DBusError *error);
+typedef int (*BusPropertyCallback)(DBusMessageIter *iter, const char *property, void *data);
+typedef int (*BusPropertySetCallback)(DBusMessageIter *iter, const char *property);
+
+typedef struct BusProperty {
+ const char *interface; /* interface of the property */
+ const char *property; /* name of the property */
+ BusPropertyCallback append; /* Function that is called to serialize this property */
+ const char *signature;
+ const void *data; /* The data of this property */
+ BusPropertySetCallback set; /* Optional: Function that is called to set this property */
+} BusProperty;
+
+DBusHandlerResult bus_send_error_reply(
+ DBusConnection *c,
+ DBusMessage *message,
+ DBusError *bus_error,
+ int error);
+
+DBusHandlerResult bus_default_message_handler(
+ DBusConnection *c,
+ DBusMessage *message,
+ const char *introspection,
+ const char *interfaces,
+ const BusProperty *properties);
+
+int bus_property_append_string(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_strv(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_bool(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_int32(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_uint32(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_uint64(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_size(DBusMessageIter *i, const char *property, void *data);
+int bus_property_append_ul(DBusMessageIter *i, const char *property, void *data);
+
+#define bus_property_append_int bus_property_append_int32
+#define bus_property_append_pid bus_property_append_uint32
+#define bus_property_append_mode bus_property_append_uint32
+#define bus_property_append_unsigned bus_property_append_uint32
+#define bus_property_append_usec bus_property_append_uint64
+
+#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
+ int function(DBusMessageIter *i, const char *property, void *data) { \
+ const char *value; \
+ type *field = data; \
+ \
+ assert(i); \
+ assert(property); \
+ \
+ value = name##_to_string(*field); \
+ \
+ if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
+ return -ENOMEM; \
+ \
+ return 0; \
+ }
+
+const char *bus_errno_to_dbus(int error);
+
+DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
+
#endif
#include "dbus-unit.h"
#include "dbus-device.h"
+#include "dbus-common.h"
#define BUS_DEVICE_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Device\">\n" \
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "missing.h"
#include "ioprio.h"
#include "strv.h"
+#include "dbus-common.h"
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_kill_mode, kill_mode, KillMode);
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput);
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput);
-int bus_execute_append_env_files(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_env_files(DBusMessageIter *i, const char *property, void *data) {
char **env_files = data, **j;
DBusMessageIter sub, sub2;
- assert(m);
assert(i);
assert(property);
return 0;
}
-int bus_execute_append_oom_score_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_oom_score_adjust(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_nice(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_ioprio(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_cpu_sched_policy(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_cpu_sched_priority(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_affinity(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
dbus_bool_t b;
DBusMessageIter sub;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_timer_slack_nsec(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_timer_slack_nsec(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
uint64_t u;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_capability_bs(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_capability_bs(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
uint64_t normal, inverted;
- assert(m);
assert(i);
assert(property);
assert(c);
normal = *(uint64_t*) data;
inverted = ~normal;
- return bus_property_append_uint64(m, i, property, &inverted);
+ return bus_property_append_uint64(i, property, &inverted);
}
-int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_capabilities(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
char *t = NULL;
const char *s;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_rlimits(DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int r;
uint64_t u;
- assert(m);
assert(i);
assert(property);
assert(c);
return 0;
}
-int bus_execute_append_command(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_command(DBusMessageIter *i, const char *property, void *data) {
ExecCommand *c = data;
DBusMessageIter sub, sub2, sub3;
- assert(m);
assert(i);
assert(property);
#define BUS_EXEC_COMMAND_PROPERTY(interface, command, name) \
{ interface, name, bus_execute_append_command, "a(sasbttttuii)", (command) }
-int bus_execute_append_output(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_input(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_oom_score_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_cpu_sched_priority(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_affinity(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_timer_slack_nsec(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_capabilities(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_capability_bs(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_rlimits(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_command(Manager *m, DBusMessageIter *u, const char *property, void *data);
-int bus_execute_append_kill_mode(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_env_files(Manager *m, DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_output(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_input(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_oom_score_adjust(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_nice(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_ioprio(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_cpu_sched_policy(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_cpu_sched_priority(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_affinity(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_timer_slack_nsec(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_capabilities(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_capability_bs(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_rlimits(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_command(DBusMessageIter *u, const char *property, void *data);
+int bus_execute_append_kill_mode(DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_env_files(DBusMessageIter *i, const char *property, void *data);
#endif
#include "dbus.h"
#include "log.h"
#include "dbus-job.h"
+#include "dbus-common.h"
#define BUS_JOB_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Job\">\n" \
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_state, job_state, JobState);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_job_append_type, job_type, JobType);
-static int bus_job_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_job_append_unit(DBusMessageIter *i, const char *property, void *data) {
Job *j = data;
DBusMessageIter sub;
char *p;
- assert(m);
assert(i);
assert(property);
assert(j);
job_finish_and_invalidate(j, JOB_CANCELED);
} else
- return bus_default_message_handler(j->manager, connection, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
if (reply) {
if (!dbus_connection_send(connection, reply, NULL))
dbus_error_init(&e);
dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown job");
- return bus_send_error_reply(m, connection, message, &e, r);
+ return bus_send_error_reply(connection, message, &e, r);
}
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
return bus_job_message_dispatch(j, connection, message);
#include "strv.h"
#include "bus-errors.h"
#include "build.h"
+#include "dbus-common.h"
#define BUS_MANAGER_INTERFACE_BEGIN \
" <interface name=\"org.freedesktop.systemd1.Manager\">\n"
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_running_as, manager_running_as, ManagerRunningAs);
static DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_manager_append_exec_output, exec_output, ExecOutput);
-static int bus_manager_append_tainted(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_tainted(DBusMessageIter *i, const char *property, void *data) {
const char *t;
+ Manager *m = data;
char buf[LINE_MAX] = "", *e = buf, *p = NULL;
- assert(m);
assert(i);
assert(property);
+ assert(m);
if (m->taint_usr)
e = stpcpy(e, "usr-separate-fs ");
return 0;
}
-static int bus_manager_append_log_target(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_log_target(DBusMessageIter *i, const char *property, void *data) {
const char *t;
- assert(m);
assert(i);
assert(property);
return 0;
}
-static int bus_manager_set_log_target(Manager *m, DBusMessageIter *i, const char *property) {
+static int bus_manager_set_log_target(DBusMessageIter *i, const char *property) {
const char *t;
- assert(m);
assert(i);
assert(property);
return log_set_target_from_string(t);
}
-static int bus_manager_append_log_level(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_log_level(DBusMessageIter *i, const char *property, void *data) {
const char *t;
- assert(m);
assert(i);
assert(property);
return 0;
}
-static int bus_manager_set_log_level(Manager *m, DBusMessageIter *i, const char *property) {
+static int bus_manager_set_log_level(DBusMessageIter *i, const char *property) {
const char *t;
- assert(m);
assert(i);
assert(property);
return log_set_max_level_from_string(t);
}
-static int bus_manager_append_n_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_n_names(DBusMessageIter *i, const char *property, void *data) {
+ Manager *m = data;
uint32_t u;
- assert(m);
assert(i);
assert(property);
+ assert(m);
u = hashmap_size(m->units);
return 0;
}
-static int bus_manager_append_n_jobs(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_n_jobs(DBusMessageIter *i, const char *property, void *data) {
+ Manager *m = data;
uint32_t u;
- assert(m);
assert(i);
assert(property);
+ assert(m);
u = hashmap_size(m->jobs);
return 0;
}
-static int bus_manager_append_progress(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_manager_append_progress(DBusMessageIter *i, const char *property, void *data) {
double d;
+ Manager *m = data;
- assert(m);
assert(i);
assert(property);
+ assert(m);
if (dual_timestamp_is_set(&m->finish_timestamp))
d = 1.0;
{ "org.freedesktop.systemd1.Manager", "StartupTimestampMonotonic", bus_property_append_uint64, "t", &m->startup_timestamp.monotonic },
{ "org.freedesktop.systemd1.Manager", "FinishTimestamp", bus_property_append_uint64, "t", &m->finish_timestamp.realtime },
{ "org.freedesktop.systemd1.Manager", "FinishTimestampMonotonic", bus_property_append_uint64, "t",&m->finish_timestamp.monotonic },
- { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", NULL, bus_manager_set_log_level},
- { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", NULL, bus_manager_set_log_target},
- { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", NULL },
+ { "org.freedesktop.systemd1.Manager", "LogLevel", bus_manager_append_log_level, "s", m, bus_manager_set_log_level },
+ { "org.freedesktop.systemd1.Manager", "LogTarget", bus_manager_append_log_target, "s", m, bus_manager_set_log_target },
+ { "org.freedesktop.systemd1.Manager", "NNames", bus_manager_append_n_names, "u", m },
{ "org.freedesktop.systemd1.Manager", "NJobs", bus_manager_append_n_jobs, "u", NULL },
{ "org.freedesktop.systemd1.Manager", "NInstalledJobs",bus_property_append_uint32, "u", &m->n_installed_jobs },
{ "org.freedesktop.systemd1.Manager", "NFailedJobs", bus_property_append_uint32, "u", &m->n_failed_jobs },
- { "org.freedesktop.systemd1.Manager", "Progress", bus_manager_append_progress, "d", NULL },
+ { "org.freedesktop.systemd1.Manager", "Progress", bus_manager_append_progress, "d", m },
{ "org.freedesktop.systemd1.Manager", "Environment", bus_property_append_strv, "as", m->environment },
{ "org.freedesktop.systemd1.Manager", "ConfirmSpawn", bus_property_append_bool, "b", &m->confirm_spawn },
{ "org.freedesktop.systemd1.Manager", "ShowStatus", bus_property_append_bool, "b", &m->show_status },
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = manager_get_unit(m, name))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if (!(reply = dbus_message_new_method_return(message)))
&error,
DBUS_TYPE_UINT32, &pid,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = cgroup_unit_by_pid(m, (pid_t) pid))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "No unit for PID %lu is loaded.", (unsigned long) pid);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if (!(reply = dbus_message_new_method_return(message)))
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INT32, &signo,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((mode = kill_mode_from_string(smode)) < 0 ||
(who = kill_who_from_string(swho)) < 0 ||
signo <= 0 ||
signo >= _NSIG)
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = manager_get_unit(m, name))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
&error,
DBUS_TYPE_UINT32, &id,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(j = manager_get_job(m, id))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "Job %u does not exist.", (unsigned) id);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if (!(reply = dbus_message_new_method_return(message)))
&error,
DBUS_TYPE_STRING, &name,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (!(u = manager_get_unit(m, name))) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_UNIT, "Unit %s is not loaded.", name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
unit_reset_failed(u);
if ((r = set_put(s, client)) < 0) {
free(client);
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
if (!(reply = dbus_message_new_method_return(message)))
if (!(client = set_remove(BUS_CONNECTION_SUBSCRIBED(m, connection), (char*) message_get_sender_with_fallback(message)))) {
dbus_set_error(&error, BUS_ERROR_NOT_SUBSCRIBED, "Client is not subscribed.");
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
free(client);
DBUS_TYPE_STRING, &name,
DBUS_TYPE_BOOLEAN, &cleanup,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (name && name[0] == 0)
name = NULL;
if ((r = snapshot_create(m, name, cleanup, &error, &s)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
if (m->running_as == MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Exit is only supported for user service managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Reboot is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Powering off is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "Halting is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
if (m->running_as != MANAGER_SYSTEM) {
dbus_set_error(&error, BUS_ERROR_NOT_SUPPORTED, "kexec is only supported for system managers.");
- return bus_send_error_reply(m, connection, message, &error, -ENOTSUP);
+ return bus_send_error_reply(connection, message, &error, -ENOTSUP);
}
if (!(reply = dbus_message_new_method_return(message)))
if (r == -ENOMEM)
goto oom;
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
e = strv_env_merge(2, m->environment, l);
if (r == -ENOMEM)
goto oom;
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
e = strv_env_delete(m->environment, 1, l);
m->environment = e;
} else
- return bus_default_message_handler(m, connection, message, NULL, INTERFACES_LIST, properties);
+ return bus_default_message_handler(connection, message, NULL, INTERFACES_LIST, properties);
if (job_type != _JOB_TYPE_INVALID) {
const char *name, *smode, *old_name = NULL;
DBUS_TYPE_INVALID);
if (!b)
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (old_name)
if (!(u = manager_get_unit(m, old_name)) ||
!u->meta.job ||
u->meta.job->type != JOB_START) {
dbus_set_error(&error, BUS_ERROR_NO_SUCH_JOB, "No job queued for unit %s", old_name);
- return bus_send_error_reply(m, connection, message, &error, -ENOENT);
+ return bus_send_error_reply(connection, message, &error, -ENOENT);
}
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
}
if ((r = manager_load_unit(m, name, NULL, &error, &u)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (reload_if_possible && unit_can_reload(u)) {
if (job_type == JOB_RESTART)
((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
(u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
- return bus_send_error_reply(m, connection, message, &error, -EPERM);
+ return bus_send_error_reply(connection, message, &error, -EPERM);
}
if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(j->bus_client = strdup(message_get_sender_with_fallback(message))))
goto oom;
#include "dbus-unit.h"
#include "dbus-mount.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_MOUNT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Mount\">\n" \
"ExecRemount\0"
"ControlPID\0";
-static int bus_mount_append_what(Manager *n, DBusMessageIter *i, const char *property, void *data) {
+static int bus_mount_append_what(DBusMessageIter *i, const char *property, void *data) {
Mount *m = data;
const char *d;
- assert(n);
assert(i);
assert(property);
assert(m);
return 0;
}
-static int bus_mount_append_options(Manager *n, DBusMessageIter *i, const char *property, void *data) {
+static int bus_mount_append_options(DBusMessageIter *i, const char *property, void *data) {
Mount *m = data;
const char *d;
- assert(n);
assert(i);
assert(property);
assert(m);
return 0;
}
-static int bus_mount_append_type(Manager *n, DBusMessageIter *i, const char *property, void *data) {
+static int bus_mount_append_type(DBusMessageIter *i, const char *property, void *data) {
Mount *m = data;
const char *d;
- assert(n);
assert(i);
assert(property);
assert(m);
}
DBusHandlerResult bus_mount_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
+
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Mount", "Where", bus_property_append_string, "s", u->mount.where },
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "dbus-unit.h"
#include "dbus-path.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_PATH_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Path\">\n" \
const char bus_path_interface[] _introspect_("Path") = BUS_PATH_INTERFACE;
-static int bus_path_append_paths(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_path_append_paths(DBusMessageIter *i, const char *property, void *data) {
Path *p = data;
DBusMessageIter sub, sub2;
PathSpec *k;
- assert(m);
assert(i);
assert(property);
assert(p);
return 0;
}
-static int bus_path_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_path_append_unit(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *t;
- assert(m);
assert(i);
assert(property);
assert(u);
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "dbus-unit.h"
#include "dbus-execute.h"
#include "dbus-service.h"
+#include "dbus-common.h"
#ifdef HAVE_SYSV_COMPAT
#define BUS_SERVICE_SYSV_INTERFACE_FRAGMENT \
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, connection, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(connection, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "dbus-unit.h"
#include "dbus-snapshot.h"
+#include "dbus-common.h"
#define BUS_SNAPSHOT_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Snapshot\">\n" \
const char bus_snapshot_interface[] _introspect_("Snapshot") = BUS_SNAPSHOT_INTERFACE;
DBusHandlerResult bus_snapshot_message_handler(Unit *u, DBusConnection *c, DBusMessage *message) {
+
const BusProperty properties[] = {
BUS_UNIT_PROPERTIES,
{ "org.freedesktop.systemd1.Snapshot", "Cleanup", bus_property_append_bool, "b", &u->snapshot.cleanup },
goto oom;
} else
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
if (reply) {
if (!dbus_connection_send(c, reply, NULL))
#include "dbus-unit.h"
#include "dbus-socket.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_SOCKET_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Socket\">\n" \
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "dbus-unit.h"
#include "dbus-swap.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_SWAP_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Swap\">\n" \
"ExecDeactivate\0"
"ControlPID\0";
-static int bus_swap_append_priority(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_swap_append_priority(DBusMessageIter *i, const char *property, void *data) {
Swap *s = data;
dbus_int32_t j;
- assert(m);
assert(i);
assert(property);
assert(s);
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "dbus-unit.h"
#include "dbus-target.h"
+#include "dbus-common.h"
#define BUS_TARGET_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Target\">\n" \
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "dbus-unit.h"
#include "dbus-timer.h"
#include "dbus-execute.h"
+#include "dbus-common.h"
#define BUS_TIMER_INTERFACE \
" <interface name=\"org.freedesktop.systemd1.Timer\">\n" \
"Timers\0"
"NextElapseUSec\0";
-static int bus_timer_append_timers(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_timer_append_timers(DBusMessageIter *i, const char *property, void *data) {
Timer *p = data;
DBusMessageIter sub, sub2;
TimerValue *k;
- assert(m);
assert(i);
assert(property);
assert(p);
return 0;
}
-static int bus_timer_append_unit(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+static int bus_timer_append_unit(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *t;
- assert(m);
assert(i);
assert(property);
assert(u);
{ NULL, NULL, NULL, NULL, NULL }
};
- return bus_default_message_handler(u->meta.manager, c, message, INTROSPECTION, INTERFACES_LIST, properties);
+ return bus_default_message_handler(c, message, INTROSPECTION, INTERFACES_LIST, properties);
}
#include "log.h"
#include "dbus-unit.h"
#include "bus-errors.h"
+#include "dbus-common.h"
const char bus_unit_interface[] _introspect_("Unit") = BUS_UNIT_INTERFACE;
"Job\0" \
"NeedDaemonReload\0"
-int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_names(DBusMessageIter *i, const char *property, void *data) {
char *t;
Iterator j;
DBusMessageIter sub;
return 0;
}
-int bus_unit_append_following(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_following(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data, *f;
const char *d;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_dependencies(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_dependencies(DBusMessageIter *i, const char *property, void *data) {
Unit *u;
Iterator j;
DBusMessageIter sub;
return 0;
}
-int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_description(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *d;
- assert(m);
assert(i);
assert(property);
assert(u);
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_unit_append_load_state, unit_load_state, UnitLoadState);
-int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_active_state(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *state;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
const char *state;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_can_stop(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_stop(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_reload(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_can_isolate(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_can_isolate(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_job(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
DBusMessageIter sub;
char *p;
- assert(m);
assert(i);
assert(property);
assert(u);
return 0;
}
-int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_default_cgroup(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
char *t;
CGroupBonding *cgb;
bool success;
- assert(m);
assert(i);
assert(property);
assert(u);
return success ? 0 : -ENOMEM;
}
-int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_cgroups(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
CGroupBonding *cgb;
DBusMessageIter sub;
return 0;
}
-int bus_unit_append_need_daemon_reload(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data) {
Unit *u = data;
dbus_bool_t b;
- assert(m);
assert(i);
assert(property);
assert(u);
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INT32, &signo,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((mode = kill_mode_from_string(smode)) < 0 ||
(who = kill_who_from_string(swho)) < 0 ||
signo <= 0 ||
signo >= _NSIG)
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if ((r = unit_kill(u, who, mode, signo, &error)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
((job_type == JOB_RESTART || job_type == JOB_TRY_RESTART) &&
(u->meta.refuse_manual_start || u->meta.refuse_manual_stop))) {
dbus_set_error(&error, BUS_ERROR_ONLY_BY_DEPENDENCY, "Operation refused, may be requested by dependency only.");
- return bus_send_error_reply(m, connection, message, &error, -EPERM);
+ return bus_send_error_reply(connection, message, &error, -EPERM);
}
if (!dbus_message_get_args(
&error,
DBUS_TYPE_STRING, &smode,
DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
if (reload_if_possible && unit_can_reload(u)) {
if (job_type == JOB_RESTART)
if ((mode = job_mode_from_string(smode)) == _JOB_MODE_INVALID) {
dbus_set_error(&error, BUS_ERROR_INVALID_JOB_MODE, "Job mode %s is invalid.", smode);
- return bus_send_error_reply(m, connection, message, &error, -EINVAL);
+ return bus_send_error_reply(connection, message, &error, -EINVAL);
}
if ((r = manager_add_job(m, job_type, u, mode, true, &error, &j)) < 0)
- return bus_send_error_reply(m, connection, message, &error, r);
+ return bus_send_error_reply(connection, message, &error, r);
if (!(reply = dbus_message_new_method_return(message)))
goto oom;
dbus_error_init(&e);
dbus_set_error_const(&e, DBUS_ERROR_UNKNOWN_OBJECT, "Unknown unit");
- return bus_send_error_reply(m, connection, message, &e, r);
+ return bus_send_error_reply(connection, message, &e, r);
}
- return bus_send_error_reply(m, connection, message, NULL, r);
+ return bus_send_error_reply(connection, message, NULL, r);
}
return bus_unit_message_dispatch(u, connection, message);
{ "org.freedesktop.systemd1.Unit", "ConditionTimestampMonotonic", bus_property_append_usec,"t", &u->meta.condition_timestamp.monotonic }, \
{ "org.freedesktop.systemd1.Unit", "ConditionResult", bus_property_append_bool, "b", &u->meta.condition_result }
-int bus_unit_append_names(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_following(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_dependencies(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_description(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_load_state(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_active_state(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_sub_state(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_start(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_stop(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_reload(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_can_isolate(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_job(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_default_cgroup(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_cgroups(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_unit_append_need_daemon_reload(Manager *m, DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_names(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_following(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_dependencies(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_description(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_load_state(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_active_state(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_sub_state(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_start(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_stop(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_reload(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_can_isolate(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_job(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_default_cgroup(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_cgroups(DBusMessageIter *i, const char *property, void *data);
+int bus_unit_append_need_daemon_reload(DBusMessageIter *i, const char *property, void *data);
void bus_unit_send_change_signal(Unit *u);
void bus_unit_send_removed_signal(Unit *u);
#include "dbus-path.h"
#include "bus-errors.h"
#include "special.h"
+#include "dbus-common.h"
#define CONNECTIONS_MAX 52
NULL
};
-static const char *error_to_dbus(int error);
static void bus_done_api(Manager *m);
static void bus_done_system(Manager *m);
static void bus_done_private(Manager *m);
if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure")))
goto oom;
- id = error.name ? error.name : error_to_dbus(r);
+ id = error.name ? error.name : bus_errno_to_dbus(r);
text = bus_error(&error, r);
if (!dbus_message_set_destination(reply, DBUS_SERVICE_DBUS) ||
return -ENOMEM;
}
-DBusHandlerResult bus_default_message_handler(
- Manager *m,
- DBusConnection *c,
- DBusMessage *message,
- const char *introspection,
- const char *interfaces,
- const BusProperty *properties) {
-
- DBusError error;
- DBusMessage *reply = NULL;
- int r;
-
- assert(m);
- assert(c);
- assert(message);
-
- dbus_error_init(&error);
-
- if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Introspectable", "Introspect") && introspection) {
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- if (!dbus_message_append_args(reply, DBUS_TYPE_STRING, &introspection, DBUS_TYPE_INVALID))
- goto oom;
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Get") && properties) {
- const char *interface, *property;
- const BusProperty *p;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_STRING, &property,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
-
- for (p = properties; p->property; p++)
- if (streq(p->interface, interface) && streq(p->property, property))
- break;
-
- if (p->property) {
- DBusMessageIter iter, sub;
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- dbus_message_iter_init_append(reply, &iter);
-
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, p->signature, &sub))
- goto oom;
-
- if ((r = p->append(m, &sub, property, (void*) p->data)) < 0) {
-
- if (r == -ENOMEM)
- goto oom;
-
- dbus_message_unref(reply);
- return bus_send_error_reply(m, c, message, NULL, r);
- }
-
- if (!dbus_message_iter_close_container(&iter, &sub))
- goto oom;
- } else {
- if (!nulstr_contains(interfaces, interface))
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- else
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
-
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "GetAll") && properties) {
- const char *interface;
- const BusProperty *p;
- DBusMessageIter iter, sub, sub2, sub3;
-
- if (!dbus_message_get_args(
- message,
- &error,
- DBUS_TYPE_STRING, &interface,
- DBUS_TYPE_INVALID))
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
-
- if (interface[0] && !nulstr_contains(interfaces, interface)) {
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
-
- dbus_message_iter_init_append(reply, &iter);
-
- if (!dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub))
- goto oom;
-
- for (p = properties; p->property; p++) {
- if (interface[0] && !streq(p->interface, interface))
- continue;
-
- if (!dbus_message_iter_open_container(&sub, DBUS_TYPE_DICT_ENTRY, NULL, &sub2) ||
- !dbus_message_iter_append_basic(&sub2, DBUS_TYPE_STRING, &p->property) ||
- !dbus_message_iter_open_container(&sub2, DBUS_TYPE_VARIANT, p->signature, &sub3))
- goto oom;
-
- if ((r = p->append(m, &sub3, p->property, (void*) p->data)) < 0) {
-
- if (r == -ENOMEM)
- goto oom;
-
- dbus_message_unref(reply);
- return bus_send_error_reply(m, c, message, NULL, r);
- }
-
- if (!dbus_message_iter_close_container(&sub2, &sub3) ||
- !dbus_message_iter_close_container(&sub, &sub2))
- goto oom;
- }
-
- if (!dbus_message_iter_close_container(&iter, &sub))
- goto oom;
-
- } else if (dbus_message_is_method_call(message, "org.freedesktop.DBus.Properties", "Set") && properties) {
- const char *interface, *property;
- DBusMessageIter iter;
- const BusProperty *p;
-
- if (!dbus_message_iter_init(message, &iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
-
- dbus_message_iter_get_basic(&iter, &interface);
-
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
-
- dbus_message_iter_get_basic(&iter, &property);
-
- if (!dbus_message_iter_next(&iter) ||
- dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT ||
- dbus_message_iter_has_next(&iter))
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
-
- for (p = properties; p->property; p++)
- if (streq(p->interface, interface) && streq(p->property, property))
- break;
-
- if (p->set) {
- DBusMessageIter sub;
- char *sig;
-
- dbus_message_iter_recurse(&iter, &sub);
-
- if (!(sig = dbus_message_iter_get_signature(&sub)))
- goto oom;
-
- if (!streq(sig, p->signature)) {
- dbus_free(sig);
- return bus_send_error_reply(m, c, message, NULL, -EINVAL);
- }
-
- dbus_free(sig);
-
- if ((r = p->set(m, &sub, property)) < 0) {
- if (r == -ENOMEM)
- goto oom;
- return bus_send_error_reply(m, c, message, NULL, r);
- }
-
- if (!(reply = dbus_message_new_method_return(message)))
- goto oom;
- } else {
- if (p->property)
- dbus_set_error_const(&error, DBUS_ERROR_PROPERTY_READ_ONLY, "Property read-only");
- else if (!nulstr_contains(interfaces, interface))
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- else
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_PROPERTY, "Unknown property");
-
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- } else if (!nulstr_contains(interfaces, dbus_message_get_interface(message))) {
- dbus_set_error_const(&error, DBUS_ERROR_UNKNOWN_INTERFACE, "Unknown interface");
- return bus_send_error_reply(m, c, message, &error, -EINVAL);
- }
-
- if (reply) {
- if (!dbus_connection_send(c, reply, NULL))
- goto oom;
-
- dbus_message_unref(reply);
- return DBUS_HANDLER_RESULT_HANDLED;
- }
-
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-oom:
- if (reply)
- dbus_message_unref(reply);
-
- dbus_error_free(&error);
-
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-}
-
-static const char *error_to_dbus(int error) {
-
- switch(error) {
-
- case -EINVAL:
- return DBUS_ERROR_INVALID_ARGS;
-
- case -ENOMEM:
- return DBUS_ERROR_NO_MEMORY;
-
- case -EPERM:
- case -EACCES:
- return DBUS_ERROR_ACCESS_DENIED;
-
- case -ESRCH:
- return DBUS_ERROR_UNIX_PROCESS_ID_UNKNOWN;
-
- case -ENOENT:
- return DBUS_ERROR_FILE_NOT_FOUND;
-
- case -EEXIST:
- return DBUS_ERROR_FILE_EXISTS;
-
- case -ETIMEDOUT:
- case -ETIME:
- return DBUS_ERROR_TIMEOUT;
-
- case -EIO:
- return DBUS_ERROR_IO_ERROR;
-
- case -ENETRESET:
- case -ECONNABORTED:
- case -ECONNRESET:
- return DBUS_ERROR_DISCONNECTED;
- }
-
- return DBUS_ERROR_FAILED;
-}
-
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *berror, int error) {
- DBusMessage *reply = NULL;
- const char *name, *text;
-
- if (berror && dbus_error_is_set(berror)) {
- name = berror->name;
- text = berror->message;
- } else {
- name = error_to_dbus(error);
- text = strerror(-error);
- }
-
- if (!(reply = dbus_message_new_error(message, name, text)))
- goto oom;
-
- if (!dbus_connection_send(c, reply, NULL))
- goto oom;
-
- dbus_message_unref(reply);
-
- if (berror)
- dbus_error_free(berror);
-
- return DBUS_HANDLER_RESULT_HANDLED;
-
-oom:
- if (reply)
- dbus_message_unref(reply);
-
- if (berror)
- dbus_error_free(berror);
-
- return DBUS_HANDLER_RESULT_NEED_MEMORY;
-}
-
int bus_broadcast(Manager *m, DBusMessage *message) {
bool oom = false;
Iterator i;
return oom ? -ENOMEM : 0;
}
-int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- const char *t = data;
-
- assert(m);
- assert(i);
- assert(property);
-
- if (!t)
- t = "";
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &t))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- DBusMessageIter sub;
- char **t = data;
-
- assert(m);
- assert(i);
- assert(property);
-
- if (!dbus_message_iter_open_container(i, DBUS_TYPE_ARRAY, "s", &sub))
- return -ENOMEM;
-
- STRV_FOREACH(t, t)
- if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, t))
- return -ENOMEM;
-
- if (!dbus_message_iter_close_container(i, &sub))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- bool *b = data;
- dbus_bool_t db;
-
- assert(m);
- assert(i);
- assert(property);
- assert(b);
-
- db = *b;
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_BOOLEAN, &db))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- /* Let's ensure that pid_t is actually 64bit, and hence this
- * function can be used for usec_t */
- assert_cc(sizeof(uint64_t) == sizeof(usec_t));
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, data))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- /* Let's ensure that pid_t and mode_t is actually 32bit, and
- * hence this function can be used for pid_t/mode_t */
- assert_cc(sizeof(uint32_t) == sizeof(pid_t));
- assert_cc(sizeof(uint32_t) == sizeof(mode_t));
- assert_cc(sizeof(uint32_t) == sizeof(unsigned));
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT32, data))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- assert_cc(sizeof(int32_t) == sizeof(int));
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_INT32, data))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_size(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- uint64_t u;
-
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- u = (uint64_t) *(size_t*) data;
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
- return -ENOMEM;
-
- return 0;
-}
-
-int bus_property_append_ul(Manager *m, DBusMessageIter *i, const char *property, void *data) {
- uint64_t u;
-
- assert(m);
- assert(i);
- assert(property);
- assert(data);
-
- u = (uint64_t) *(unsigned long*) data;
-
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_UINT64, &u))
- return -ENOMEM;
-
- return 0;
-}
-
int bus_parse_strv(DBusMessage *m, char ***_l) {
DBusMessageIter iter, sub;
unsigned n = 0, i = 0;
return !set_isempty(BUS_CONNECTION_SUBSCRIBED(m, c));
}
-
-DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties) {
- DBusMessage *m;
- DBusMessageIter iter, sub;
- const char *i;
-
- assert(interface);
- assert(properties);
-
- if (!(m = dbus_message_new_signal(path, "org.freedesktop.DBus.Properties", "PropertiesChanged")))
- goto oom;
-
- dbus_message_iter_init_append(m, &iter);
-
- /* We won't send any property values, since they might be
- * large and sometimes not cheap to generated */
-
- if (!dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface) ||
- !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &sub) ||
- !dbus_message_iter_close_container(&iter, &sub) ||
- !dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "s", &sub))
- goto oom;
-
- NULSTR_FOREACH(i, properties)
- if (!dbus_message_iter_append_basic(&sub, DBUS_TYPE_STRING, &i))
- goto oom;
-
- if (!dbus_message_iter_close_container(&iter, &sub))
- goto oom;
-
- return m;
-
-oom:
- if (m)
- dbus_message_unref(m);
-
- return NULL;
-}
#include <dbus/dbus.h>
-#ifndef DBUS_ERROR_UNKNOWN_OBJECT
-#define DBUS_ERROR_UNKNOWN_OBJECT "org.freedesktop.DBus.Error.UnknownObject"
-#endif
-
-#ifndef DBUS_ERROR_UNKNOWN_INTERFACE
-#define DBUS_ERROR_UNKNOWN_INTERFACE "org.freedesktop.DBus.Error.UnknownInterface"
-#endif
-
-#ifndef DBUS_ERROR_UNKNOWN_PROPERTY
-#define DBUS_ERROR_UNKNOWN_PROPERTY "org.freedesktop.DBus.Error.UnknownProperty"
-#endif
-
-#ifndef DBUS_ERROR_PROPERTY_READ_ONLY
-#define DBUS_ERROR_PROPERTY_READ_ONLY "org.freedesktop.DBus.Error.PropertyReadOnly"
-#endif
-
#include "manager.h"
-typedef int (*BusPropertyCallback)(Manager *m, DBusMessageIter *iter, const char *property, void *data);
-typedef int (*BusPropertySetCallback)(Manager *m, DBusMessageIter *iter, const char *property);
-
-typedef struct BusProperty {
- const char *interface; /* interface of the property */
- const char *property; /* name of the property */
- BusPropertyCallback append; /* Function that is called to serialize this property */
- const char *signature;
- const void *data; /* The data of this property */
- BusPropertySetCallback set; /* Function that is called to set this property */
-} BusProperty;
-
-#define BUS_PROPERTIES_INTERFACE \
- " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
- " <method name=\"Get\">\n" \
- " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
- " </method>\n" \
- " <method name=\"GetAll\">\n" \
- " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
- " </method>\n" \
- " <method name=\"Set\">\n" \
- " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
- " <arg name=\"value\" direction=\"in\" type=\"v\"/>\n" \
- " </method>\n" \
- " <signal name=\"PropertiesChanged\">\n" \
- " <arg type=\"s\" name=\"interface\"/>\n" \
- " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
- " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
- " </signal>\n" \
- " </interface>\n"
-
-#define BUS_INTROSPECTABLE_INTERFACE \
- " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
- " <method name=\"Introspect\">\n" \
- " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
- " </method>\n" \
- " </interface>\n"
-
-#define BUS_PEER_INTERFACE \
- "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
- " <method name=\"Ping\"/>\n" \
- " <method name=\"GetMachineId\">\n" \
- " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
- " </method>\n" \
- "</interface>\n"
-
-#define BUS_GENERIC_INTERFACES_LIST \
- "org.freedesktop.DBus.Properties\0" \
- "org.freedesktop.DBus.Introspectable\0" \
- "org.freedesktop.DBus.Peer\0"
-
int bus_init(Manager *m, bool try_bus_connect);
void bus_done(Manager *m);
int bus_query_pid(Manager *m, const char *name);
-DBusHandlerResult bus_default_message_handler(Manager *m, DBusConnection *c, DBusMessage *message, const char* introspection, const char *interfaces, const BusProperty *properties);
-DBusHandlerResult bus_send_error_reply(Manager *m, DBusConnection *c, DBusMessage *message, DBusError *bus_error, int error);
-
int bus_broadcast(Manager *m, DBusMessage *message);
-int bus_property_append_string(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_strv(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_bool(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_int32(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_uint32(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_uint64(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_size(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_property_append_ul(Manager *m, DBusMessageIter *i, const char *property, void *data);
-
-#define bus_property_append_int bus_property_append_int32
-#define bus_property_append_pid bus_property_append_uint32
-#define bus_property_append_mode bus_property_append_uint32
-#define bus_property_append_unsigned bus_property_append_uint32
-#define bus_property_append_usec bus_property_append_uint64
-
-#define DEFINE_BUS_PROPERTY_APPEND_ENUM(function,name,type) \
- int function(Manager *m, DBusMessageIter *i, const char *property, void *data) { \
- const char *value; \
- type *field = data; \
- \
- assert(m); \
- assert(i); \
- assert(property); \
- \
- value = name##_to_string(*field); \
- \
- if (!dbus_message_iter_append_basic(i, DBUS_TYPE_STRING, &value)) \
- return -ENOMEM; \
- \
- return 0; \
- }
-
int bus_parse_strv(DBusMessage *m, char ***_l);
bool bus_has_subscriber(Manager *m);
bool bus_connection_has_subscriber(Manager *m, DBusConnection *c);
-DBusMessage* bus_properties_changed_new(const char *path, const char *interface, const char *properties);
-
#define BUS_CONNECTION_SUBSCRIBED(m, c) dbus_connection_get_data((c), (m)->subscribed_data_slot)
#define BUS_PENDING_CALL_NAME(m, p) dbus_pending_call_get_data((p), (m)->name_data_slot)