[systemd-commits] 6 commits - src/dbus.c src/dbus-common.c src/load-fragment.c src/logind.h src/logind-session.c src/main.c TODO units/user at .service.in

Lennart Poettering lennart at kemper.freedesktop.org
Fri Jul 1 13:36:35 PDT 2011


 TODO                   |    4 --
 src/dbus-common.c      |   66 ++++++++++++++++++++++++++++++-----------------
 src/dbus.c             |   39 ++++++++++++++++++++++------
 src/load-fragment.c    |   68 ++++++++++++++++++++++++++++++++++++++++++-------
 src/logind-session.c   |    6 ++--
 src/logind.h           |    1 
 src/main.c             |    2 -
 units/user at .service.in |    3 +-
 8 files changed, 140 insertions(+), 49 deletions(-)

New commits:
commit bde7f9072109aaf298fe35de59a61b1eb026bf51
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 22:36:15 2011 +0200

    logind: temporarily hack right user bus address into unit file

diff --git a/units/user at .service.in b/units/user at .service.in
index d692c8e..59fe524 100644
--- a/units/user at .service.in
+++ b/units/user at .service.in
@@ -12,7 +12,8 @@ After=systemd-user-sessions.service
 [Service]
 User=%I
 PAMName=systemd-shared
-ControlGroup=/user/%I/shared
+ControlGroup=%R/user/%I/shared cpu:/
 ControlGroupModify=yes
 Type=notify
 ExecStart=- at rootbindir@/systemd --user
+Environment=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/%I/dbus/user_bus_socket

commit eeecf6e607740337599dfb9878dbef843b0f39c3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 22:35:34 2011 +0200

    log: log to syslog unless connected to a tty in user mode

diff --git a/src/main.c b/src/main.c
index e10441c..76a0943 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1063,7 +1063,7 @@ int main(int argc, char *argv[]) {
                 }
         } else {
                 arg_running_as = MANAGER_USER;
-                log_set_target(LOG_TARGET_CONSOLE);
+                log_set_target(LOG_TARGET_AUTO);
         }
 
         if (set_default_unit(SPECIAL_DEFAULT_TARGET) < 0)

commit 0254daedb1b67a16c6d54b964b31b5e8eaa4ac4c
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 22:34:58 2011 +0200

    logind: create private subdirectory for X11 socket

diff --git a/src/logind-session.c b/src/logind-session.c
index cadf932..ab4de66 100644
--- a/src/logind-session.c
+++ b/src/logind-session.c
@@ -380,13 +380,15 @@ static int session_link_x11_socket(Session *s) {
                 return -ENOENT;
         }
 
-        t = strappend(s->user->runtime_path, "/display");
+        t = strappend(s->user->runtime_path, "/X11/display");
         if (!t) {
                 log_error("Out of memory");
                 free(f);
                 return -ENOMEM;
         }
 
