This way clients can skip invoking GetSessionByPID() for their own PID
or a similar call to access these objects.
};
int seat_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
};
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;
Manager *m = userdata;
Seat *seat;
assert(bus);
assert(path);
assert(bus);
assert(path);
assert(found);
assert(m);
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;
+ }
};
int session_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
};
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;
Manager *m = userdata;
Session *session;
assert(bus);
assert(path);
assert(bus);
assert(path);
assert(found);
assert(m);
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;
*found = session;
return 1;
};
int user_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
};
int user_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
-
- _cleanup_free_ char *e = NULL;
- unsigned long lu;
- const char *p;
assert(found);
assert(m);
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;
+ }
#include <string.h>
#include "bus-util.h"
#include <string.h>
#include "bus-util.h"
#include "machine.h"
static int property_get_id(
#include "machine.h"
static int property_get_id(
};
int machine_object_find(sd_bus *bus, const char *path, const char *interface, void **found, void *userdata) {
};
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;
Manager *m = userdata;
Machine *machine;
assert(bus);
assert(path);
assert(bus);
assert(path);
assert(found);
assert(m);
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;
*found = machine;
return 1;
return strappend("/org/freedesktop/machine1/machine/", e);
}
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;
int machine_send_signal(Machine *m, bool new_machine) {
_cleanup_free_ char *p = NULL;
-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;
int match_job_removed(sd_bus *bus, sd_bus_message *message, void *userdata) {
const char *path, *result, *unit;
Manager *m = userdata;