1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/***
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2011 Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is free software; you can redistribute it and/or modify it
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering under the terms of the GNU Lesser General Public License as published by
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering (at your option) any later version.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering systemd is distributed in the hope that it will be useful, but
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Lesser General Public License for more details.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering You should have received a copy of the GNU Lesser General Public License
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering***/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include <errno.h>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include <string.h>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering#include <unistd.h>
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering#include "sd-id128.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "btrfs-util.h"
96aad8d15a324d0e956a4e5653a11a67b209b41aLennart Poettering#include "bus-common-errors.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "bus-util.h"
23c80348e656a4e6fd9ba8f17523a65b6fa349a0Kay Sievers#include "cgroup-util.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "fd-util.h"
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering#include "formats-util.h"
25300b5a1fcf54674a69d0f4ab08925be00b0227Lennart Poettering#include "hostname-util.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "image-dbus.h"
a90fb858ac91de4c14c9b68da6060731954515b7Lennart Poettering#include "io-util.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "machine-dbus.h"
003dffde2c1b93afbc9aff24b277276f65424406Lennart Poettering#include "machine-image.h"
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering#include "machine-pool.h"
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering#include "machined.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "path-util.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "process-util.h"
15a5e95075a7f6007dd97b2a165c8ed16fe683dfLennart Poettering#include "stdio-util.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "strv.h"
3ffd4af22052963e7a29431721ee204e634bea75Lennart Poettering#include "unit-name.h"
b1d4f8e154bf61b5de1b27461ef8e9c8c5e838a1Lennart Poettering#include "user-util.h"
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringstatic int property_get_pool_path(
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus *bus,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *path,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *interface,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *property,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus_message *reply,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering void *userdata,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus_error *error) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering assert(bus);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering assert(reply);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering return sd_bus_message_append(reply, "s", "/var/lib/machines");
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering}
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringstatic int property_get_pool_usage(
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus *bus,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *path,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *interface,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *property,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus_message *reply,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering void *userdata,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus_error *error) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering _cleanup_close_ int fd = -1;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering uint64_t usage = (uint64_t) -1;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering struct stat st;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering assert(bus);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering assert(reply);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering /* We try to read the quota info from /var/lib/machines, as
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering * well as the usage of the loopback file
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering * /var/lib/machines.raw, and pick the larger value. */
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (fd >= 0) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering BtrfsQuotaInfo q;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
5bcd08db289cd02aad8a89b37b2a46244a7bd473Lennart Poettering if (btrfs_subvol_get_subtree_quota_fd(fd, 0, &q) >= 0)
cb81cd8073392936882643af0129934bf67e96c4Lennart Poettering usage = q.referenced;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering }
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (stat("/var/lib/machines.raw", &st) >= 0) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (usage == (uint64_t) -1 || st.st_blocks * 512ULL > usage)
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering usage = st.st_blocks * 512ULL;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering }
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering return sd_bus_message_append(reply, "t", usage);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering}
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poetteringstatic int property_get_pool_limit(
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus *bus,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *path,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *interface,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering const char *property,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus_message *reply,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering void *userdata,
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering sd_bus_error *error) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering _cleanup_close_ int fd = -1;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering uint64_t size = (uint64_t) -1;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering struct stat st;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering assert(bus);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering assert(reply);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering /* We try to read the quota limit from /var/lib/machines, as
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering * well as the size of the loopback file
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering * /var/lib/machines.raw, and pick the smaller value. */
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (fd >= 0) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering BtrfsQuotaInfo q;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
5bcd08db289cd02aad8a89b37b2a46244a7bd473Lennart Poettering if (btrfs_subvol_get_subtree_quota_fd(fd, 0, &q) >= 0)
cb81cd8073392936882643af0129934bf67e96c4Lennart Poettering size = q.referenced_max;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering }
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (stat("/var/lib/machines.raw", &st) >= 0) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (size == (uint64_t) -1 || (uint64_t) st.st_size < size)
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering size = st.st_size;
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering }
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering return sd_bus_message_append(reply, "t", size);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering}
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_free_ char *p = NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const char *name;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(m);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machines, name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!machine)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering p = machine_bus_path(machine);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!p)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return -ENOMEM;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
df2d202e6ed4001a21c6512c244acad5d4706c87Lennart Poettering return sd_bus_reply_method_return(message, "o", p);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering}
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering _cleanup_free_ char *p = NULL;
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering Manager *m = userdata;
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering const char *name;
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering int r;
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering assert(message);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering assert(m);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering if (r < 0)
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering return r;
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering r = image_find(name, NULL);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering if (r == 0)
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering if (r < 0)
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering return r;
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering p = image_bus_path(name);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering if (!p)
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering return -ENOMEM;
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering return sd_bus_reply_method_return(message, "o", p);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering}
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_free_ char *p = NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine = NULL;
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering pid_t pid;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(m);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering assert_cc(sizeof(pid_t) == sizeof(uint32_t));
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "u", &pid);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
06820eafdbc3dd89cb1f7563564c7d91426709caLennart Poettering if (pid < 0)
06820eafdbc3dd89cb1f7563564c7d91426709caLennart Poettering return -EINVAL;
06820eafdbc3dd89cb1f7563564c7d91426709caLennart Poettering
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering if (pid == 0) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering if (r < 0)
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering return r;
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering r = sd_bus_creds_get_pid(creds, &pid);
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering }
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = manager_get_machine_by_pid(m, pid, &machine);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!machine)
de0671ee7fe465e108f62dcbbbe9366f81dd9e9aZbigniew Jędrzejewski-Szmek return sd_bus_error_setf(error, BUS_ERROR_NO_MACHINE_FOR_PID, "PID "PID_FMT" does not belong to any known machine", pid);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering p = machine_bus_path(machine);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!p)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return -ENOMEM;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
df2d202e6ed4001a21c6512c244acad5d4706c87Lennart Poettering return sd_bus_reply_method_return(message, "o", p);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering}
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_list_machines(sd_bus_message *message, void *userdata, sd_bus_error *error) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Iterator i;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(m);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
df2d202e6ed4001a21c6512c244acad5d4706c87Lennart Poettering r = sd_bus_message_new_method_return(message, &reply);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_set_errno(error, r);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_open_container(reply, 'a', "(ssso)");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_set_errno(error, r);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering HASHMAP_FOREACH(machine, m->machines, i) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_free_ char *p = NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering p = machine_bus_path(machine);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!p)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return -ENOMEM;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(reply, "(ssso)",
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine->name,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering strempty(machine_class_to_string(machine->class)),
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine->service,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering p);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_set_errno(error, r);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_close_container(reply);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_set_errno(error, r);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
9030ca462bd13cd6536299814e4a71d5c5e85be9Lennart Poettering return sd_bus_send(NULL, reply, NULL);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering}
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poetteringstatic int method_create_or_register_machine(Manager *manager, sd_bus_message *message, bool read_network, Machine **_m, sd_bus_error *error) {
8aec412ff697bc14995746953912ca6fdf2c9ba8Lennart Poettering const char *name, *service, *class, *root_directory;
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering const int32_t *netif = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering MachineClass c;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering uint32_t leader;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering sd_id128_t id;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const void *v;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Machine *m;
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering size_t n, n_netif = 0;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(manager);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering assert(message);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering assert(_m);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
7f0d207d2c816e0a8cb2742b0a789911f7c99356Lennart Poettering if (!machine_name_is_valid(name))
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read_array(message, 'y', &v, &n);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (n == 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering id = SD_ID128_NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering else if (n == 16)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering memcpy(&id, v, n);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering else
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "ssus", &service, &class, &leader, &root_directory);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering if (read_network) {
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering size_t i;
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering r = sd_bus_message_read_array(message, 'i', (const void**) &netif, &n_netif);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering if (r < 0)
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering return r;
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering n_netif /= sizeof(int32_t);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering for (i = 0; i < n_netif; i++) {
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering if (netif[i] <= 0)
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid network interface index %i", netif[i]);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering }
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering }
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (isempty(class))
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering c = _MACHINE_CLASS_INVALID;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering else {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering c = machine_class_from_string(class);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (c < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (leader == 1)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!isempty(root_directory) && !path_is_absolute(root_directory))
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (leader == 0) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering if (r < 0)
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering return r;
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert_cc(sizeof(uint32_t) == sizeof(pid_t));
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering r = sd_bus_creds_get_pid(creds, (pid_t*) &leader);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering }
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (hashmap_get(manager->machines, name))
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_MACHINE_EXISTS, "Machine '%s' already exists", name);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering r = manager_add_machine(manager, name, &m);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering m->leader = leader;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering m->class = c;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering m->id = id;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!isempty(service)) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering m->service = strdup(service);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!m->service) {
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering r = -ENOMEM;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering goto fail;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!isempty(root_directory)) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering m->root_directory = strdup(root_directory);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!m->root_directory) {
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering r = -ENOMEM;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering goto fail;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering if (n_netif > 0) {
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering m->netif = memdup(netif, sizeof(int32_t) * n_netif);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering if (!m->netif) {
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering r = -ENOMEM;
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering goto fail;
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering }
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering m->n_netif = n_netif;
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering }
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering *_m = m;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering return 1;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poetteringfail:
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering machine_add_to_gc_queue(m);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering return r;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering}
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_create_machine_internal(sd_bus_message *message, bool read_network, void *userdata, sd_bus_error *error) {
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering Manager *manager = userdata;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering Machine *m = NULL;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering int r;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(message);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(manager);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering r = method_create_or_register_machine(manager, message, read_network, &m, error);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering if (r < 0)
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering return r;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = sd_bus_message_enter_container(message, 'a', "(sv)");
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering if (r < 0)
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering goto fail;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering r = machine_start(m, message, error);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering goto fail;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering m->create_message = sd_bus_message_ref(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return 1;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringfail:
a3e7f417d72ba3251fd6b3a228a2721a4b725a03Zbigniew Jędrzejewski-Szmek machine_add_to_gc_queue(m);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering return r;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_create_machine_with_network(sd_bus_message *message, void *userdata, sd_bus_error *error) {
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return method_create_machine_internal(message, true, userdata, error);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering}
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_create_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return method_create_machine_internal(message, false, userdata, error);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering}
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_register_machine_internal(sd_bus_message *message, bool read_network, void *userdata, sd_bus_error *error) {
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering Manager *manager = userdata;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering _cleanup_free_ char *p = NULL;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering Machine *m = NULL;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering int r;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(message);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(manager);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering r = method_create_or_register_machine(manager, message, read_network, &m, error);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering if (r < 0)
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering return r;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = cg_pid_get_unit(m->leader, &m->unit);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering if (r < 0) {
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = sd_bus_error_set_errnof(error, r, "Failed to determine unit of process "PID_FMT" : %s", m->leader, strerror(-r));
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering goto fail;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering }
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = machine_start(m, NULL, error);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering if (r < 0)
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering goto fail;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering p = machine_bus_path(m);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering if (!p) {
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = -ENOMEM;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering goto fail;
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering }
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering return sd_bus_reply_method_return(message, "o", p);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poetteringfail:
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering machine_add_to_gc_queue(m);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_register_machine_with_network(sd_bus_message *message, void *userdata, sd_bus_error *error) {
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return method_register_machine_internal(message, true, userdata, error);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering}
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_register_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return method_register_machine_internal(message, false, userdata, error);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering}
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_terminate_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const char *name;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(message);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(m);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_set_errno(error, r);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machines, name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!machine)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_terminate(message, machine, error);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_kill_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const char *name;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(m);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_set_errno(error, r);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machines, name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!machine)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_kill(message, machine, error);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering}
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine_addresses(sd_bus_message *message, void *userdata, sd_bus_error *error) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering Manager *m = userdata;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering Machine *machine;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering const char *name;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering int r;
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering assert(message);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering assert(m);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_set_errno(error, r);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering machine = hashmap_get(m->machines, name);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering if (!machine)
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_get_addresses(message, machine, error);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine_os_release(sd_bus_message *message, void *userdata, sd_bus_error *error) {
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering Manager *m = userdata;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering Machine *machine;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering const char *name;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering int r;
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering assert(message);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering assert(m);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = sd_bus_message_read(message, "s", &name);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (r < 0)
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return sd_bus_error_set_errno(error, r);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering machine = hashmap_get(m->machines, name);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering if (!machine)
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_get_os_release(message, machine, error);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering}
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_list_images(sd_bus_message *message, void *userdata, sd_bus_error *error) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering _cleanup_(image_hashmap_freep) Hashmap *images = NULL;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering Manager *m = userdata;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering Image *image;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering Iterator i;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering int r;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(message);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering assert(m);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering images = hashmap_new(&string_hash_ops);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (!images)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return -ENOMEM;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r = image_discover(images);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (r < 0)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return r;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r = sd_bus_message_new_method_return(message, &reply);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (r < 0)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return r;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering r = sd_bus_message_open_container(reply, 'a', "(ssbttto)");
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (r < 0)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return r;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering HASHMAP_FOREACH(image, images, i) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering _cleanup_free_ char *p = NULL;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering p = image_bus_path(image->name);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (!p)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return -ENOMEM;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering r = sd_bus_message_append(reply, "(ssbttto)",
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering image->name,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering image_type_to_string(image->type),
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering image->read_only,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering image->crtime,
10f9c75519671e7c7ab8993b54fe22da7c2d0c38Lennart Poettering image->mtime,
c19de71113f956809995fc68817e055e9f61f607Lennart Poettering image->usage,
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering p);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (r < 0)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return r;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering }
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r = sd_bus_message_close_container(reply);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering if (r < 0)
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering return r;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
9030ca462bd13cd6536299814e4a71d5c5e85be9Lennart Poettering return sd_bus_send(NULL, reply, NULL);
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering}
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_open_machine_pty(sd_bus_message *message, void *userdata, sd_bus_error *error) {
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering Manager *m = userdata;
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering Machine *machine;
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering const char *name;
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering int r;
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering assert(message);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering assert(m);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering r = sd_bus_message_read(message, "s", &name);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering if (r < 0)
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering return sd_bus_error_set_errno(error, r);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering machine = hashmap_get(m->machines, name);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering if (!machine)
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_open_pty(message, machine, error);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering}
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_open_machine_login(sd_bus_message *message, void *userdata, sd_bus_error *error) {
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering Manager *m = userdata;
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering Machine *machine;
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering const char *name;
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering int r;
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering assert(message);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering assert(m);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering r = sd_bus_message_read(message, "s", &name);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering if (r < 0)
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering return r;
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering machine = hashmap_get(m->machines, name);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering if (!machine)
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_open_login(message, machine, error);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering}
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poetteringstatic int method_open_machine_shell(sd_bus_message *message, void *userdata, sd_bus_error *error) {
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering Manager *m = userdata;
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering Machine *machine;
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering const char *name;
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering int r;
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering assert(message);
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering assert(m);
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering r = sd_bus_message_read(message, "s", &name);
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering if (r < 0)
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering return r;
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering machine = hashmap_get(m->machines, name);
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering if (!machine)
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering return bus_machine_method_open_shell(message, machine, error);
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering}
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_bind_mount_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering Manager *m = userdata;
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering Machine *machine;
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering const char *name;
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering int r;
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering assert(message);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering assert(m);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering r = sd_bus_message_read(message, "s", &name);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering if (r < 0)
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering return r;
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering machine = hashmap_get(m->machines, name);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering if (!machine)
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_bind_mount(message, machine, error);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering}
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_copy_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering Manager *m = userdata;
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering Machine *machine;
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering const char *name;
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering int r;
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering assert(message);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering assert(m);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering r = sd_bus_message_read(message, "s", &name);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering if (r < 0)
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering return r;
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering machine = hashmap_get(m->machines, name);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering if (!machine)
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_copy(message, machine, error);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering}
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_remove_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering _cleanup_(image_unrefp) Image* i = NULL;
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering const char *name;
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering int r;
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering assert(message);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering r = sd_bus_message_read(message, "s", &name);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering if (r < 0)
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering return r;
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering if (!image_name_is_valid(name))
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering r = image_find(name, &i);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering if (r < 0)
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering return r;
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering if (r == 0)
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering i->userdata = userdata;
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_remove(message, i, error);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering}
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_rename_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering _cleanup_(image_unrefp) Image* i = NULL;
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering const char *old_name;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering int r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering assert(message);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering r = sd_bus_message_read(message, "s", &old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r < 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (!image_name_is_valid(old_name))
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering r = image_find(old_name, &i);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r < 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r == 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering i->userdata = userdata;
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_rename(message, i, error);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering}
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_clone_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering _cleanup_(image_unrefp) Image *i = NULL;
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering const char *old_name;
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering int r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(message);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering r = sd_bus_message_read(message, "s", &old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r < 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (!image_name_is_valid(old_name))
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering r = image_find(old_name, &i);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r < 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r == 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering i->userdata = userdata;
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_clone(message, i, error);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering}
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_mark_image_read_only(sd_bus_message *message, void *userdata, sd_bus_error *error) {
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering _cleanup_(image_unrefp) Image *i = NULL;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering const char *name;
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering int r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(message);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering r = sd_bus_message_read(message, "s", &name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r < 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (!image_name_is_valid(name))
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering r = image_find(name, &i);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r < 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return r;
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering if (r == 0)
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering i->userdata = userdata;
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_mark_read_only(message, i, error);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering}
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_set_pool_limit(sd_bus_message *message, void *userdata, sd_bus_error *error) {
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering Manager *m = userdata;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering uint64_t limit;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering int r;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(message);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering r = sd_bus_message_read(message, "t", &limit);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (r < 0)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return r;
a90fb858ac91de4c14c9b68da6060731954515b7Lennart Poettering if (!FILE_SIZE_VALID_OR_INFINITY(limit))
a90fb858ac91de4c14c9b68da6060731954515b7Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New limit out of range");
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering r = bus_verify_polkit_async(
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering message,
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering CAP_SYS_ADMIN,
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "org.freedesktop.machine1.manage-machines",
403ed0e5c914f2a0a683403d8ba7eaf96e3ffcdfMichael Chapman NULL,
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering false,
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering UID_INVALID,
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering &m->polkit_registry,
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering error);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (r < 0)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return r;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (r == 0)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return 1; /* Will call us back */
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering /* Set up the machine directory if necessary */
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering r = setup_machine_directory(limit, error);
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering if (r < 0)
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering return r;
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering /* Resize the backing loopback device, if there is one, except if we asked to drop any limit */
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering if (limit != (uint64_t) -1) {
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering r = btrfs_resize_loopback("/var/lib/machines", limit, false);
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering if (r == -ENOTTY)
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering if (r < 0 && r != -ENODEV) /* ignore ENODEV, as that's what is returned if the file system is not on loopback */
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering return sd_bus_error_set_errnof(error, r, "Failed to adjust loopback limit: %m");
05e8f270a9ca97e1014184df113494b143639fb8Lennart Poettering }
efe0286285a7432f738fafae840fa4eda51c2986Lennart Poettering
5bcd08db289cd02aad8a89b37b2a46244a7bd473Lennart Poettering (void) btrfs_qgroup_set_limit("/var/lib/machines", 0, limit);
5bcd08db289cd02aad8a89b37b2a46244a7bd473Lennart Poettering
5bcd08db289cd02aad8a89b37b2a46244a7bd473Lennart Poettering r = btrfs_subvol_set_subtree_quota_limit("/var/lib/machines", 0, limit);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (r == -ENOTTY)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
26166c88e0b47b83972f32b5057ecbffe06bf904Lennart Poettering if (r < 0)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_set_errnof(error, r, "Failed to adjust quota limit: %m");
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_reply_method_return(message, NULL);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering}
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_set_image_limit(sd_bus_message *message, void *userdata, sd_bus_error *error) {
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering _cleanup_(image_unrefp) Image *i = NULL;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering const char *name;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering int r;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(message);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering r = sd_bus_message_read(message, "s", &name);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (r < 0)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return r;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (!image_name_is_valid(name))
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering r = image_find(name, &i);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (r < 0)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return r;
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering if (r == 0)
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering i->userdata = userdata;
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_set_limit(message, i, error);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering}
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_from_machine_user(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering _cleanup_fclose_ FILE *f = NULL;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Manager *m = userdata;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering const char *name, *p;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Machine *machine;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering uint32_t uid;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int r;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "su", &name, &uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (r < 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return r;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!uid_is_valid(uid))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering machine = hashmap_get(m->machines, name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!machine)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering if (machine->class != MACHINE_CONTAINER)
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines.");
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering p = procfs_file_alloca(machine->leader, "uid_map");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering f = fopen(p, "re");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!f)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -errno;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering for (;;) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering uid_t uid_base, uid_shift, uid_range, converted;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int k;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering errno = 0;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering k = fscanf(f, UID_FMT " " UID_FMT " " UID_FMT, &uid_base, &uid_shift, &uid_range);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k < 0 && feof(f))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering break;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k != 3) {
b3267152783d5784c45010615045d4e8ee459da2Zbigniew Jędrzejewski-Szmek if (ferror(f) && errno > 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -errno;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -EIO;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (uid < uid_base || uid >= uid_base + uid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering continue;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering converted = uid - uid_base + uid_shift;
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!uid_is_valid(converted))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "u", (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "Machine '%s' has no matching user mappings.", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering}
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_to_machine_user(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Manager *m = userdata;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Machine *machine;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering uid_t uid;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Iterator i;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int r;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "u", &uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (r < 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return r;
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!uid_is_valid(uid))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (uid < 0x10000)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "User " UID_FMT " belongs to host UID range", uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering HASHMAP_FOREACH(machine, m->machines, i) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering _cleanup_fclose_ FILE *f = NULL;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering char p[strlen("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1];
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering if (machine->class != MACHINE_CONTAINER)
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering continue;
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering xsprintf(p, "/proc/" UID_FMT "/uid_map", machine->leader);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering f = fopen(p, "re");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!f) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering log_warning_errno(errno, "Failed top open %s, ignoring,", p);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering continue;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering for (;;) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering _cleanup_free_ char *o = NULL;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering uid_t uid_base, uid_shift, uid_range, converted;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int k;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering errno = 0;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering k = fscanf(f, UID_FMT " " UID_FMT " " UID_FMT, &uid_base, &uid_shift, &uid_range);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k < 0 && feof(f))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering break;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k != 3) {
b3267152783d5784c45010615045d4e8ee459da2Zbigniew Jędrzejewski-Szmek if (ferror(f) && errno > 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -errno;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -EIO;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (uid < uid_shift || uid >= uid_shift + uid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering continue;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering converted = (uid - uid_shift + uid_base);
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!uid_is_valid(converted))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering o = machine_bus_path(machine);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!o)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -ENOMEM;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "sou", machine->name, o, (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "No matching user mapping for " UID_FMT ".", uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering}
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_from_machine_group(sd_bus_message *message, void *groupdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering _cleanup_fclose_ FILE *f = NULL;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Manager *m = groupdata;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering const char *name, *p;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Machine *machine;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering uint32_t gid;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int r;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "su", &name, &gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (r < 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return r;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!gid_is_valid(gid))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering machine = hashmap_get(m->machines, name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!machine)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering if (machine->class != MACHINE_CONTAINER)
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines.");
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering p = procfs_file_alloca(machine->leader, "gid_map");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering f = fopen(p, "re");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!f)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -errno;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering for (;;) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering gid_t gid_base, gid_shift, gid_range, converted;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int k;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering errno = 0;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering k = fscanf(f, GID_FMT " " GID_FMT " " GID_FMT, &gid_base, &gid_shift, &gid_range);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k < 0 && feof(f))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering break;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k != 3) {
b3267152783d5784c45010615045d4e8ee459da2Zbigniew Jędrzejewski-Szmek if (ferror(f) && errno > 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -errno;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -EIO;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (gid < gid_base || gid >= gid_base + gid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering continue;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering converted = gid - gid_base + gid_shift;
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!gid_is_valid(converted))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "u", (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "Machine '%s' has no matching group mappings.", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering}
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_to_machine_group(sd_bus_message *message, void *groupdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Manager *m = groupdata;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Machine *machine;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering gid_t gid;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering Iterator i;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int r;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "u", &gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (r < 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return r;
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!gid_is_valid(gid))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (gid < 0x10000)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "Group " GID_FMT " belongs to host GID range", gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering HASHMAP_FOREACH(machine, m->machines, i) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering _cleanup_fclose_ FILE *f = NULL;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering char p[strlen("/proc//gid_map") + DECIMAL_STR_MAX(pid_t) + 1];
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering if (machine->class != MACHINE_CONTAINER)
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering continue;
a79366e22a43ed81017e2d8c2426431d369f3cfaLennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering xsprintf(p, "/proc/" GID_FMT "/gid_map", machine->leader);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering f = fopen(p, "re");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!f) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering log_warning_errno(errno, "Failed top open %s, ignoring,", p);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering continue;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering for (;;) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering _cleanup_free_ char *o = NULL;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering gid_t gid_base, gid_shift, gid_range, converted;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering int k;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering errno = 0;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering k = fscanf(f, GID_FMT " " GID_FMT " " GID_FMT, &gid_base, &gid_shift, &gid_range);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k < 0 && feof(f))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering break;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (k != 3) {
b3267152783d5784c45010615045d4e8ee459da2Zbigniew Jędrzejewski-Szmek if (ferror(f) && errno > 0)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -errno;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -EIO;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (gid < gid_shift || gid >= gid_shift + gid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering continue;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering converted = (gid - gid_shift + gid_base);
c077529ba6852192c464772ce907670850210dfeLennart Poettering if (!gid_is_valid(converted))
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering o = machine_bus_path(machine);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering if (!o)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return -ENOMEM;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "sou", machine->name, o, (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering }
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "No matching group mapping for " GID_FMT ".", gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering}
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringconst sd_bus_vtable manager_vtable[] = {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering SD_BUS_VTABLE_START(0),
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering SD_BUS_PROPERTY("PoolPath", "s", property_get_pool_path, 0, 0),
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering SD_BUS_PROPERTY("PoolUsage", "t", property_get_pool_usage, 0, 0),
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering SD_BUS_PROPERTY("PoolLimit", "t", property_get_pool_limit, 0, 0),
adacb9575a09981fcf11279f2f661e3fc21e58ffLennart Poettering SD_BUS_METHOD("GetMachine", "s", "o", method_get_machine, SD_BUS_VTABLE_UNPRIVILEGED),
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering SD_BUS_METHOD("GetImage", "s", "o", method_get_image, SD_BUS_VTABLE_UNPRIVILEGED),
adacb9575a09981fcf11279f2f661e3fc21e58ffLennart Poettering SD_BUS_METHOD("GetMachineByPID", "u", "o", method_get_machine_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),
adacb9575a09981fcf11279f2f661e3fc21e58ffLennart Poettering SD_BUS_METHOD("ListMachines", NULL, "a(ssso)", method_list_machines, SD_BUS_VTABLE_UNPRIVILEGED),
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering SD_BUS_METHOD("ListImages", NULL, "a(ssbttto)", method_list_images, SD_BUS_VTABLE_UNPRIVILEGED),
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering SD_BUS_METHOD("CreateMachine", "sayssusa(sv)", "o", method_create_machine, 0),
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering SD_BUS_METHOD("CreateMachineWithNetwork", "sayssusaia(sv)", "o", method_create_machine_with_network, 0),
8d07a7c47159ebc2bcc775e2c1997cb44bd1ac95Lennart Poettering SD_BUS_METHOD("RegisterMachine", "sayssus", "o", method_register_machine, 0),
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering SD_BUS_METHOD("RegisterMachineWithNetwork", "sayssusai", "o", method_register_machine_with_network, 0),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("TerminateMachine", "s", NULL, method_terminate_machine, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("KillMachine", "ssi", NULL, method_kill_machine, SD_BUS_VTABLE_UNPRIVILEGED),
3a6fb33c54bc64398e0af1c9d7c74a6b614a849dLennart Poettering SD_BUS_METHOD("GetMachineAddresses", "s", "a(iay)", method_get_machine_addresses, SD_BUS_VTABLE_UNPRIVILEGED),
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering SD_BUS_METHOD("GetMachineOSRelease", "s", "a{ss}", method_get_machine_os_release, SD_BUS_VTABLE_UNPRIVILEGED),
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering SD_BUS_METHOD("OpenMachinePTY", "s", "hs", method_open_machine_pty, 0),
d04c1fb8e215600b4950c6778c6c16ddafc14024Lennart Poettering SD_BUS_METHOD("OpenMachineLogin", "s", "hs", method_open_machine_login, SD_BUS_VTABLE_UNPRIVILEGED),
49af9e1368571f4e423cde0fd45ee284451434d1Lennart Poettering SD_BUS_METHOD("OpenMachineShell", "sssasas", "hs", method_open_machine_shell, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("BindMountMachine", "sssbb", NULL, method_bind_mount_machine, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("CopyFromMachine", "sss", NULL, method_copy_machine, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("CopyToMachine", "sss", NULL, method_copy_machine, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("RemoveImage", "s", NULL, method_remove_image, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("RenameImage", "ss", NULL, method_rename_image, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("CloneImage", "ssb", NULL, method_clone_image, SD_BUS_VTABLE_UNPRIVILEGED),
70244d1d25eb80b57e160ea004d0e6bf793d4cafLennart Poettering SD_BUS_METHOD("MarkImageReadOnly", "sb", NULL, method_mark_image_read_only, SD_BUS_VTABLE_UNPRIVILEGED),
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering SD_BUS_METHOD("SetPoolLimit", "t", NULL, method_set_pool_limit, SD_BUS_VTABLE_UNPRIVILEGED),
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering SD_BUS_METHOD("SetImageLimit", "st", NULL, method_set_image_limit, SD_BUS_VTABLE_UNPRIVILEGED),
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering SD_BUS_METHOD("MapFromMachineUser", "su", "u", method_map_from_machine_user, SD_BUS_VTABLE_UNPRIVILEGED),
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering SD_BUS_METHOD("MapToMachineUser", "u", "sou", method_map_to_machine_user, SD_BUS_VTABLE_UNPRIVILEGED),
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering SD_BUS_METHOD("MapFromMachineGroup", "su", "u", method_map_from_machine_group, SD_BUS_VTABLE_UNPRIVILEGED),
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering SD_BUS_METHOD("MapToMachineGroup", "u", "sou", method_map_to_machine_group, SD_BUS_VTABLE_UNPRIVILEGED),
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering SD_BUS_SIGNAL("MachineNew", "so", 0),
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering SD_BUS_SIGNAL("MachineRemoved", "so", 0),
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering SD_BUS_VTABLE_END
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering};
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const char *path, *result, *unit;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering uint32_t id;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(m);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0) {
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering bus_log_parse_error(r);
65d73cf042ba7de11d254f5c4714f467db64b7c3Lennart Poettering return 0;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering }
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machine_units, unit);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!machine)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return 0;
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (streq_ptr(path, machine->scope_job)) {
491ac9f2c4aeda8c40edde35112404b737e38b60Lennart Poettering machine->scope_job = mfree(machine->scope_job);
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (machine->started) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (streq(result, "done"))
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine_send_create_reply(machine, NULL);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering else {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error e = SD_BUS_ERROR_NULL;
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering machine_send_create_reply(machine, &e);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering }
49f3fffd94591bdf2bd6c2233a9300daeab79566Lennart Poettering }
49f3fffd94591bdf2bd6c2233a9300daeab79566Lennart Poettering
49f3fffd94591bdf2bd6c2233a9300daeab79566Lennart Poettering machine_save(machine);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine_add_to_gc_queue(machine);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return 0;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_free_ char *unit = NULL;
49f3fffd94591bdf2bd6c2233a9300daeab79566Lennart Poettering const char *path;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine;
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering int r;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(m);
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering path = sd_bus_message_get_path(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (!path)
554604b3073467af75dc94fac9e2343148603289Lennart Poettering return 0;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering r = unit_name_from_dbus_path(path, &unit);
e5f5b5b9c92d59ef3cb5169982cb6f436c9206faLennart Poettering if (r == -EINVAL) /* not for a unit */
e5f5b5b9c92d59ef3cb5169982cb6f436c9206faLennart Poettering return 0;
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering if (r < 0){
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering log_oom();
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering return 0;
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering }
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machine_units, unit);
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering if (!machine)
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering return 0;
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering machine_add_to_gc_queue(machine);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return 0;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering}
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const char *path, *unit;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Manager *m = userdata;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Machine *machine;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(message);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(m);
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "so", &unit, &path);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0) {
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering bus_log_parse_error(r);
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering return 0;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering }
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machine_units, unit);
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering if (!machine)
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering return 0;
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering machine_add_to_gc_queue(machine);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return 0;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering}
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering Manager *m = userdata;
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering Machine *machine;
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering Iterator i;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int b, r;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(message);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering assert(m);
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "b", &b);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0) {
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering bus_log_parse_error(r);
65d73cf042ba7de11d254f5c4714f467db64b7c3Lennart Poettering return 0;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering }
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering if (b)
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering return 0;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering /* systemd finished reloading, let's recheck all our machines */
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering log_debug("System manager has been reloaded, rechecking machines...");
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering HASHMAP_FOREACH(machine, m->machines, i)
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering machine_add_to_gc_queue(machine);
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
554604b3073467af75dc94fac9e2343148603289Lennart Poettering return 0;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering}
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint manager_start_scope(
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Manager *manager,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *scope,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering pid_t pid,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *slice,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *description,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_message *more_properties,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_error *error,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering char **job) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(manager);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(scope);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(pid > 1);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_new_method_call(
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering manager->bus,
151b9b9662a90455262ce575a8a8ae74bf4ff336Lennart Poettering &m,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "/org/freedesktop/systemd1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1.Manager",
151b9b9662a90455262ce575a8a8ae74bf4ff336Lennart Poettering "StartTransientUnit");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering r = sd_bus_message_append(m, "ss", strempty(scope), "fail");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_open_container(m, 'a', "(sv)");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!isempty(slice)) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(m, "(sv)", "Slice", "s", slice);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!isempty(description)) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(m, "(sv)", "Description", "s", description);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, pid);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
a931ad47a8623163a29d898224d8a8c1177ffdafLennart Poettering r = sd_bus_message_append(m, "(sv)", "Delegate", "b", 1);
a931ad47a8623163a29d898224d8a8c1177ffdafLennart Poettering if (r < 0)
a931ad47a8623163a29d898224d8a8c1177ffdafLennart Poettering return r;
a931ad47a8623163a29d898224d8a8c1177ffdafLennart Poettering
cf7d1a30e44bf380027a2e73f9bf13f423a33cc1Lennart Poettering r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", UINT64_C(16384));
b370fec2b964c9ced48379824e896f44ad02a59aAlban Crequy if (r < 0)
b370fec2b964c9ced48379824e896f44ad02a59aAlban Crequy return bus_log_create_error(r);
b370fec2b964c9ced48379824e896f44ad02a59aAlban Crequy
554604b3073467af75dc94fac9e2343148603289Lennart Poettering if (more_properties) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_copy(m, more_properties, true);
554604b3073467af75dc94fac9e2343148603289Lennart Poettering if (r < 0)
554604b3073467af75dc94fac9e2343148603289Lennart Poettering return r;
554604b3073467af75dc94fac9e2343148603289Lennart Poettering }
554604b3073467af75dc94fac9e2343148603289Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_close_container(m);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
86b8d289717bad2800342efca0a5023aa8374e9cLennart Poettering r = sd_bus_message_append(m, "a(sa(sv))", 0);
86b8d289717bad2800342efca0a5023aa8374e9cLennart Poettering if (r < 0)
86b8d289717bad2800342efca0a5023aa8374e9cLennart Poettering return r;
86b8d289717bad2800342efca0a5023aa8374e9cLennart Poettering
c49b30a23583ff39daaa26696bcab478d2fee0bbLennart Poettering r = sd_bus_call(manager->bus, m, 0, error, &reply);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (job) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *j;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering char *copy;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(reply, "o", &j);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering copy = strdup(j);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!copy)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return -ENOMEM;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering *job = copy;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return 1;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringint manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(manager);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(unit);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_call_method(
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering manager->bus,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "/org/freedesktop/systemd1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "StopUnit",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering error,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering &reply,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "ss", unit, "fail");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (r < 0) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (sd_bus_error_has_name(error, BUS_ERROR_NO_SUCH_UNIT) ||
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_error_has_name(error, BUS_ERROR_LOAD_FAILED)) {
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering if (job)
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering *job = NULL;
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_error_free(error);
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering return 0;
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering }
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (job) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *j;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering char *copy;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(reply, "o", &j);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering copy = strdup(j);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!copy)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return -ENOMEM;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering *job = copy;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering return 1;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
de58a50e24a0d55e3bbcc77f8f6170a7322acf52Lennart Poetteringint manager_kill_unit(Manager *manager, const char *unit, int signo, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(manager);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(unit);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering return sd_bus_call_method(
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering manager->bus,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "/org/freedesktop/systemd1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "KillUnit",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering error,
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering NULL,
de58a50e24a0d55e3bbcc77f8f6170a7322acf52Lennart Poettering "ssi", unit, "all", signo);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint manager_unit_is_active(Manager *manager, const char *unit) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering _cleanup_free_ char *path = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *state;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering int r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(manager);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering assert(unit);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering path = unit_dbus_path_from_name(unit);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (!path)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return -ENOMEM;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_get_property(
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering manager->bus,
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering path,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "org.freedesktop.systemd1.Unit",
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "ActiveState",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering &error,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering &reply,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "s");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering if (r < 0) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (sd_bus_error_has_name(&error, SD_BUS_ERROR_NO_REPLY) ||
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_error_has_name(&error, SD_BUS_ERROR_DISCONNECTED))
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering return true;
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT) ||
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_error_has_name(&error, BUS_ERROR_LOAD_FAILED))
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering return false;
6797c324a653f119a3d7133122648aaa4878ddd6Lennart Poettering
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return r;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering }
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(reply, "s", &state);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0)
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering return -EINVAL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering return !STR_IN_SET(state, "inactive", "failed");
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering}
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringint manager_job_is_active(Manager *manager, const char *path) {
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
4afd3348c7506dd1d36305b7bcb9feb8952b9d6bLennart Poettering _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering int r;
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(manager);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert(path);
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_get_property(
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering manager->bus,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "org.freedesktop.systemd1",
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering path,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "org.freedesktop.systemd1.Job",
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "State",
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering &error,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering &reply,
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "s");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (r < 0) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (sd_bus_error_has_name(&error, SD_BUS_ERROR_NO_REPLY) ||
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_error_has_name(&error, SD_BUS_ERROR_DISCONNECTED))
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return true;
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT))
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return false;
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek return r;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering }
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering /* We don't actually care about the state really. The fact
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering * that we could read the job state is enough for us */
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering return true;
bd16acf35e13a19cd2ded0a0c2ef774a98f73808Zbigniew Jędrzejewski-Szmek}
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sieversint manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers Machine *mm;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers int r;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers assert(m);
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers assert(pid >= 1);
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers assert(machine);
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
4a0b58c4a30ecaa61202f845ed86f75b36370cd0Lennart Poettering mm = hashmap_get(m->machine_leaders, PID_TO_PTR(pid));
077c8c366b58222629ed953abf2faa74ebadb769Lennart Poettering if (!mm) {
077c8c366b58222629ed953abf2faa74ebadb769Lennart Poettering _cleanup_free_ char *unit = NULL;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
077c8c366b58222629ed953abf2faa74ebadb769Lennart Poettering r = cg_pid_get_unit(pid, &unit);
077c8c366b58222629ed953abf2faa74ebadb769Lennart Poettering if (r >= 0)
077c8c366b58222629ed953abf2faa74ebadb769Lennart Poettering mm = hashmap_get(m->machine_units, unit);
077c8c366b58222629ed953abf2faa74ebadb769Lennart Poettering }
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers if (!mm)
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers return 0;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers *machine = mm;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers return 1;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers}
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sieversint manager_add_machine(Manager *m, const char *name, Machine **_machine) {
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers Machine *machine;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers assert(m);
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers assert(name);
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers machine = hashmap_get(m->machines, name);
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers if (!machine) {
fbe550738d03b178bb004a1390e74115e904118aLennart Poettering machine = machine_new(m, _MACHINE_CLASS_INVALID, name);
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers if (!machine)
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers return -ENOMEM;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers }
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers if (_machine)
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers *_machine = machine;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers return 0;
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers}