Explorar el Código

feat(cli): add bind mount support for manifest in chroot

When using the manifest command with --root, bind mount the current working
directory to /usm-wd inside the chroot environment. This allows the manifest
command to access the original working directory files while running in the
chroot context.
clanker hace 10 meses
padre
commit
d8ba14cd50
Se han modificado 2 ficheros con 23 adiciones y 6 borrados
  1. 22 6
      src/cli/Cli.vala
  2. 1 0
      src/cli/meson.build

+ 22 - 6
src/cli/Cli.vala

@@ -21,21 +21,37 @@ public static int main(string[] args) {
                 printerr("Expected path after --root\n");
                 return 255;
             }
+
+            
+            if(command == "manifest") {
+                var wd = File.new_build_filename(root_path, "usm-wd");
+                if(!wd.query_exists()) {
+                    wd.make_directory();
+                }
+                Linux.umount(wd.get_path());
+                var res = Linux.mount(Environment.get_current_dir(), wd.get_path(), "", Linux.MountFlags.BIND);
+                if(res != 0) {
+                    printerr(@"Unable to bind mount working directory\n");
+                }
+            }
+
             var result = Posix.chroot(root_path);
             if(result != 0) {
                 printerr(@"Unable to chroot to \"$root_path\": $(Posix.strerror(result))\n");
                 return result;
             }
+
+            if(command == "manifest") {
+                Environment.set_current_dir("/usm-wd");
+            }
     
-            arguments.remove_at(root_flag_pos);
-            arguments.remove_at(root_flag_pos+1);
+            arguments.remove("--root");
+            arguments.remove(root_path);
         }
     
         if(command == "manifest") {
-            var m_args = new Invercargill.DataStructures.Vector<string>();
-            m_args.add_all(Invercargill.Wrap.array(args));
-            m_args.remove("manifest");
-            return manifest_main(m_args.to_array());
+            arguments.remove("manifest");
+            return manifest_main(arguments.to_array());
         }
         if(command == "info") {
             return info(args);

+ 1 - 0
src/cli/meson.build

@@ -7,5 +7,6 @@ sources += files('Scaffold.vala')
 
  deps = dependencies
  deps += usm_dep
+ deps += meson.get_compiler('vala').find_library('linux')
 
 executable('usm', sources, dependencies: deps, install: true)