File multipath-tools-always-allocate-alias of Package multipath-tools

From 1532369e0269ddc8bbb295f3cc26f102b247bca0 Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Thu, 20 Nov 2008 08:50:10 +0100
Subject: [PATCH] Always allocate space for alias

We should always allocate memory for the alias, this makes freeing
up the string less error-prone.

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 libmultipath/devmapper.c |    8 ++++----
 libmultipath/propsel.c   |    6 +++---
 libmultipath/structs.c   |    4 +---
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c
index 92afae7..bc4f9db 100644
--- a/libmultipath/devmapper.c
+++ b/libmultipath/devmapper.c
@@ -765,7 +765,7 @@ dm_get_name(char *uuid, char *name)
 {
 	vector vec;
 	struct multipath *mpp;
-	int i;
+	int i, retval = 0;
 
 	vec = vector_alloc();
 
@@ -779,14 +779,14 @@ dm_get_name(char *uuid, char *name)
 
 	vector_foreach_slot(vec, mpp, i) {
 		if (!strcmp(uuid, mpp->wwid)) {
-			vector_free(vec);
 			strcpy(name, mpp->alias);
-			return 1;
+			retval = 1;
 		}
+		free_multipath(mpp, KEEP_PATHS);
 	}
 
 	vector_free(vec);
-	return 0;
+	return retval;
 }
 
 int
diff --git a/libmultipath/propsel.c b/libmultipath/propsel.c
index 43611ff..5a16182 100644
--- a/libmultipath/propsel.c
+++ b/libmultipath/propsel.c
@@ -159,7 +159,7 @@ extern int
 select_alias (struct multipath * mp)
 {
 	if (mp->mpe && mp->mpe->alias)
-		mp->alias = mp->mpe->alias;
+		mp->alias = strdup(mp->mpe->alias);
 	else {
 		mp->alias = NULL;
 		if (conf->user_friendly_names)
@@ -175,7 +175,7 @@ select_alias (struct multipath * mp)
 			}
 		}
 		if (mp->alias == NULL)
-			mp->alias = mp->wwid;
+			mp->alias = strdup(mp->wwid);
 	}
 
 	return 0;
@@ -365,6 +365,6 @@ select_pg_timeout(struct multipath *mp)
 		return 0;
 	}
 	mp->pg_timeout = PGTIMEOUT_UNDEF;
-	condlog(3, "pg_timeout = NONE (internal default)");
+	condlog(3, "%s: pg_timeout = NONE (internal default)", mp->alias);
 	return 0;
 }
diff --git a/libmultipath/structs.c b/libmultipath/structs.c
index bb0d9f7..d2bfc2d 100644
--- a/libmultipath/structs.c
+++ b/libmultipath/structs.c
@@ -161,9 +161,7 @@ free_multipath (struct multipath * mpp, int free_paths)
 
 	free_multipath_attributes(mpp);
 
-	if (mpp->alias &&
-	    (!mpp->mpe || (mpp->mpe && mpp->alias != mpp->mpe->alias)) &&
-	    (mpp->wwid && mpp->alias != mpp->wwid)) {
+	if (mpp->alias) {
 		FREE(mpp->alias);
 		mpp->alias = NULL;
 	}
-- 
1.5.3.2

openSUSE Build Service is sponsored by