aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorнаб <[email protected]>2022-03-16 02:06:27 +0100
committerBrian Behlendorf <[email protected]>2022-03-23 08:55:38 -0700
commit6322a77ce7e661facac3335721dde9eff9ceb634 (patch)
treedd0d67124db132aced94926574379433aff50fce /lib
parent8a2ed86001583280b4d84d1f37919ea8a34ddb79 (diff)
linux: libzutil: zfs_path_order: don't strdup ZPOOL_IMPORT_PATH
Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ahelenia Ziemiańska <[email protected]> Closes #13223
Diffstat (limited to 'lib')
-rw-r--r--lib/libzutil/os/linux/zutil_import_os.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/lib/libzutil/os/linux/zutil_import_os.c b/lib/libzutil/os/linux/zutil_import_os.c
index 0493e897b..6b825fcd7 100644
--- a/lib/libzutil/os/linux/zutil_import_os.c
+++ b/lib/libzutil/os/linux/zutil_import_os.c
@@ -264,36 +264,36 @@ zpool_default_search_paths(size_t *count)
* index in the passed 'order' variable, otherwise return an error.
*/
static int
-zfs_path_order(char *name, int *order)
+zfs_path_order(const char *name, int *order)
{
- int i, error = ENOENT;
- char *dir, *env, *envdup, *tmp = NULL;
+ const char *env = getenv("ZPOOL_IMPORT_PATH");
- env = getenv("ZPOOL_IMPORT_PATH");
if (env) {
- envdup = strdup(env);
- for (dir = strtok_r(envdup, ":", &tmp), i = 0;
- dir != NULL;
- dir = strtok_r(NULL, ":", &tmp), i++) {
- if (strncmp(name, dir, strlen(dir)) == 0) {
- *order = i;
- error = 0;
+ for (int i = 0; ; ++i) {
+ env += strspn(env, ":");
+ size_t dirlen = strcspn(env, ":");
+ if (dirlen) {
+ if (strncmp(name, env, dirlen) == 0) {
+ *order = i;
+ return (0);
+ }
+
+ env += dirlen;
+ } else
break;
- }
}
- free(envdup);
} else {
- for (i = 0; i < ARRAY_SIZE(zpool_default_import_path); i++) {
+ for (int i = 0; i < ARRAY_SIZE(zpool_default_import_path);
+ ++i) {
if (strncmp(name, zpool_default_import_path[i],
strlen(zpool_default_import_path[i])) == 0) {
*order = i;
- error = 0;
- break;
+ return (0);
}
}
}
- return (error);
+ return (ENOENT);
}
/*