linux: libzutil: zfs_path_order: don't strdup ZPOOL_IMPORT_PATH
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> Closes #13223
This commit is contained in:
parent
8a2ed86001
commit
6322a77ce7
|
@ -264,36 +264,36 @@ zpool_default_search_paths(size_t *count)
|
||||||
* index in the passed 'order' variable, otherwise return an error.
|
* index in the passed 'order' variable, otherwise return an error.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
zfs_path_order(char *name, int *order)
|
zfs_path_order(const char *name, int *order)
|
||||||
{
|
{
|
||||||
int i, error = ENOENT;
|
const char *env = getenv("ZPOOL_IMPORT_PATH");
|
||||||
char *dir, *env, *envdup, *tmp = NULL;
|
|
||||||
|
|
||||||
env = getenv("ZPOOL_IMPORT_PATH");
|
|
||||||
if (env) {
|
if (env) {
|
||||||
envdup = strdup(env);
|
for (int i = 0; ; ++i) {
|
||||||
for (dir = strtok_r(envdup, ":", &tmp), i = 0;
|
env += strspn(env, ":");
|
||||||
dir != NULL;
|
size_t dirlen = strcspn(env, ":");
|
||||||
dir = strtok_r(NULL, ":", &tmp), i++) {
|
if (dirlen) {
|
||||||
if (strncmp(name, dir, strlen(dir)) == 0) {
|
if (strncmp(name, env, dirlen) == 0) {
|
||||||
*order = i;
|
*order = i;
|
||||||
error = 0;
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
env += dirlen;
|
||||||
|
} else
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(envdup);
|
|
||||||
} else {
|
} 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],
|
if (strncmp(name, zpool_default_import_path[i],
|
||||||
strlen(zpool_default_import_path[i])) == 0) {
|
strlen(zpool_default_import_path[i])) == 0) {
|
||||||
*order = i;
|
*order = i;
|
||||||
error = 0;
|
return (0);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return (error);
|
return (ENOENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue