[ofa-general] [PATCH 3/4] opensm: option to specify config file

Sasha Khapyorsky sashak at voltaire.com
Tue Apr 8 18:10:24 PDT 2008


There is a new command line option '--config <file-name>' (or '-F').
When specified OpenSM will read initial configuration from this file
(the format is same as opensm.opts) and not from
/var/cache/opensm/opensm.opts file.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/opensm/main.c |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index da8047e..e39037d 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -130,6 +130,11 @@ static void show_usage(void)
 	printf("\n------- OpenSM - Usage and options ----------------------\n");
 	printf("Usage:   opensm [options]\n");
 	printf("Options:\n");
+	printf("-F <file-name>, --config <file-name>\n"
+	       "          The name of the OpenSM config file. It has a same format\n"
+	       "          as opensm.opts option cache file. When not specified\n"
+	       "          $OSM_CACHE_DIR/opensm.opts (or /var/cache/opensm/opensm.opts)\n"
+	       "          will be used (if exists).\n\n");
 	printf("-c\n"
 	       "--cache-options\n"
 	       "          Cache the given command line options into the file\n"
@@ -600,8 +605,9 @@ int main(int argc, char *argv[])
 	boolean_t cache_options = FALSE;
 	char *ignore_guids_file_name = NULL;
 	uint32_t val;
+	unsigned config_file_done = 0;
 	const char *const short_option =
-	    "i:f:ed:g:l:L:s:t:a:u:m:R:zM:U:S:P:Y:NBIQvVhorcyxp:n:q:k:C:";
+	    "F:i:f:ed:g:l:L:s:t:a:u:m:R:zM:U:S:P:Y:NBIQvVhorcyxp:n:q:k:C:";
 
 	/*
 	   In the array below, the 2nd parameter specifies the number
@@ -611,6 +617,7 @@ int main(int argc, char *argv[])
 	   2: optional
 	 */
 	const struct option long_option[] = {
+		{"config", 1, NULL, 'F'},
 		{"debug", 1, NULL, 'd'},
 		{"guid", 1, NULL, 'g'},
 		{"ignore_guids", 1, NULL, 'i'},
@@ -691,6 +698,18 @@ int main(int argc, char *argv[])
 		next_option = getopt_long_only(argc, argv, short_option,
 					       long_option, NULL);
 		switch (next_option) {
+		case 'F':
+			if (config_file_done)
+				break;
+			printf("Reloading config from `%s`:\n", optarg);
+			if (osm_subn_parse_conf_file(optarg, &opt)) {
+				printf("cannot parse config file.\n");
+				exit(1);
+			}
+			printf("Rescaning command line:\n");
+			config_file_done = 1;
+			optind = 0;
+			break;
 		case 'o':
 			/*
 			   Run once option.
-- 
1.5.4.1.122.gaa8d




More information about the general mailing list