[systemd-commits] 2 commits - fixme src/dbus.c src/sd-daemon.c src/sd-daemon.h
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Jun 1 19:24:40 PDT 2010
fixme | 4 --
src/dbus.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
src/sd-daemon.c | 1
src/sd-daemon.h | 27 ++++++++++--------
4 files changed, 94 insertions(+), 20 deletions(-)
New commits:
commit 695d1ef183a2200cf5f32998f9bd7eb0d8b56ac2
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 2 04:24:33 2010 +0200
sd-daemon: rework documentation a little
diff --git a/src/sd-daemon.c b/src/sd-daemon.c
index 2e1bf32..29bd204 100644
--- a/src/sd-daemon.c
+++ b/src/sd-daemon.c
@@ -89,7 +89,6 @@ int sd_listen_fds(int unset_environment) {
goto finish;
}
-
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + (int) l; fd ++) {
int flags;
diff --git a/src/sd-daemon.h b/src/sd-daemon.h
index e209af6..0d8de45 100644
--- a/src/sd-daemon.h
+++ b/src/sd-daemon.h
@@ -30,10 +30,11 @@
#include <inttypes.h>
/* Reference implementation of a few systemd related interfaces for
- * writing daemons. These interfaces are trivial to implement, however
- * to simplify porting we provide this reference
- * implementation. Applications are free to reimplement the algorithms
- * described here. */
+ * writing daemons. These interfaces are trivial to implement. To
+ * simplify porting we provide this reference
+ * implementation. Applications are welcome to reimplement the
+ * algorithms described here, if they do not want to include these two
+ * source files. */
/*
Log levels for usage on stderr:
@@ -56,12 +57,16 @@
#define SD_LISTEN_FDS_START 3
/* Returns how many file descriptors have been passed, or a negative
- * errno code on failure. Optionally removes the $LISTEN_FDS and
- * $LISTEN_PID file descriptors from the environment
- * (recommended). You'll find the file descriptors passed as fds
- * SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1 if r is the return
- * value of this functioin. Returns a negative errno style error code
- * on failure. */
+ * errno code on failure. Optionally, removes the $LISTEN_FDS and
+ * $LISTEN_PID file descriptors from the environment (recommended, but
+ * problematic in threaded environments). If r is the return value of
+ * this function you'll find the file descriptors passed as fds
+ * SD_LISTEN_FDS_START to SD_LISTEN_FDS_START+r-1. Returns a negative
+ * errno style error code on failure. This function call ensures that
+ * the FD_CLOEXEC flag is set for the passed file descriptors, to make
+ * sure they are not passed on to child processes. If FD_CLOEXEC shall
+ * not be set, the caller needs to unset it after this call for all file
+ * descriptors that are used.*/
int sd_listen_fds(int unset_environment);
/* Helper call for identifying a passed file descriptor. Returns 1 if
@@ -86,7 +91,7 @@ int sd_is_socket(int fd, int family, int type, int listening);
/* Helper call for identifying a passed file descriptor. Returns 1 if
* the file descriptor is an Internet socket, of the specified family
- * (either AF_INET or AF_INET6) of the specified type (SOCK_DGRAM,
+ * (either AF_INET or AF_INET6) and the specified type (SOCK_DGRAM,
* SOCK_STREAM, ...), 0 otherwise. If version is 0 a protocol version
* check is not done. If type is 0 a socket type check will not be
* done. If port is 0 a socket port check will not be done. The
commit 0034c15c60ba5c30cf2786c5693c71f99dfffbc3
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jun 2 04:24:16 2010 +0200
dbus: implement systemd side of dbus activation glue
diff --git a/fixme b/fixme
index 87068c4..b6752d9 100644
--- a/fixme
+++ b/fixme
@@ -64,10 +64,6 @@
* tcpwrap
-* dbus intzerface files und so weiter müssen NICHT nach prefixdir
-
-* fix den kram mit rootdir..
-
Regularly:
* look for close() vs. close_nointr() vs. close_nointr_nofail()
diff --git a/src/dbus.c b/src/dbus.c
index f5bbc58..7916817 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -65,6 +65,8 @@ const char *const bus_interface_table[] = {
NULL
};
+static const char *error_to_dbus(int error);
+
static void api_bus_dispatch_status(DBusConnection *bus, DBusDispatchStatus status, void *data) {
Manager *m = data;
@@ -333,6 +335,7 @@ static void bus_toggle_timeout(DBusTimeout *timeout, void *data) {
static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBusMessage *message, void *data) {
Manager *m = data;
DBusError error;
+ DBusMessage *reply = NULL;
assert(connection);
assert(message);
@@ -340,10 +343,10 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBu
dbus_error_init(&error);
- /* log_debug("Got D-Bus request: %s.%s() on %s", */
- /* dbus_message_get_interface(message), */
- /* dbus_message_get_member(message), */
- /* dbus_message_get_path(message)); */
+ log_debug("Got D-Bus request: %s.%s() on %s",
+ dbus_message_get_interface(message),
+ dbus_message_get_member(message),
+ dbus_message_get_path(message));
if (dbus_message_is_signal(message, DBUS_INTERFACE_LOCAL, "Disconnected")) {
log_error("Warning! API D-Bus connection terminated.");
@@ -370,10 +373,65 @@ static DBusHandlerResult api_bus_message_filter(DBusConnection *connection, DBu
manager_dispatch_bus_name_owner_changed(m, name, old_owner, new_owner);
}
+ } else if (dbus_message_is_signal(message, "org.freedesktop.systemd1.Activator", "ActivationRequest")) {
+ const char *name;
+
+ if (!dbus_message_get_args(message, &error,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_INVALID))
+ log_error("Failed to parse ActivationRequest message: %s", error.message);
+ else {
+ int r;
+ Unit *u;
+
+ r = manager_load_unit(m, name, NULL, &u);
+
+ if (r >= 0 && u->meta.only_by_dependency)
+ r = -EPERM;
+
+ if (r >= 0)
+ r = manager_add_job(m, JOB_START, u, JOB_REPLACE, true, NULL);
+
+ if (r < 0) {
+ const char *id, *text;
+
+ if (!(reply = dbus_message_new_signal("/org/freedesktop/systemd1", "org.freedesktop.systemd1.Activator", "ActivationFailure")))
+ goto oom;
+
+ id = error_to_dbus(r);
+ text = strerror(-r);
+
+ if (!dbus_message_set_destination(reply, DBUS_SERVICE_DBUS) ||
+ !dbus_message_append_args(reply,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &id,
+ DBUS_TYPE_STRING, &text,
+ DBUS_TYPE_INVALID))
+ goto oom;
+ }
+
+ /* On success we don't do anything, the service will be spwaned now */
+ }
}
dbus_error_free(&error);
+
+ if (reply) {
+ if (!dbus_connection_send(connection, reply, NULL))
+ goto oom;
+
+ dbus_message_unref(reply);
+ }
+
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 DBusHandlerResult system_bus_message_filter(DBusConnection *connection, DBusMessage *message, void *data) {
@@ -642,6 +700,7 @@ int bus_init_api(Manager *m) {
return -ENOMEM;
}
+ /* Get NameOwnerChange messages */
dbus_bus_add_match(m->api_bus,
"type='signal',"
"sender='"DBUS_SERVICE_DBUS"',"
@@ -656,6 +715,21 @@ int bus_init_api(Manager *m) {
return -ENOMEM;
}
+ /* Get activation requests */
+ dbus_bus_add_match(m->api_bus,
+ "type='signal',"
+ "sender='"DBUS_SERVICE_DBUS"',"
+ "interface='org.freedesktop.systemd1.Activator',"
+ "path='"DBUS_PATH_DBUS"'",
+ &error);
+
+ if (dbus_error_is_set(&error)) {
+ log_error("Failed to register match: %s", error.message);
+ dbus_error_free(&error);
+ bus_done_api(m);
+ return -ENOMEM;
+ }
+
if ((r = request_name(m)) < 0) {
bus_done_api(m);
return r;
More information about the systemd-commits
mailing list