machined-dbus.c revision 65d73cf042ba7de11d254f5c4714f467db64b7c3
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering This file is part of systemd.
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering Copyright 2011 Lennart 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 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 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/>.
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering return sd_bus_message_append(reply, "s", "/var/lib/machines");
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 fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (btrfs_subvol_get_quota_fd(fd, &q) >= 0)
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (stat("/var/lib/machines.raw", &st) >= 0) {
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (usage == (uint64_t) -1 || st.st_blocks * 512ULL > usage)
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering return sd_bus_message_append(reply, "t", usage);
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 fd = open("/var/lib/machines", O_RDONLY|O_CLOEXEC|O_DIRECTORY);
160e3793adf2da2bd9ae3fe6b8881bb937e6e71bLennart Poettering if (btrfs_subvol_get_quota_fd(fd, &q) >= 0)
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 return sd_bus_message_append(reply, "t", size);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machines, name);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
df2d202e6ed4001a21c6512c244acad5d4706c87Lennart Poettering return sd_bus_reply_method_return(message, "o", p);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
c2ce6a3d82b717c4c1e6245ad8c6ce1173f502d0Lennart Poettering return sd_bus_reply_method_return(message, "o", p);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine_by_pid(sd_bus_message *message, void *userdata, sd_bus_error *error) {
4e724d9c5ab76c3f8327945317463ef706011082Lennart Poettering assert_cc(sizeof(pid_t) == sizeof(uint32_t));
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "u", &pid);
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = manager_get_machine_by_pid(m, pid, &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);
df2d202e6ed4001a21c6512c244acad5d4706c87Lennart Poettering return sd_bus_reply_method_return(message, "o", p);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_list_machines(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
df2d202e6ed4001a21c6512c244acad5d4706c87Lennart Poettering r = sd_bus_message_new_method_return(message, &reply);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_open_container(reply, 'a', "(ssso)");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering HASHMAP_FOREACH(machine, m->machines, i) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(reply, "(ssso)",
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering strempty(machine_class_to_string(machine->class)),
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_close_container(reply);
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;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering const void *v;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "s", &name);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read_array(message, 'y', &v, &n);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering else if (n == 16)
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "ssus", &service, &class, &leader, &root_directory);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering r = sd_bus_message_read_array(message, 'i', (const void**) &netif, &n_netif);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering for (i = 0; i < n_netif; i++) {
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid network interface index %i", netif[i]);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter");
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
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");
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering _cleanup_bus_creds_unref_ sd_bus_creds *creds = NULL;
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering r = sd_bus_query_sender_creds(message, SD_BUS_CREDS_PID, &creds);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering assert_cc(sizeof(uint32_t) == sizeof(pid_t));
5b12334d35eadf1f45cc3d631fd1a2e72ffaea0aLennart Poettering r = sd_bus_creds_get_pid(creds, (pid_t*) &leader);
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 r = manager_add_machine(manager, name, &m);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering m->root_directory = strdup(root_directory);
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering assert_cc(sizeof(int32_t) == sizeof(int));
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering m->netif = memdup(netif, sizeof(int32_t) * n_netif);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_create_machine_internal(sd_bus_message *message, bool read_network, void *userdata, sd_bus_error *error) {
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering r = method_create_or_register_machine(manager, message, read_network, &m, error);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = sd_bus_message_enter_container(message, 'a', "(sv)");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering m->create_message = sd_bus_message_ref(message);
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);
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);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_register_machine_internal(sd_bus_message *message, bool read_network, void *userdata, sd_bus_error *error) {
9b5ed6feda08290edce3bf916fa7362733dd30eaLennart Poettering r = method_create_or_register_machine(manager, message, read_network, &m, error);
89f7c8465cd1ab37347dd0c15920bce31e8225dfLennart Poettering r = cg_pid_get_unit(m->leader, &m->unit);
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 return sd_bus_reply_method_return(message, "o", p);
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);
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);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_terminate_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machines, name);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_terminate(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_kill_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_read(message, "s", &name);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machines, name);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_kill(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine_addresses(sd_bus_message *message, void *userdata, sd_bus_error *error) {
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering r = sd_bus_message_read(message, "s", &name);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering machine = hashmap_get(m->machines, name);
878cd7e95ca303f9851d227a22d2022bd49944b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_get_addresses(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_get_machine_os_release(sd_bus_message *message, void *userdata, sd_bus_error *error) {
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering r = sd_bus_message_read(message, "s", &name);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering machine = hashmap_get(m->machines, name);
717603e391b52983ca1fd218e7333a1b9dfc5c05Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_get_os_release(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_list_images(sd_bus_message *message, void *userdata, sd_bus_error *error) {
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering _cleanup_(image_hashmap_freep) Hashmap *images = NULL;
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r = sd_bus_message_new_method_return(message, &reply);
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering r = sd_bus_message_open_container(reply, 'a', "(ssbttto)");
b6b1849830f5e4a6065c3b0c993668e500c954d3Lennart Poettering r = sd_bus_message_append(reply, "(ssbttto)",
cd61c3bfd718fb398cc53ced906266a9297782c9Lennart Poettering r = sd_bus_message_close_container(reply);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_open_machine_pty(sd_bus_message *message, void *userdata, sd_bus_error *error) {
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering r = sd_bus_message_read(message, "s", &name);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering machine = hashmap_get(m->machines, name);
40205d706e1210763ff4c98a317556375bd04bcdLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_open_pty(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_open_machine_login(sd_bus_message *message, void *userdata, sd_bus_error *error) {
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering r = sd_bus_message_read(message, "s", &name);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering machine = hashmap_get(m->machines, name);
5f8cc96a0301c1177b11dd2e89370ef0b2ef577bLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_open_login(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_bind_mount_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering r = sd_bus_message_read(message, "s", &name);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering machine = hashmap_get(m->machines, name);
90adaa25e894a580930ef2c3e65ab8db8295515aLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_bind_mount(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_copy_machine(sd_bus_message *message, void *userdata, sd_bus_error *error) {
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering r = sd_bus_message_read(message, "s", &name);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering machine = hashmap_get(m->machines, name);
0370612e0522191f929e3feb7d4937fff3d421e2Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_machine_method_copy(message, machine, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_remove_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering r = sd_bus_message_read(message, "s", &name);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
086821244b5113f00a0ef993b78dc56aae2a8f6cLennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_remove(message, i, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_rename_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering r = sd_bus_message_read(message, "s", &old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", old_name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_rename(message, i, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_clone_image(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering r = sd_bus_message_read(message, "s", &old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", old_name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", old_name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_clone(message, i, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_mark_image_read_only(sd_bus_message *message, void *userdata, sd_bus_error *error) {
1ddb263d21099ae42195c2bc382bdf72a7f24f82Lennart Poettering r = sd_bus_message_read(message, "s", &name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
ebd93cb684806ac0f352139e69ac8f53eb49f5e4Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_mark_read_only(message, i, error);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_set_pool_limit(sd_bus_message *message, void *userdata, sd_bus_error *error) {
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering r = sd_bus_message_read(message, "t", &limit);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering "org.freedesktop.machine1.manage-machines",
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering /* Set up the machine directory if necessary */
4cee5eede280b7fd48c18a1942616c4ac896a554Lennart Poettering r = setup_machine_directory(limit, error);
26166c88e0b47b83972f32b5057ecbffe06bf904Lennart Poettering r = btrfs_resize_loopback("/var/lib/machines", limit, false);
26166c88e0b47b83972f32b5057ecbffe06bf904Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
26166c88e0b47b83972f32b5057ecbffe06bf904Lennart Poettering if (r < 0 && r != -ENODEV) /* ignore ENODEV, as that's what is returned if the file system is not on loopback */
efe0286285a7432f738fafae840fa4eda51c2986Lennart Poettering return sd_bus_error_set_errnof(error, r, "Failed to adjust loopback limit: %m");
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering r = btrfs_quota_limit("/var/lib/machines", limit);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_set_errnof(error, r, "Failed to adjust quota limit: %m");
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_reply_method_return(message, NULL);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringstatic int method_set_image_limit(sd_bus_message *message, void *userdata, sd_bus_error *error) {
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering r = sd_bus_message_read(message, "s", &name);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
d6ce17c7f02ed3facdb45f65f546e587c2f00950Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poettering return bus_image_method_set_limit(message, i, error);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_from_machine_user(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering const char *name, *p;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "su", &name, &uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering machine = hashmap_get(m->machines, name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering p = procfs_file_alloca(machine->leader, "uid_map");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering uid_t uid_base, uid_shift, uid_range, converted;
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 if (uid < uid_base || uid >= uid_base + uid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "u", (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "Machine '%s' has no matching user mappings.", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_to_machine_user(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "u", &uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
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 HASHMAP_FOREACH(machine, m->machines, i) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering char p[strlen("/proc//uid_map") + DECIMAL_STR_MAX(pid_t) + 1];
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering xsprintf(p, "/proc/" UID_FMT "/uid_map", machine->leader);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering log_warning_errno(errno, "Failed top open %s, ignoring,", p);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering uid_t uid_base, uid_shift, uid_range, converted;
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 if (uid < uid_shift || uid >= uid_shift + uid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering converted = (uid - uid_shift + uid_base);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid user ID " UID_FMT, uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "sou", machine->name, o, (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_USER_MAPPING, "No matching user mapping for " UID_FMT ".", uid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_from_machine_group(sd_bus_message *message, void *groupdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering const char *name, *p;
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "su", &name, &gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering machine = hashmap_get(m->machines, name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering p = procfs_file_alloca(machine->leader, "gid_map");
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering gid_t gid_base, gid_shift, gid_range, converted;
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 if (gid < gid_base || gid >= gid_base + gid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "u", (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "Machine '%s' has no matching group mappings.", name);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poetteringstatic int method_map_to_machine_group(sd_bus_message *message, void *groupdata, sd_bus_error *error) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering r = sd_bus_message_read(message, "u", &gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
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 HASHMAP_FOREACH(machine, m->machines, i) {
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering char p[strlen("/proc//gid_map") + DECIMAL_STR_MAX(pid_t) + 1];
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering xsprintf(p, "/proc/" GID_FMT "/gid_map", machine->leader);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering log_warning_errno(errno, "Failed top open %s, ignoring,", p);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering gid_t gid_base, gid_shift, gid_range, converted;
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 if (gid < gid_shift || gid >= gid_shift + gid_range)
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering converted = (gid - gid_shift + gid_base);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid group ID " GID_FMT, gid);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_reply_method_return(message, "sou", machine->name, o, (uint32_t) converted);
c01ff965b48bb9693dcd77cbc748b5d8676766b0Lennart Poettering return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_GROUP_MAPPING, "No matching group mapping for " GID_FMT ".", gid);
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),
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("MachineRemoved", "so", 0),
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "uoss", &id, &path, &unit, &result);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machine_units, unit);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering if (streq_ptr(path, machine->scope_job)) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine_send_create_reply(machine, NULL);
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering _cleanup_bus_error_free_ sd_bus_error e = SD_BUS_ERROR_NULL;
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering sd_bus_error_setf(&e, BUS_ERROR_JOB_FAILED, "Start job for unit %s failed with '%s'", unit, result);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
ebcf1f97de4f6b1580ae55eb56b1a3939fe6b602Lennart Poettering r = unit_name_from_dbus_path(path, &unit);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machine_units, unit);
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering r = sd_bus_message_read(message, "s", &interface);
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering if (streq(interface, "org.freedesktop.systemd1.Unit")) {
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering const struct bus_properties_map map[] = {
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering { "ActiveState", "s", NULL, offsetof(struct properties, active_state) },
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering { "SubState", "s", NULL, offsetof(struct properties, sub_state) },
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering r = bus_message_map_properties_changed(message, map, &properties);
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering else if (streq_ptr(properties.active_state, "inactive") ||
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering streq_ptr(properties.active_state, "failed") ||
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering streq_ptr(properties.sub_state, "auto-restart"))
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "so", &unit, &path);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering machine = hashmap_get(m->machine_units, unit);
190700621f95160d364f8ec1d3e360246c41ce75Lennart Poetteringint match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(message, "b", &b);
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering /* systemd finished reloading, let's recheck all our machines */
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering log_debug("System manager has been reloaded, rechecking machines...");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *m = NULL, *reply = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1.Manager",
151b9b9662a90455262ce575a8a8ae74bf4ff336Lennart Poettering "StartTransientUnit");
a658cafa98ab55ea948c29bc87eb3945d515fb41Lennart Poettering r = sd_bus_message_append(m, "ss", strempty(scope), "fail");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_open_container(m, 'a', "(sv)");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(m, "(sv)", "Slice", "s", slice);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(m, "(sv)", "Description", "s", description);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, pid);
a931ad47a8623163a29d898224d8a8c1177ffdafLennart Poettering r = sd_bus_message_append(m, "(sv)", "Delegate", "b", 1);
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_copy(m, more_properties, true);
86b8d289717bad2800342efca0a5023aa8374e9cLennart Poettering r = sd_bus_message_append(m, "a(sa(sv))", 0);
c49b30a23583ff39daaa26696bcab478d2fee0bbLennart Poettering r = sd_bus_call(manager->bus, m, 0, error, &reply);
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *j;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringint manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1.Manager",
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)) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering const char *j;
de58a50e24a0d55e3bbcc77f8f6170a7322acf52Lennart Poetteringint manager_kill_unit(Manager *manager, const char *unit, int signo, sd_bus_error *error) {
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poettering "org.freedesktop.systemd1.Manager",
1ee306e1248866617c96ed9f4263f375588ad838Lennart Poetteringint manager_unit_is_active(Manager *manager, const char *unit) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering "ActiveState",
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 if (sd_bus_error_has_name(&error, BUS_ERROR_NO_SUCH_UNIT) ||
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering sd_bus_error_has_name(&error, BUS_ERROR_LOAD_FAILED))
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering r = sd_bus_message_read(reply, "s", &state);
9b420b3cfb8b93daf50e4cdbc92b05f2209ef893Lennart Poettering return !STR_IN_SET(state, "inactive", "failed");
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poetteringint manager_job_is_active(Manager *manager, const char *path) {
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL;
c335068380fe8c9d843cdb2cf8a00f822cfabed3Lennart Poettering _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
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 if (sd_bus_error_has_name(&error, SD_BUS_ERROR_UNKNOWN_OBJECT))
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 */
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sieversint manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) {
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sievers mm = hashmap_get(m->machine_leaders, UINT_TO_PTR(pid));
ab49725fd8587ef2b90dd0a67b2c915bc772d089Kay Sieversint manager_add_machine(Manager *m, const char *name, Machine **_machine) {