File 0009-lio_node-listendpoints-crashes-if-config-dir-is-not-.patch of Package lio-utils

From 12da40834576d1f5dbf17710948d8cb10a810a2d Mon Sep 17 00:00:00 2001
From: Hannes Reinecke <hare@suse.de>
Date: Fri, 26 Oct 2012 12:46:41 +0200
Subject: lio_node: --listendpoints crashes if config dir is not present

The python script just blindly tries to do a readdir(), without
checking if the directory is actually present.

References: bnc#785058

Signed-off-by: Hannes Reinecke <hare@suse.de>
---
 lio-py/lio_node.py | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/lio-py/lio_node.py b/lio-py/lio_node.py
index 02e661b..78c7592 100755
--- a/lio-py/lio_node.py
+++ b/lio-py/lio_node.py
@@ -132,7 +132,9 @@ def __lio_target_del_iqn(option, opt_str, value, parser, delete_tpg_md):
 	iqn = iqn.lower();
 
 # Loop through LIO-Target IQN+TPGT list
-	tpg_root = os.listdir(lio_root + "/" + iqn); 
+	tpg_root = ""
+	if os.path.isdir(lio_root + "/" + iqn):
+		tpg_root = os.listdir(lio_root + "/" + iqn);
 	for tpgt_tmp in tpg_root:
 		if tpgt_tmp == "fabric_statistics":
 			continue
@@ -887,6 +889,8 @@ def lio_target_alua_show_tgptgp(option, opt_str, value, parser):
 	return
 
 def lio_target_list_endpoints(option, opt_str, value, parser):
+	if not os.path.isdir(lio_root):
+		return
 
 	iqn_root = os.listdir(lio_root)
 	
@@ -955,6 +959,9 @@ def lio_target_list_lunacls(option, opt_str, value, parser):
 	iqn = iqn.lower();
 	tpgt = str(value[1]);
 
+	if not os.path.isdir(lio_root):
+		return
+
 	iqn_root = os.listdir(lio_root)
 
 	nacl_root_dir = lio_root + "/" + iqn + "/tpgt_" + tpgt + "/acls"
@@ -1000,6 +1007,9 @@ def lio_target_list_nodeacls(option, opt_str, value, parser):
 	iqn = iqn.lower();
 	tpgt = str(value[1]);
 
+	if not os.path.isdir(lio_root):
+		return
+
 	iqn_root = os.listdir(lio_root)
 	
 	nacl_root_dir = lio_root + "/" + iqn + "/tpgt_" + tpgt + "/acls"
@@ -1027,6 +1037,9 @@ def lio_target_list_nps(option, opt_str, value, parser):
 	iqn = iqn.lower();
 	tpgt = str(value[1]);
 
+	if not os.path.isdir(lio_root):
+		return
+
 	np_root = os.listdir(lio_root + "/" + iqn + "/tpgt_" + tpgt + "/np")
 	for np in np_root:
 		print np
@@ -1034,6 +1047,8 @@ def lio_target_list_nps(option, opt_str, value, parser):
 	return
 
 def lio_target_list_targetnames(option, opt_str, value, parser):
+	if not os.path.isdir(lio_root):
+		return
 	
 	iqn_root = os.listdir(lio_root)
 	
-- 
1.8.1.4