[PATCH fstools 1/2] libfstools: get rid of "extroot_prefix" global variable

Rafał Miłecki zajec5 at gmail.com
Tue Jan 4 14:17:29 PST 2022


From: Rafał Miłecki <rafal at milecki.pl>

Replace it with mount_extroot() argument. It's cleaner than a global
var.

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 libfstools/extroot.c    | 7 +------
 libfstools/libfstools.h | 3 +--
 libfstools/overlay.c    | 3 +--
 mount_root.c            | 3 +--
 4 files changed, 4 insertions(+), 12 deletions(-)

diff --git a/libfstools/extroot.c b/libfstools/extroot.c
index 418df94..7cc0b19 100644
--- a/libfstools/extroot.c
+++ b/libfstools/extroot.c
@@ -23,13 +23,11 @@
 
 #include "libfstools.h"
 
-char const *extroot_prefix = NULL;
-
 /*
  * This will execute "block extroot" and make use of mounted extroot or return
  * an error.
  */
-int mount_extroot(void)
+int mount_extroot(char const *extroot_prefix)
 {
 	char ldlib_path[32];
 	char block_path[32];
@@ -37,9 +35,6 @@ int mount_extroot(void)
 	struct stat s;
 	pid_t pid;
 
-	if (!extroot_prefix)
-		return -1;
-
 	/* try finding the library directory */
 	snprintf(ldlib_path, sizeof(ldlib_path), "%s/upper/lib", extroot_prefix);
 
diff --git a/libfstools/libfstools.h b/libfstools/libfstools.h
index 6aa0e41..340e2dc 100644
--- a/libfstools/libfstools.h
+++ b/libfstools/libfstools.h
@@ -39,8 +39,7 @@ enum fs_state {
 	__FS_STATE_LAST = FS_STATE_READY,
 };
 
-extern char const *extroot_prefix;
-extern int mount_extroot(void);
+extern int mount_extroot(char const *extroot_prefix);
 extern int mount_snapshot(struct volume *v);
 extern int mount_overlay(struct volume *v);
 
diff --git a/libfstools/overlay.c b/libfstools/overlay.c
index 352f0f2..26f0d6e 100644
--- a/libfstools/overlay.c
+++ b/libfstools/overlay.c
@@ -435,8 +435,7 @@ int mount_overlay(struct volume *v)
 	 * Check for extroot config in overlay (rootfs_data) and if present then
 	 * prefer it over rootfs_data.
 	 */
-	extroot_prefix = "/tmp/overlay";
-	if (!mount_extroot()) {
+	if (!mount_extroot("/tmp/overlay")) {
 		ULOG_INFO("switched to extroot\n");
 		return 0;
 	}
diff --git a/mount_root.c b/mount_root.c
index ca2c31c..d343909 100644
--- a/mount_root.c
+++ b/mount_root.c
@@ -45,8 +45,7 @@ start(int argc, char *argv[1])
 	}
 
 	/* Check for extroot config in rootfs before even trying rootfs_data */
-	extroot_prefix = "";
-	if (!mount_extroot()) {
+	if (!mount_extroot("")) {
 		ULOG_NOTE("switched to extroot\n");
 		return 0;
 	}
-- 
2.31.1




More information about the openwrt-devel mailing list