+        mkdir_parents(t, 0755);
+
         if (link(f, t) < 0) {
                 if (errno == EEXIST) {
                         unlink(t);
@@ -638,7 +640,7 @@ static int session_unlink_x11_socket(Session *s) {
 
         s->user->display = NULL;
 
-        t = strappend(s->user->runtime_path, "/display");
+        t = strappend(s->user->runtime_path, "/X11/display");
         if (!t) {
                 log_error("Out of memory");
                 return -ENOMEM;

commit be81bfc4a700e2b8544857279dc09a17b1efcf2d
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 22:34:37 2011 +0200

    dbus: listen on private sockets in user mode too

diff --git a/src/dbus-common.c b/src/dbus-common.c
index 73f9e87..5bfaf36 100644
--- a/src/dbus-common.c
+++ b/src/dbus-common.c
@@ -55,7 +55,7 @@ int bus_check_peercred(DBusConnection *c) {
                 return -E2BIG;
         }
 
-        if (ucred.uid != 0)
+        if (ucred.uid != 0 && ucred.uid != geteuid())
                 return -EPERM;
 
         return 1;
@@ -98,27 +98,53 @@ static int sync_auth(DBusConnection *bus, DBusError *error) {
         return 0;
 }
 
-int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private, DBusError *error) {
-        DBusConnection *bus;
+int bus_connect(DBusBusType t, DBusConnection **_bus, bool *_private, DBusError *error) {
+        DBusConnection *bus = NULL;
         int r;
+        bool private = true;
 
         assert(_bus);
 
-        /* If we are root, then let's not go via the bus */
         if (geteuid() == 0 && t == DBUS_BUS_SYSTEM) {
+                /* If we are root, then let's talk directly to the
+                 * system instance, instead of going via the bus */
+
+                bus = dbus_connection_open_private("unix:path=/run/systemd/private", error);
+                if (!bus)
+                        return -EIO;
+
+        } else {
+                if (t == DBUS_BUS_SESSION) {
+                        const char *e;
+
+                        /* If we are supposed to talk to the instance,
+                         * try via XDG_RUNTIME_DIR first, then
+                         * fallback to normal bus access */
 
-                if (!(bus = dbus_connection_open_private("unix:path=/run/systemd/private", error))) {
-#ifndef LEGACY
-                        dbus_error_free(error);
+                        e = getenv("XDG_RUNTIME_DIR");
+                        if (e) {
+                                char *p;
 
-                        /* Retry with the pre v21 socket name, to ease upgrades */
-                        if (!(bus = dbus_connection_open_private("unix:abstract=/org/freedesktop/systemd1/private", error)))
-#endif
+                                if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0)
+                                        return -ENOMEM;
+
+                                bus = dbus_connection_open_private(p, NULL);
+                                free(p);
+                        }
+                }
+
+                if (!bus) {
+                        bus = dbus_bus_get_private(t, error);
+                        if (!bus)
                                 return -EIO;
+
+                        private = false;
                 }
+        }
 
-                dbus_connection_set_exit_on_disconnect(bus, FALSE);
+        dbus_connection_set_exit_on_disconnect(bus, FALSE);
 
+        if (private) {
                 if (bus_check_peercred(bus) < 0) {
                         dbus_connection_close(bus);
                         dbus_connection_unref(bus);
@@ -126,26 +152,18 @@ int bus_connect(DBusBusType t, DBusConnection **_bus, bool *private, DBusError *
                         dbus_set_error_const(error, DBUS_ERROR_ACCESS_DENIED, "Failed to verify owner of bus.");
                         return -EACCES;
                 }
-
-                if (private)
-                        *private = true;
-
-        } else {
-                if (!(bus = dbus_bus_get_private(t, error)))
-                        return -EIO;
-
-                dbus_connection_set_exit_on_disconnect(bus, FALSE);
-
-                if (private)
-                        *private = false;
         }
 
-        if ((r = sync_auth(bus, error)) < 0) {
+        r = sync_auth(bus, error);
+        if (r < 0) {
                 dbus_connection_close(bus);
                 dbus_connection_unref(bus);
                 return r;
         }
 
+        if (_private)
+                *_private = private;
+
         *_bus = bus;
         return 0;
 }
diff --git a/src/dbus.c b/src/dbus.c
index 8c7f0ab..daa2c84 100644
--- a/src/dbus.c
+++ b/src/dbus.c
@@ -731,8 +731,8 @@ static int bus_setup_loop(Manager *m, DBusConnection *bus) {
         return 0;
 }
 
-static dbus_bool_t allow_only_root(DBusConnection *connection, unsigned long uid, void *data) {
-        return uid == 0;
+static dbus_bool_t allow_only_same_user(DBusConnection *connection, unsigned long uid, void *data) {
+        return uid == 0 || uid == geteuid();
 }
 
 static void bus_new_connection(
@@ -749,7 +749,7 @@ static void bus_new_connection(
                 return;
         }
 
-        dbus_connection_set_unix_user_function(new_connection, allow_only_root, NULL, NULL);
+        dbus_connection_set_unix_user_function(new_connection, allow_only_same_user, NULL, NULL);
 
         if (bus_setup_loop(m, new_connection) < 0)
                 return;
@@ -930,12 +930,35 @@ static int bus_init_private(Manager *m) {
         if (m->private_bus)
                 return 0;
 
-        /* We want the private bus only when running as init */
-        if (getpid() != 1)
-                return 0;
+        if (m->running_as == MANAGER_SYSTEM) {
+
+                /* We want the private bus only when running as init */
+                if (getpid() != 1)
+                        return 0;
+
+                unlink("/run/systemd/private");
+                m->private_bus = dbus_server_listen("unix:path=/run/systemd/private", &error);
+        } else {
+                const char *e;
+                char *p;
+
+                e = getenv("XDG_RUNTIME_DIR");
+                if (!e)
+                        return 0;
+
+                if (asprintf(&p, "unix:path=%s/systemd/private", e) < 0) {
+                        log_error("Not enough memory");
+                        r = -ENOMEM;
+                        goto fail;
+                }
+
+                mkdir_parents(p+10, 0755);
+                unlink(p+10);
+                m->private_bus = dbus_server_listen(p, &error);
+                free(p);
+        }
 
-        unlink("/run/systemd/private");
-        if (!(m->private_bus = dbus_server_listen("unix:path=/run/systemd/private", &error))) {
+        if (!m->private_bus) {
                 log_error("Failed to create private D-Bus server: %s", bus_error_message(&error));
                 r = -EIO;
                 goto fail;

commit 8fef76590052b235eec789f1acd24a0d1acbdaef
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 01:13:47 2011 +0200

    unit: support wildcards in Environment=, EnvironmentFile=

diff --git a/TODO b/TODO
index 155f09f..5901a90 100644
--- a/TODO
+++ b/TODO
@@ -73,10 +73,6 @@ Features:
 
 * GC unreferenced jobs (such as .device jobs)
 
-* support wildcard expansion in ListenStream= and friends
-
-* support wildcard expansion in EnvironmentFile= and friends
-
 * add JoinControllers= to system.conf to mount certain cgroup
   controllers together in order to guarantee atomic creation/addition
   of cgroups
diff --git a/src/load-fragment.c b/src/load-fragment.c
index 30fbb57..8f39839 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -188,6 +188,35 @@ static int config_parse_string_printf(
         return 0;
 }
 
+static int config_parse_strv_printf(
+                const char *filename,
+                unsigned line,
+                const char *section,
+                const char *lvalue,
+                int ltype,
+                const char *rvalue,
+                void *data,
+                void *userdata) {
+
+        Unit *u = userdata;
+        char *k;
+        int r;
+
+        assert(filename);
+        assert(lvalue);
+        assert(rvalue);
+        assert(u);
+
+        k = unit_full_printf(u, rvalue);
+        if (!k)
+                return -ENOMEM;
+
+        r = config_parse_strv(filename, line, section, lvalue, ltype, k, data, userdata);
+        free(k);
+
+        return r;
+}
+
 static int config_parse_path_printf(
                 const char *filename,
                 unsigned line,
@@ -1496,18 +1525,27 @@ static int config_parse_env_file(
                 void *userdata) {
 
         char ***env = data, **k;
+        Unit *u = userdata;
+        char *s;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        if (!path_is_absolute(rvalue[0] == '-' ? rvalue + 1 : rvalue)) {
-                log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, rvalue);
+        s = unit_full_printf(u, rvalue);
+        if (!s)
+                return -ENOMEM;
+
+        if (!path_is_absolute(s[0] == '-' ? s + 1 : s)) {
+                log_error("[%s:%u] Path '%s' is not absolute, ignoring.", filename, line, s);
+                free(s);
                 return 0;
         }
 
-        if (!(k = strv_append(*env, rvalue)))
+        k = strv_append(*env, s);
+        free(s);
+        if (!k)
                 return -ENOMEM;
 
         strv_free(*env);
@@ -1892,7 +1930,7 @@ static int load_from_path(Unit *u, const char *path) {
                 { "CPUSchedulingResetOnFork", config_parse_bool,          0, &(context).cpu_sched_reset_on_fork,              section   }, \
                 { "CPUAffinity",            config_parse_cpu_affinity,    0, &(context),                                      section   }, \
                 { "UMask",                  config_parse_mode,            0, &(context).umask,                                section   }, \
-                { "Environment",            config_parse_strv,            0, &(context).environment,                          section   }, \
+                { "Environment",            config_parse_strv_printf,     0, &(context).environment,                          section   }, \
                 { "EnvironmentFile",        config_parse_env_file,        0, &(context).environment_files,                    section   }, \
                 { "StandardInput",          config_parse_input,           0, &(context).std_input,                            section   }, \
                 { "StandardOutput",         config_parse_output,          0, &(context).std_output,                           section   }, \

commit 1fd45a90f5c99a88c268981de321d0ef8542bd4f
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 1 00:55:34 2011 +0200

    unit: do wildcard expansion in ListenStream= and friends

diff --git a/src/load-fragment.c b/src/load-fragment.c
index 3146186..30fbb57 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -251,7 +251,7 @@ static int config_parse_listen(
         if (streq(lvalue, "ListenFIFO")) {
                 p->type = SOCKET_FIFO;
 
-                if (!(p->path = strdup(rvalue))) {
+                if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
                         free(p);
                         return -ENOMEM;
                 }
@@ -261,7 +261,7 @@ static int config_parse_listen(
         } else if (streq(lvalue, "ListenSpecial")) {
                 p->type = SOCKET_SPECIAL;
 
-                if (!(p->path = strdup(rvalue))) {
+                if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
                         free(p);
                         return -ENOMEM;
                 }
@@ -272,7 +272,7 @@ static int config_parse_listen(
 
                 p->type = SOCKET_MQUEUE;
 
-                if (!(p->path = strdup(rvalue))) {
+                if (!(p->path = unit_full_printf(UNIT(s), rvalue))) {
                         free(p);
                         return -ENOMEM;
                 }
@@ -280,18 +280,30 @@ static int config_parse_listen(
                 path_kill_slashes(p->path);
 
         } else if (streq(lvalue, "ListenNetlink")) {
+                char  *k;
+                int r;
+
                 p->type = SOCKET_SOCKET;
+                k = unit_full_printf(UNIT(s), rvalue);
+                r = socket_address_parse_netlink(&p->address, k);
+                free(k);
 
-                if (socket_address_parse_netlink(&p->address, rvalue) < 0) {
+                if (r < 0) {
                         log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
                         free(p);
                         return 0;
                 }
 
         } else {
+                char *k;
+                int r;
+
                 p->type = SOCKET_SOCKET;
+                k = unit_full_printf(UNIT(s), rvalue);
+                r = socket_address_parse(&p->address, k);
+                free(k);
 
-                if (socket_address_parse(&p->address, rvalue) < 0) {
+                if (r < 0) {
                         log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
                         free(p);
                         return 0;
diff --git a/src/logind.h b/src/logind.h
index 10b7527..d91cae3 100644
--- a/src/logind.h
+++ b/src/logind.h
@@ -36,6 +36,7 @@
  *
  * spawn user systemd
  * direct client API
+ * add display symlinks also per-session
  *
  * udev:
  * drop redundant udev_device_get_is_initialized() use as soon as libudev is fixed



More information about the systemd-commits mailing list