]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
vmspawn: use indexed loop
authorYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 19 Jan 2026 14:14:26 +0000 (23:14 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 19 Jan 2026 17:26:35 +0000 (02:26 +0900)
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.

src/vmspawn/vmspawn.c

index 43817954a3d22b16afa218b54cca5f0dca48b5f4..b12e260fa4d1fd526fe14bf86701a7038864539d 100644 (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();
         }