Blob Blame History Raw
commit 7df5edbb427c79337bdd651c2bcdda8eb05f077b
Author: Lee Duncan <lduncan@suse.com>
Date:   Mon Sep 24 16:30:34 2018 -0700

    Fix incorrect sysfs logic for port and ip address.
    
    If "port" is available and "persistent_port" is not, then
    correctly use the one that is present for both values.
    Likewise for "address" and "persistent_address".
---
 libopeniscsiusr/session.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/libopeniscsiusr/session.c b/libopeniscsiusr/session.c
index f8c89c323afb..98601dcf807e 100644
--- a/libopeniscsiusr/session.c
+++ b/libopeniscsiusr/session.c
@@ -208,22 +208,20 @@ int iscsi_session_get(struct iscsi_context *ctx, uint32_t sid,
 	_sysfs_prop_get_i32(ctx, sysfs_con_dir_path, "port",
 			    &((*se)->port), -1, true);
 
-	if ((strcmp((*se)->address, "") == 0) &&
-	    (strcmp((*se)->persistent_address, "") != 0))
-		_strncpy((*se)->persistent_address, (*se)->address,
-			 sizeof((*se)->persistent_address) / sizeof(char));
-
 	if ((strcmp((*se)->address, "") != 0) &&
 	    (strcmp((*se)->persistent_address, "") == 0))
+		_strncpy((*se)->persistent_address, (*se)->address,
+			 sizeof((*se)->persistent_address) / sizeof(char));
+	else if ((strcmp((*se)->address, "") == 0) &&
+	    (strcmp((*se)->persistent_address, "") != 0))
 		_strncpy((*se)->address, (*se)->persistent_address,
 			 sizeof((*se)->address) / sizeof(char));
 
-	if (((*se)->persistent_port != -1) &&
-	    ((*se)->port == -1))
+	if (((*se)->persistent_port == -1) &&
+	    ((*se)->port != -1))
 		(*se)->persistent_port = (*se)->port;
-
-	if (((*se)->persistent_port != -1) &&
-	    ((*se)->port == -1))
+	else if (((*se)->persistent_port != -1) &&
+		 ((*se)->port == -1))
 		(*se)->port = (*se)->persistent_port;
 
 	_good(_iscsi_host_id_of_session(ctx, sid, &host_id), rc, out);