vmspawn: use indexed loop

Previously, the index is obtained from the pointer offset. The
pointer offset is expressed by ptrdiff_t and may be different from
ssize_t.

Let's avoid to use FOREACH_ARRAY() but use an indexed loop.
This also renames `mount` to `m` to avoid conflict with `mount()`.

Fixes #40380.
This commit is contained in:
Yu Watanabe
2026-01-20 02:26:35 +09:00
parent 3d2284c7db
commit 8a5fb3627a
+8 -7
View File
@@ -2408,7 +2408,8 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
if (r < 0)
return log_oom();
FOREACH_ARRAY(mount, arg_runtime_mounts.mounts, arg_runtime_mounts.n_mounts) {
for (size_t j = 0; j < arg_runtime_mounts.n_mounts; j++) {
RuntimeMount *m = arg_runtime_mounts.mounts + j;
_cleanup_free_ char *listen_address = NULL;
_cleanup_(fork_notify_terminate) PidRef child = PIDREF_NULL;
@@ -2417,9 +2418,9 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
r = start_virtiofsd(
unit,
mount->source,
/* source_uid= */ mount->source_uid,
/* target_uid= */ mount->target_uid,
m->source,
/* source_uid= */ m->source_uid,
/* target_uid= */ m->target_uid,
/* uid_range= */ 1U,
runtime_dir,
sd_socket_activate,
@@ -2444,7 +2445,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
return log_oom();
_cleanup_free_ char *id = NULL;
if (asprintf(&id, "mnt%zi", mount - arg_runtime_mounts.mounts) < 0)
if (asprintf(&id, "mnt%zu", j) < 0)
return log_oom();
if (strv_extendf(&cmdline, "socket,id=%s,path=%s", id, escaped_listen_address) < 0)
@@ -2456,12 +2457,12 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
if (strv_extendf(&cmdline, "vhost-user-fs-pci,queue-size=1024,chardev=%1$s,tag=%1$s", id) < 0)
return log_oom();
_cleanup_free_ char *clean_target = xescape(mount->target, "\":");
_cleanup_free_ char *clean_target = xescape(m->target, "\":");
if (!clean_target)
return log_oom();
if (strv_extendf(&arg_kernel_cmdline_extra, "systemd.mount-extra=\"%s:%s:virtiofs:%s\"",
id, clean_target, mount->read_only ? "ro" : "rw") < 0)
id, clean_target, m->read_only ? "ro" : "rw") < 0)
return log_oom();
}