summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2024-05-22 11:23:59 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2024-05-22 11:23:59 -0500
commit75db43b7fc8a049090a6f77a31a658a718268ac7 (patch)
tree90cf93b34bae5505713e143a8329fcfa29363b1c
parent4f8a406b0a6bb3669e63dce5074fdd9b15be3d9b (diff)
downloadhorizon-75db43b7fc8a049090a6f77a31a658a718268ac7.tar.gz
horizon-75db43b7fc8a049090a6f77a31a658a718268ac7.tar.bz2
horizon-75db43b7fc8a049090a6f77a31a658a718268ac7.tar.xz
horizon-75db43b7fc8a049090a6f77a31a658a718268ac7.zip
image: backends: Implement a cleanup() method
This allows backends to implement their own handling of target umounts. Notably, the tar backend already umounts the target /dev /proc /sys, so our hardcoded cleanup in the Creator caused unnecessary and confusing error output when umount was run a second time. Closes: #345
-rw-r--r--image/backends/README.rst5
-rw-r--r--image/backends/basic.cc10
-rw-r--r--image/backends/basic.hh4
-rw-r--r--image/backends/tar.cc6
-rw-r--r--image/creator.cc5
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;