#include <string.h>
#include "bus-util.h"
+#include "strv.h"
#include "machine.h"
static int property_get_id(
r = machine_stop(m);
if (r < 0)
- return sd_bus_reply_method_errno(bus, message, r, NULL);
+ return sd_bus_reply_method_errno(message, r, NULL);
- return sd_bus_reply_method_return(bus, message, NULL);
+ return sd_bus_reply_method_return(message, NULL);
}
static int method_kill(sd_bus *bus, sd_bus_message *message, void *userdata) {
r = sd_bus_message_read(message, "si", &swho, &signo);
if (r < 0)
- return sd_bus_reply_method_errno(bus, message, r, NULL);
+ return sd_bus_reply_method_errno(message, r, NULL);
if (isempty(swho))
who = KILL_ALL;
else {
who = kill_who_from_string(swho);
if (who < 0)
- return sd_bus_reply_method_errorf(bus, message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
+ return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid kill parameter '%s'", swho);
}
if (signo <= 0 || signo >= _NSIG)
- return sd_bus_reply_method_errorf(bus, message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
+ return sd_bus_reply_method_errorf(message, SD_BUS_ERROR_INVALID_ARGS, "Invalid signal %i", signo);
r = machine_kill(m, who, signo);
if (r < 0)
- return sd_bus_reply_method_errno(bus, message, r, NULL);
+ return sd_bus_reply_method_errno(message, r, NULL);
- return sd_bus_reply_method_return(bus, message, NULL);
+ return sd_bus_reply_method_return(message, NULL);
}
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);
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 = sd_bus_label_unescape(p);
+ if (!e)
+ return -ENOMEM;
+
+ machine = hashmap_get(m->machines, e);
+ if (!machine)
+ return 0;
+ }
*found = machine;
return 1;
assert(m);
- e = bus_path_escape(m->name);
+ e = sd_bus_label_escape(m->name);
if (!e)
return NULL;
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;
m->create_message = NULL;
if (error)
- return sd_bus_reply_method_error(m->manager->bus, c, error);
+ return sd_bus_reply_method_error(c, error);
/* Update the machine state file before we notify the client
* about the result. */
if (!p)
return -ENOMEM;
- return sd_bus_reply_method_return(m->manager->bus, c, "o", p);
+ return sd_bus_reply_method_return(c, "o", p);
}