diff options
Diffstat (limited to 'image')
-rw-r--r-- | image/backends/README.rst | 5 | ||||
-rw-r--r-- | image/backends/basic.cc | 10 | ||||
-rw-r--r-- | image/backends/basic.hh | 4 | ||||
-rw-r--r-- | image/backends/tar.cc | 6 | ||||
-rw-r--r-- | image/creator.cc | 5 |
5 files changed, 26 insertions, 4 deletions
diff --git a/image/backends/README.rst b/image/backends/README.rst index e2a91a7..5eb9036 100644 --- a/image/backends/README.rst +++ b/image/backends/README.rst @@ -56,6 +56,11 @@ name. You may also implement ``prepare()``, which is called before create, and ``finalise()``, which is called after. Default no-op implementations are provided for you in BasicBackend. +You may also implement ``cleanup()``, which is called after ``finalise()`` +or when an error occurs during one of the other phases. The default +implementation in BasicBackend unmounts the target 'dev', 'proc', and 'sys' +filesystems from ir_dir/target. + Repository Layout diff --git a/image/backends/basic.cc b/image/backends/basic.cc index 0aa1afa..dc4d9ea 100644 --- a/image/backends/basic.cc +++ b/image/backends/basic.cc @@ -12,6 +12,9 @@ #include "basic.hh" +#include <sys/mount.h> /* umount */ +#include "hscript/util.hh" /* run_command */ + namespace Horizon { namespace Image { @@ -38,5 +41,12 @@ int BasicBackend::finalise() { return 0; } +void BasicBackend::cleanup() { + /* The default implementation unmounts /dev, /proc, and /sys from the target. */ + run_command("umount", {"-R", (ir_dir + "/target/sys")}); + ::umount((ir_dir + "/target/proc").c_str()); + run_command("umount", {"-R", (ir_dir + "/target/dev")}); +} + } } diff --git a/image/backends/basic.hh b/image/backends/basic.hh index ff92ec8..0babfd3 100644 --- a/image/backends/basic.hh +++ b/image/backends/basic.hh @@ -50,6 +50,10 @@ public: */ virtual int finalise(); + /*! Clean up the target mounts. + */ + virtual void cleanup(); + /*! The intermediate directory which contains the sysroot the image * should contain. */ const string ir_dir; diff --git a/image/backends/tar.cc b/image/backends/tar.cc index b05f4a5..a110acb 100644 --- a/image/backends/tar.cc +++ b/image/backends/tar.cc @@ -175,6 +175,12 @@ ret: return 0; } + + void cleanup() override { + /* We call umount during creation to avoid including the dirs in the tarball, + * so we don't need the default cleanup to run. */ + return; + } }; __attribute__((constructor(400))) diff --git a/image/creator.cc b/image/creator.cc index ce2c537..c45c50f 100644 --- a/image/creator.cc +++ b/image/creator.cc @@ -257,10 +257,7 @@ int main(int argc, char *argv[]) { trouble: /* delete the Script and exit */ /* ensure that our target mounts are unmounted */ - run_command("umount", {"-R", (ir_dir + "/target/sys")}); - ::umount((ir_dir + "/target/proc").c_str()); - run_command("umount", {"-R", (ir_dir + "/target/dev")}); - + backend->cleanup(); delete my_script; early_trouble: /* no script yet */ delete backend; |