]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: make rootfs relative to oci bundle path
authorArian van Putten <arian.vanputten@gmail.com>
Sun, 20 Dec 2020 22:11:57 +0000 (23:11 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Jan 2021 17:29:19 +0000 (18:29 +0100)
This is inline with the OCI runtime spec:

On POSIX platforms, path is either an absolute path or a relative path
to the bundle. For example, with a bundle at /to/bundle and a root
filesystem at /to/bundle/rootfs, the path value can be either
/to/bundle/rootfs or rootfs. The value SHOULD be the conventional
rootfs.
(https://github.com/opencontainers/runtime-spec/blob/master/config.md)

src/nspawn/nspawn-oci.c

index ccbae616cac0ed552f10c55d75c59d9ad62177a1..fe5768b02224ca5602a474fd8ebbb0a7f7edff19 100644 (file)
@@ -444,6 +444,8 @@ static int oci_process(const char *name, JsonVariant *v, JsonDispatchFlags flags
 }
 
 static int oci_root(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) {
+        Settings *s = userdata;
+        int r;
 
         static const JsonDispatch table[] = {
                 { "path",     JSON_VARIANT_STRING,  json_dispatch_string,  offsetof(Settings, root)      },
@@ -451,7 +453,21 @@ static int oci_root(const char *name, JsonVariant *v, JsonDispatchFlags flags, v
                 {}
         };
 
-        return json_dispatch(v, table, oci_unexpected, flags, userdata);
+        r = json_dispatch(v, table, oci_unexpected, flags, s);
+        if (r < 0)
+                return r;
+
+        if (s->root && !path_is_absolute(s->root)) {
+                char *joined;
+
+                joined = path_join(s->bundle, s->root);
+                if (!joined)
+                        return log_oom();
+
+                free_and_replace(s->root, joined);
+        }
+
+        return 0;
 }
 
 static int oci_hostname(const char *name, JsonVariant *v, JsonDispatchFlags flags, void *userdata) {