-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <unistd.h>
#include "bus-locator.h"
#include "bus-polkit.h"
#include "cgroup-util.h"
+#include "discover-image.h"
#include "errno-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "image-dbus.h"
#include "io-util.h"
#include "machine-dbus.h"
-#include "machine-image.h"
#include "machine-pool.h"
#include "machined.h"
#include "missing_capability.h"
+#include "os-util.h"
#include "path-util.h"
#include "process-util.h"
#include "stdio-util.h"
sd_bus_error *error) {
_cleanup_close_ int fd = -1;
- uint64_t usage = (uint64_t) -1;
+ uint64_t usage = UINT64_MAX;
assert(bus);
assert(reply);
sd_bus_error *error) {
_cleanup_close_ int fd = -1;
- uint64_t size = (uint64_t) -1;
+ uint64_t size = UINT64_MAX;
assert(bus);
assert(reply);
if (r < 0)
return r;
- r = image_find(IMAGE_MACHINE, name, NULL);
+ r = image_find(IMAGE_MACHINE, name, NULL, NULL);
if (r == -ENOENT)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
if (r < 0)
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
Manager *m = userdata;
Machine *machine;
- Iterator i;
int r;
assert(message);
if (r < 0)
return sd_bus_error_set_errno(error, r);
- HASHMAP_FOREACH(machine, m->machines, i) {
+ HASHMAP_FOREACH(machine, m->machines) {
_cleanup_free_ char *p = NULL;
p = machine_bus_path(machine);
r = sd_bus_message_read(message, "s", &name);
if (r < 0)
return r;
- if (!machine_name_is_valid(name))
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name");
+ if (!hostname_is_valid(name, 0))
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine name");
r = sd_bus_message_read_array(message, 'y', &v, &n);
if (r < 0)
else if (n == 16)
memcpy(&id, v, n);
else
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine ID parameter");
r = sd_bus_message_read(message, "ssus", &service, &class, &leader, &root_directory);
if (r < 0)
return r;
if (read_network) {
- size_t i;
-
r = sd_bus_message_read_array(message, 'i', (const void**) &netif, &n_netif);
if (r < 0)
return r;
n_netif /= sizeof(int32_t);
- for (i = 0; i < n_netif; i++) {
+ for (size_t i = 0; i < n_netif; i++) {
if (netif[i] <= 0)
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid network interface index %i", netif[i]);
}
else {
c = machine_class_from_string(class);
if (c < 0)
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid machine class parameter");
}
if (leader == 1)
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid leader PID");
if (!isempty(root_directory) && !path_is_absolute(root_directory))
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Root directory must be empty or an absolute path");
if (leader == 0) {
_cleanup_(sd_bus_creds_unrefp) sd_bus_creds *creds = NULL;
_cleanup_hashmap_free_ Hashmap *images = NULL;
_unused_ Manager *m = userdata;
Image *image;
- Iterator i;
int r;
assert(message);
if (!images)
return -ENOMEM;
- r = image_discover(IMAGE_MACHINE, images);
+ r = image_discover(IMAGE_MACHINE, NULL, images);
if (r < 0)
return r;
if (r < 0)
return r;
- HASHMAP_FOREACH(image, images, i) {
+ HASHMAP_FOREACH(image, images) {
_cleanup_free_ char *p = NULL;
p = image_bus_path(image->name);
if (!image_name_is_valid(name))
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Image name '%s' is invalid.", name);
- r = image_find(IMAGE_MACHINE, name, &i);
+ r = image_find(IMAGE_MACHINE, name, NULL, &i);
if (r == -ENOENT)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_IMAGE, "No image '%s' known", name);
if (r < 0)
assert(message);
if (m->n_operations >= OPERATIONS_MAX)
- return sd_bus_error_setf(error, SD_BUS_ERROR_LIMITS_EXCEEDED, "Too many ongoing operations.");
+ return sd_bus_error_set(error, SD_BUS_ERROR_LIMITS_EXCEEDED, "Too many ongoing operations.");
r = sd_bus_message_read(message, "s", &mm);
if (r < 0)
else
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Unknown mode '%s'.", mm);
+ const char *details[] = {
+ "verb", "clean_pool",
+ "mode", mm,
+ NULL
+ };
+
r = bus_verify_polkit_async(
message,
CAP_SYS_ADMIN,
"org.freedesktop.machine1.manage-machines",
- NULL,
+ details,
false,
UID_INVALID,
&m->polkit_registry,
_cleanup_hashmap_free_ Hashmap *images = NULL;
bool success = true;
Image *image;
- Iterator i;
ssize_t l;
errno_pipe_fd[0] = safe_close(errno_pipe_fd[0]);
goto child_fail;
}
- r = image_discover(IMAGE_MACHINE, images);
+ r = image_discover(IMAGE_MACHINE, NULL, images);
if (r < 0)
goto child_fail;
goto child_fail;
}
- HASHMAP_FOREACH(image, images, i) {
+ HASHMAP_FOREACH(image, images) {
/* We can't remove vendor images (i.e. those in /usr) */
if (IMAGE_IS_VENDOR(image))
if (r < 0)
return r;
if (!FILE_SIZE_VALID_OR_INFINITY(limit))
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "New limit out of range");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "New limit out of range");
+
+ const char *details[] = {
+ "verb", "set_pool_limit",
+ NULL
+ };
r = bus_verify_polkit_async(
message,
CAP_SYS_ADMIN,
"org.freedesktop.machine1.manage-machines",
- NULL,
+ details,
false,
UID_INVALID,
&m->polkit_registry,
r = btrfs_subvol_set_subtree_quota_limit("/var/lib/machines", 0, limit);
if (r == -ENOTTY)
- return sd_bus_error_setf(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
+ return sd_bus_error_set(error, SD_BUS_ERROR_NOT_SUPPORTED, "Quota is only supported on btrfs.");
if (r < 0)
return sd_bus_error_set_errnof(error, r, "Failed to adjust quota limit: %m");
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
if (machine->class != MACHINE_CONTAINER)
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines.");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines.");
r = machine_translate_uid(machine, uid, &converted);
if (r == -ESRCH)
return sd_bus_error_setf(error, BUS_ERROR_NO_SUCH_MACHINE, "No machine '%s' known", name);
if (machine->class != MACHINE_CONTAINER)
- return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines.");
+ return sd_bus_error_set(error, SD_BUS_ERROR_INVALID_ARGS, "Not supported for non-container machines.");
r = machine_translate_gid(machine, gid, &converted);
if (r == -ESRCH)
int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error) {
Manager *m = userdata;
Machine *machine;
- Iterator i;
int b, r;
assert(message);
/* systemd finished reloading, let's recheck all our machines */
log_debug("System manager has been reloaded, rechecking machines...");
- HASHMAP_FOREACH(machine, m->machines, i)
+ HASHMAP_FOREACH(machine, m->machines)
machine_add_to_gc_queue(machine);
return 0;