[systemd-commits] 6 commits - TODO src/libsystemd-bus src/login src/machine src/systemd
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Nov 5 21:25:08 CET 2013
TODO | 6 +--
src/libsystemd-bus/bus-internal.h | 2 +
src/libsystemd-bus/bus-objects.c | 10 ++++-
src/libsystemd-bus/sd-bus.c | 23 ++++++++---
src/login/logind-dbus.c | 20 +++++++++-
src/login/logind-seat-dbus.c | 47 ++++++++++++++++++------
src/login/logind-session-dbus.c | 41 +++++++++++++++------
src/login/logind-user-dbus.c | 42 +++++++++++++++------
src/machine/machine-dbus.c | 73 ++++++++++++++++++++++++++++++++------
src/machine/machined-dbus.c | 41 ++++-----------------
src/systemd/sd-bus.h | 2 +
11 files changed, 217 insertions(+), 90 deletions(-)
New commits:
commit 5d66866d96ca7b85b36df99651991b2a1acd2b2e
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 5 21:24:33 2013 +0100
bus: never report nodes as children that do not have the right prefix
diff --git a/src/libsystemd-bus/bus-objects.c b/src/libsystemd-bus/bus-objects.c
index 92781e9..93bd3ad 100644
--- a/src/libsystemd-bus/bus-objects.c
+++ b/src/libsystemd-bus/bus-objects.c
@@ -114,12 +114,17 @@ static int add_enumerated_to_set(
continue;
}
- if (!object_path_is_valid(*k) && object_path_startswith(*k, prefix)) {
+ if (!object_path_is_valid(*k)){
free(*k);
r = -EINVAL;
continue;
}
+ if (!object_path_startswith(*k, prefix)) {
+ free(*k);
+ continue;
+ }
+
r = set_consume(s, *k);
}
@@ -154,6 +159,9 @@ static int add_subtree_to_set(
LIST_FOREACH(siblings, i, n->child) {
char *t;
+ if (!object_path_startswith(i->path, prefix))
+ continue;
+
t = strdup(i->path);
if (!t)
return -ENOMEM;
commit ce6d4630c1e52ab4f08fbf96b82ffdfa3c6e24ee
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 5 20:55:14 2013 +0100
update TODO
diff --git a/TODO b/TODO
index 0f4e416..23c0042 100644
--- a/TODO
+++ b/TODO
@@ -134,8 +134,6 @@ Features:
* load .d/*.conf dropins for device units
-* add a fixed dbus path for "my own unit", "my own session", ... to PID1, logind, ...
-
* service_coldplug() appears to reinstall the wrong stop timeout watch.
* transient units: allow creating auxiliary units with the same call
@@ -337,7 +335,6 @@ Features:
- logind: non-local X11 server handling
- logind: add equivalent to sd_pid_get_owner_uid() to the D-Bus API
- pam: when leaving a session explicitly exclude the ReleaseSession() caller process from the killing spree
- - logind: GetSessionByPID() should accept 0 as PID value
- we should probably handle SIGTERM/SIGINT to not leave dot files around, just in case
* exec: when deinitializating a tty device fix the perms and group, too, not only when initializing. Set access mode/gid to 0620/tty.
commit 927b1649448b812a7620ad013f4752d597b12407
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 5 20:52:39 2013 +0100
logind: add virtual object paths that always can be used to refer to the callers session, user, seat or machine object
This way clients can skip invoking GetSessionByPID() for their own PID
or a similar call to access these objects.
diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c
index e9f8d26..c59dfd9 100644
--- a/src/login/logind-seat-dbus.c
+++ b/src/login/logind-seat-dbus.c
@@ -254,10 +254,9 @@ const sd_bus_vtable seat_vtable[] = {
};
int seat_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
- _cleanup_free_ char *e = NULL;
Manager *m = userdata;
Seat *seat;
- const char *p;
+ int r;
assert(bus);
assert(path);
@@ -265,17 +264,43 @@ int seat_object_find(sd_bus *bus, const char *path, const char *interface, void
assert(found);
assert(m);
- p = startswith(path, "/org/freedesktop/login1/seat/");
- if (!p)
- return 0;
+ if (streq(path, "/org/freedesktop/login1/seat/self")) {
+ sd_bus_message *message;
+ Session *session;
+ pid_t pid;
- e = bus_path_unescape(p);
- if (!e)
- return -ENOMEM;
+ message = sd_bus_get_current(bus);
+ if (!message)
+ return 0;
- seat = hashmap_get(m->seats, e);
- if (!seat)
- return 0;
+ r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+ if (r < 0)
+ return 0;
+
+ r = manager_get_session_by_pid(m, pid, &session);
+ if (r <= 0)
+ return 0;
+
+ if (!session->seat)
+ return 0;
+
+ seat = session->seat;
+ } else {
+ _cleanup_free_ char *e = NULL;
+ const char *p;
+
+ p = startswith(path, "/org/freedesktop/login1/seat/");
+ if (!p)
+ return 0;
+
+ e = bus_path_unescape(p);
+ if (!e)
+ return -ENOMEM;
+
+ seat = hashmap_get(m->seats, e);
+ if (!seat)
+ return 0;
+ }
*found = seat;
return 1;
diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c
index cda6a0a..a559e60 100644
--- a/src/login/logind-session-dbus.c
+++ b/src/login/logind-session-dbus.c
@@ -465,10 +465,9 @@ const sd_bus_vtable session_vtable[] = {
};
int session_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
- _cleanup_free_ char *e = NULL;
Manager *m = userdata;
Session *session;
- const char *p;
+ int r;
assert(bus);
assert(path);
@@ -476,17 +475,37 @@ int session_object_find(sd_bus *bus, const char *path, const char *interface, vo
assert(found);
assert(m);
- p = startswith(path, "/org/freedesktop/login1/session/");
- if (!p)
- return 0;
+ if (streq(path, "/org/freedesktop/login1/session/self")) {
+ sd_bus_message *message;
+ pid_t pid;
- e = bus_path_unescape(p);
- if (!e)
- return -ENOMEM;
+ message = sd_bus_get_current(bus);
+ if (!message)
+ return 0;
- session = hashmap_get(m->sessions, e);
- if (!session)
- return 0;
+ r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+ if (r < 0)
+ return 0;
+
+ r = manager_get_session_by_pid(m, pid, &session);
+ if (r <= 0)
+ return 0;
+ } else {
+ _cleanup_free_ char *e = NULL;
+ const char *p;
+
+ p = startswith(path, "/org/freedesktop/login1/session/");
+ if (!p)
+ return 0;
+
+ e = bus_path_unescape(p);
+ if (!e)
+ return -ENOMEM;
+
+ session = hashmap_get(m->sessions, e);
+ if (!session)
+ return 0;
+ }
*found = session;
return 1;
diff --git a/src/login/logind-user-dbus.c b/src/login/logind-user-dbus.c
index dbd617f..563c7ef 100644
--- a/src/login/logind-user-dbus.c
+++ b/src/login/logind-user-dbus.c
@@ -236,11 +236,7 @@ const sd_bus_vtable user_vtable[] = {
};
int user_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
-
- _cleanup_free_ char *e = NULL;
Manager *m = userdata;
- unsigned long lu;
- const char *p;
User *user;
int r;
@@ -250,17 +246,37 @@ int user_object_find(sd_bus *bus, const char *path, const char *interface, void
assert(found);
assert(m);
- p = startswith(path, "/org/freedesktop/login1/user/_");
- if (!p)
- return 0;
+ if (streq(path, "/org/freedesktop/login1/user/self")) {
+ sd_bus_message *message;
+ pid_t pid;
- r = safe_atolu(p, &lu);
- if (r < 0)
- return 0;
+ message = sd_bus_get_current(bus);
+ if (!message)
+ return 0;
- user = hashmap_get(m->users, ULONG_TO_PTR(lu));
- if (!user)
- return 0;
+ r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+ if (r < 0)
+ return 0;
+
+ r = manager_get_user_by_pid(m, pid, &user);
+ if (r <= 0)
+ return 0;
+ } else {
+ unsigned long lu;
+ const char *p;
+
+ p = startswith(path, "/org/freedesktop/login1/user/_");
+ if (!p)
+ return 0;
+
+ r = safe_atolu(p, &lu);
+ if (r < 0)
+ return 0;
+
+ user = hashmap_get(m->users, ULONG_TO_PTR(lu));
+ if (!user)
+ return 0;
+ }
*found = user;
return 1;
diff --git a/src/machine/machine-dbus.c b/src/machine/machine-dbus.c
index ddd6b4b..db379d2 100644
--- a/src/machine/machine-dbus.c
+++ b/src/machine/machine-dbus.c
@@ -23,6 +23,7 @@
#include <string.h>
#include "bus-util.h"
+#include "strv.h"
#include "machine.h"
static int property_get_id(
@@ -142,10 +143,9 @@ const sd_bus_vtable machine_vtable[] = {
};
int machine_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
- _cleanup_free_ char *e = NULL;
Manager *m = userdata;
Machine *machine;
- const char *p;
+ int r;
assert(bus);
assert(path);
@@ -153,17 +153,37 @@ int machine_object_find(sd_bus *bus, const char *path, const char *interface, vo
assert(found);
assert(m);
- p = startswith(path, "/org/freedesktop/machine1/machine/");
- if (!p)
- return 0;
+ if (streq(path, "/org/freedesktop/machine1/machine/self")) {
+ sd_bus_message *message;
+ pid_t pid;
- e = bus_path_unescape(p);
- if (!e)
- return -ENOMEM;
+ message = sd_bus_get_current(bus);
+ if (!message)
+ return 0;
- machine = hashmap_get(m->machines, e);
- if (!machine)
- return 0;
+ r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+ if (r < 0)
+ return 0;
+
+ r = manager_get_machine_by_pid(m, pid, &machine);
+ if (r <= 0)
+ return 0;
+ } else {
+ _cleanup_free_ char *e = NULL;
+ const char *p;
+
+ p = startswith(path, "/org/freedesktop/machine1/machine/");
+ if (!p)
+ return 0;
+
+ e = bus_path_unescape(p);
+ if (!e)
+ return -ENOMEM;
+
+ machine = hashmap_get(m->machines, e);
+ if (!machine)
+ return 0;
+ }
*found = machine;
return 1;
@@ -181,6 +201,37 @@ char *machine_bus_path(Machine *m) {
return strappend("/org/freedesktop/machine1/machine/", e);
}
+int machine_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
+ _cleanup_strv_free_ char **l = NULL;
+ Machine *machine = NULL;
+ Manager *m = userdata;
+ Iterator i;
+ int r;
+
+ assert(bus);
+ assert(path);
+ assert(nodes);
+
+ HASHMAP_FOREACH(machine, m->machines, i) {
+ char *p;
+
+ p = machine_bus_path(machine);
+ if (!p)
+ return -ENOMEM;
+
+ r = strv_push(&l, p);
+ if (r < 0) {
+ free(p);
+ return r;
+ }
+ }
+
+ *nodes = l;
+ l = NULL;
+
+ return 1;
+}
+
int machine_send_signal(Machine *m, bool new_machine) {
_cleanup_free_ char *p = NULL;
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 505bc17..11256da 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -342,37 +342,6 @@ const sd_bus_vtable manager_vtable[] = {
SD_BUS_VTABLE_END
};
-int machine_node_enumerator(sd_bus *bus, const char *path, char ***nodes, void *userdata) {
- _cleanup_strv_free_ char **l = NULL;
- Machine *machine = NULL;
- Manager *m = userdata;
- Iterator i;
- int r;
-
- assert(bus);
- assert(path);
- assert(nodes);
-
- HASHMAP_FOREACH(machine, m->machines, i) {
- char *p;
-
- p = machine_bus_path(machine);
- if (!p)
- return -ENOMEM;
-
- r = strv_push(&l, p);
- if (r < 0) {
- free(p);
- return r;
- }
- }
-
- *nodes = l;
- l = NULL;
-
- return 1;
-}
-
int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
const char *path, *result, *unit;
Manager *m = userdata;
commit d16bd0556127962e0dc19f2b049edb09f354bedb
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 5 20:52:20 2013 +0100
update TODO
diff --git a/TODO b/TODO
index 049b18a..0f4e416 100644
--- a/TODO
+++ b/TODO
@@ -46,6 +46,9 @@ CGroup Rework Completion:
Features:
+* "systemctl mask" should find all names by which a unit is accessible
+ (i.e. by scanning for symlinks to it) and link them all to /dev/null
+
* Automatically configure swap partition to use for hibernation by looking for largest swap partition on the root disk?
* remove NSS usage from PID 1 (notably the specifiers)
commit affff0b6f2b267254fee981a010e06cd55d9756a
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 5 20:51:49 2013 +0100
bus: add sd_bus_get_current() bus call to determine message that is currently being dispatched
diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index 913f281..2112a29 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -247,6 +247,8 @@ struct sd_bus {
sd_event_source *time_event_source;
sd_event_source *quit_event_source;
sd_event *event;
+
+ sd_bus_message *current;
};
#define BUS_DEFAULT_TIMEOUT ((usec_t) (25 * USEC_PER_SEC))
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index a9f238e..e68f127 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -1931,6 +1931,7 @@ static int process_message(sd_bus *bus, sd_bus_message *m) {
assert(bus);
assert(m);
+ bus->current = m;
bus->iteration_counter++;
log_debug("Got message sender=%s object=%s interface=%s member=%s",
@@ -1941,25 +1942,29 @@ static int process_message(sd_bus *bus, sd_bus_message *m) {
r = process_hello(bus, m);
if (r != 0)
- return r;
+ goto finish;
r = process_reply(bus, m);
if (r != 0)
- return r;
+ goto finish;
r = process_filter(bus, m);
if (r != 0)
- return r;
+ goto finish;
r = process_match(bus, m);
if (r != 0)
- return r;
+ goto finish;
r = process_builtin(bus, m);
if (r != 0)
- return r;
+ goto finish;
+
+ r = bus_process_object(bus, m);
- return bus_process_object(bus, m);
+finish:
+ bus->current = NULL;
+ return r;
}
static int process_running(sd_bus *bus, sd_bus_message **ret) {
@@ -2422,3 +2427,9 @@ int sd_bus_detach_event(sd_bus *bus) {
return 0;
}
+
+sd_bus_message* sd_bus_get_current(sd_bus *bus) {
+ assert_return(bus, NULL);
+
+ return bus->current;
+}
diff --git a/src/systemd/sd-bus.h b/src/systemd/sd-bus.h
index 6b43a23..48edc59 100644
--- a/src/systemd/sd-bus.h
+++ b/src/systemd/sd-bus.h
@@ -101,6 +101,8 @@ int sd_bus_process(sd_bus *bus, sd_bus_message **r);
int sd_bus_wait(sd_bus *bus, uint64_t timeout_usec);
int sd_bus_flush(sd_bus *bus);
+sd_bus_message* sd_bus_get_current(sd_bus *bus);
+
int sd_bus_attach_event(sd_bus *bus, sd_event *e, int priority);
int sd_bus_detach_event(sd_bus *bus);
commit 4e724d9c5ab76c3f8327945317463ef706011082
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Nov 5 20:44:27 2013 +0100
logind: automatically determine client side PID if GetSessionByPID() is called with a PID == 0
diff --git a/src/login/logind-dbus.c b/src/login/logind-dbus.c
index dcfd25d..7e22b84 100644
--- a/src/login/logind-dbus.c
+++ b/src/login/logind-dbus.c
@@ -157,17 +157,25 @@ static int method_get_session_by_pid(sd_bus *bus, sd_bus_message *message, void
_cleanup_free_ char *p = NULL;
Session *session = NULL;
Manager *m = userdata;
- uint32_t pid;
+ pid_t pid;
int r;
assert(bus);
assert(message);
assert(m);
+ assert_cc(sizeof(pid_t) == sizeof(uint32_t));
+
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return sd_bus_reply_method_errno(bus, message, r, NULL);
+ if (pid == 0) {
+ r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+ if (r < 0)
+ return sd_bus_reply_method_errno(bus, message, r, NULL);
+ }
+
r = manager_get_session_by_pid(m, pid, &session);
if (r < 0)
return sd_bus_reply_method_errno(bus, message, r, NULL);
@@ -211,17 +219,25 @@ static int method_get_user_by_pid(sd_bus *bus, sd_bus_message *message, void *us
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
User *user = NULL;
- uint32_t pid;
+ pid_t pid;
int r;
assert(bus);
assert(message);
assert(m);
+ assert_cc(sizeof(pid_t) == sizeof(uint32_t));
+
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return sd_bus_reply_method_errno(bus, message, r, NULL);
+ if (pid == 0) {
+ r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+ if (r < 0)
+ return sd_bus_reply_method_errno(bus, message, r, NULL);
+ }
+
r = manager_get_user_by_pid(m, pid, &user);
if (r < 0)
return sd_bus_reply_method_errno(bus, message, r, NULL);
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index b552662..505bc17 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -86,17 +86,25 @@ static int method_get_machine_by_pid(sd_bus *bus, sd_bus_message *message, void
_cleanup_free_ char *p = NULL;
Manager *m = userdata;
Machine *machine = NULL;
- uint32_t pid;
+ pid_t pid;
int r;
assert(bus);
assert(message);
assert(m);
+ assert_cc(sizeof(pid_t) == sizeof(uint32_t));
+
r = sd_bus_message_read(message, "u", &pid);
if (r < 0)
return sd_bus_reply_method_errno(bus, message, r, NULL);
+ if (pid == 0) {
+ r = sd_bus_get_owner_pid(bus, sd_bus_message_get_sender(message), &pid);
+ if (r < 0)
+ return sd_bus_reply_method_errno(bus, message, r, NULL);
+ }
+
r = manager_get_machine_by_pid(m, pid, &machine);
if (r < 0)
return sd_bus_reply_method_errno(bus, message, r, NULL);
More information about the systemd-commits
mailing list