From: "Richard W.M. Jones" <rjones(a)redhat.com>
This is also called implicitly from internal_autosync, ensuring that
exit won't fail because of an open handle.
libguestfs: error: internal_autosync: umount: /sysroot: umount: /sysroot: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
Cherry picked from commit ce6e5738fc4ca9533e73cfe6b5fe3db872b7ec9d
and modified to remove references to the journal.
(cherry picked from commit 4d5da455cca1e70810af868c523a872c746f45ec)
---
daemon/augeas.c | 4 ++--
daemon/daemon.h | 4 ++++
daemon/hivex.c | 4 ++--
daemon/mount.c | 7 +++++++
4 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index 54830c7..b2d1eb2 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -39,8 +39,8 @@
static augeas *aug = NULL;
/* Clean up the augeas handle on daemon exit. */
-static void aug_finalize (void) __attribute__((destructor));
-static void
+void aug_finalize (void) __attribute__((destructor));
+void
aug_finalize (void)
{
if (aug) {
diff --git a/daemon/daemon.h b/daemon/daemon.h
index 096a3af..8ca0593 100644
--- a/daemon/daemon.h
+++ b/daemon/daemon.h
@@ -198,6 +198,10 @@ extern void copy_lvm (void);
/*-- in zero.c --*/
extern void wipe_device_before_mkfs (const char *device);
+/*-- in augeas.c, hivex.c --*/
+extern void aug_finalize (void);
+extern void hivex_finalize (void);
+
/*-- in proto.c --*/
extern void main_loop (int sock) __attribute__((noreturn));
diff --git a/daemon/hivex.c b/daemon/hivex.c
index 92e8fc3..ce6164e 100644
--- a/daemon/hivex.c
+++ b/daemon/hivex.c
@@ -47,8 +47,8 @@ optgroup_hivex_available (void)
static hive_h *h = NULL;
/* Clean up the hivex handle on daemon exit. */
-static void hivex_finalize (void) __attribute__((destructor));
-static void
+void hivex_finalize (void) __attribute__((destructor));
+void
hivex_finalize (void)
{
if (h) {
diff --git a/daemon/mount.c b/daemon/mount.c
index af92834..2f4674d 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -343,6 +343,13 @@ do_umount_all (void)
size_t i;
int r;
+ /* This is called from internal_autosync and generally as a cleanup
+ * function, and since the umount will definitely fail if any
+ * handles are open, we may as well close them.
+ */
+ aug_finalize ();
+ hivex_finalize ();
+
/* NB: Eventually we should aim to parse /proc/self/mountinfo, but
* that requires custom parsing code.
*/
--
1.8.3.1