>From f1ea67d05410373c90441962e1f3005aa6212b05 Mon Sep 17 00:00:00 2001
From: Tim Meier <meier3@llnl.gov>
Date: Wed, 3 Oct 2007 14:05:03 -0700
Subject: [PATCH] opensm: osm_console.h replaced string literals with macro definitions

Several string constants are used to define and control the behavior
of the OSM Console.  This patch formalizes those constants, and uses
them in a consistent manner.

Signed-off-by: Tim Meier <meier3@llnl.gov>
---
 opensm/include/opensm/osm_console.h |    8 +++++++-
 opensm/opensm/main.c                |   14 +++++++-------
 opensm/opensm/osm_console.c         |    8 ++++----
 opensm/opensm/osm_subnet.c          |    6 +++---
 4 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/opensm/include/opensm/osm_console.h b/opensm/include/opensm/osm_console.h
index ceba3cc..33e41e7 100644
--- a/opensm/include/opensm/osm_console.h
+++ b/opensm/include/opensm/osm_console.h
@@ -38,9 +38,15 @@
 #include <opensm/osm_subnet.h>
 #include <opensm/osm_opensm.h>
 
+#define OSM_DISABLE_CONSOLE      "off"
+#define OSM_LOCAL_CONSOLE        "local"
+#define OSM_REMOTE_CONSOLE       "socket"
+#define OSM_LOOPBACK_CONSOLE     "loopback"
+#define OSM_CONSOLE_NAME         "OSM Console"
+
 #define OSM_COMMAND_LINE_LEN	 120
 #define OSM_COMMAND_PROMPT	 "$ "
-#define OSM_DEFAULT_CONSOLE      "off"
+#define OSM_DEFAULT_CONSOLE      OSM_DISABLE_CONSOLE
 #define OSM_DEFAULT_CONSOLE_PORT 10000
 #define OSM_DAEMON_NAME          "opensm"
 
diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index 0005531..0250551 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -733,11 +733,11 @@ int main(int argc, char *argv[])
 			/*
 			 * OpenSM interactive console
 			 */
-			if (strcmp(optarg, "off") == 0
-			    || strcmp(optarg, "local") == 0
+			if (strcmp(optarg, OSM_DISABLE_CONSOLE) == 0
+			    || strcmp(optarg, OSM_LOCAL_CONSOLE) == 0
 #ifdef ENABLE_OSM_CONSOLE_SOCKET
-			    || strcmp(optarg, "socket") == 0
-			    || strcmp(optarg, "loopback") == 0
+			    || strcmp(optarg, OSM_REMOTE_CONSOLE) == 0
+			    || strcmp(optarg, OSM_LOOPBACK_CONSOLE) == 0
 #endif
 			    )
 				opt.console = optarg;
@@ -1040,10 +1040,10 @@ int main(int argc, char *argv[])
 		   Sit here forever
 		 */
 		while (!osm_exit_flag) {
-			if (strcmp(opt.console, "local") == 0
+			if (strcmp(opt.console, OSM_LOCAL_CONSOLE) == 0
 #ifdef ENABLE_OSM_CONSOLE_SOCKET
-			    || strcmp(opt.console, "socket") == 0
-			    || strcmp(opt.console, "loopback") == 0
+			    || strcmp(opt.console, OSM_REMOTE_CONSOLE) == 0
+			    || strcmp(opt.console, OSM_LOOPBACK_CONSOLE) == 0
 #endif
 			    )
 				osm_console(&osm);
diff --git a/opensm/opensm/osm_console.c b/opensm/opensm/osm_console.c
index c2816d5..c6e02ab 100644
--- a/opensm/opensm/osm_console.c
+++ b/opensm/opensm/osm_console.c
@@ -927,7 +927,7 @@ void osm_console_init(osm_subn_opt_t * opt, osm_opensm_t * p_osm)
 {
 	p_osm->console.socket = -1;
 	/* set up the file descriptors for the console */
-	if (strcmp(opt->console, "local") == 0) {
+	if (strcmp(opt->console, OSM_LOCAL_CONSOLE) == 0) {
 		p_osm->console.in = stdin;
 		p_osm->console.out = stdout;
 		p_osm->console.in_fd = fileno(stdin);
@@ -935,8 +935,8 @@ void osm_console_init(osm_subn_opt_t * opt, osm_opensm_t * p_osm)
 
 		osm_console_prompt(p_osm->console.out);
 #ifdef ENABLE_OSM_CONSOLE_SOCKET
-	} else if (strcmp(opt->console, "socket") == 0
-		   || strcmp(opt->console, "loopback") == 0) {
+	} else if (strcmp(opt->console, OSM_REMOTE_CONSOLE) == 0
+		   || strcmp(opt->console, OSM_LOOPBACK_CONSOLE) == 0) {
 		struct sockaddr_in sin;
 		int optval = 1;
 
@@ -951,7 +951,7 @@ void osm_console_init(osm_subn_opt_t * opt, osm_opensm_t * p_osm)
 			   &optval, sizeof(optval));
 		sin.sin_family = AF_INET;
 		sin.sin_port = htons(opt->console_port);
-		if (strcmp(opt->console, "socket") == 0)
+		if (strcmp(opt->console, OSM_REMOTE_CONSOLE) == 0)
 			sin.sin_addr.s_addr = htonl(INADDR_ANY);
 		else
 			sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c
index 8475936..829c82b 100644
--- a/opensm/opensm/osm_subnet.c
+++ b/opensm/opensm/osm_subnet.c
@@ -936,10 +936,10 @@ static void subn_verify_conf_file(IN osm_subn_opt_t * const p_opts)
 		p_opts->force_link_speed = IB_PORT_LINK_SPEED_ENABLED_MASK;
 	}
 
-	if (strcmp(p_opts->console, "off")
-	    && strcmp(p_opts->console, "local")
+	if (strcmp(p_opts->console, OSM_DISABLE_CONSOLE)
+	    && strcmp(p_opts->console, OSM_LOCAL_CONSOLE)
 #ifdef ENABLE_OSM_CONSOLE_SOCKET
-	    && strcmp(p_opts->console, "socket")
+	    && strcmp(p_opts->console, OSM_REMOTE_CONSOLE)
 #endif
 	    ) {
 		sprintf(buff, " Invalid Cached Option Value:console = %s"
-- 
1.5.1.4

