[ofa-general] [PATCH 4/4 v2] opensm: use OSM_DEFAULT_CONFIG_FILE as config file
Sasha Khapyorsky
sashak at voltaire.com
Wed Apr 9 03:20:06 PDT 2008
Use configurable OSM_DEFAULT_CONFIG_FILE as default (when '-F' option is
not specified) OpenSM config file. Default value is
$sysconfdir/opensm/opensm.conf.
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
opensm/configure.in | 20 ++++++++++++++++++++
opensm/include/opensm/osm_base.h | 21 +++++++++++++++++++++
opensm/opensm/main.c | 25 +++++++++++--------------
3 files changed, 52 insertions(+), 14 deletions(-)
diff --git a/opensm/configure.in b/opensm/configure.in
index a527c91..858eb60 100644
--- a/opensm/configure.in
+++ b/opensm/configure.in
@@ -106,6 +106,26 @@ AC_DEFINE_UNQUOTED(OPENSM_CONFIG_DIR,
[Define OpenSM config directory])
AC_SUBST(OPENSM_CONFIG_DIR)
+dnl Check for a different default OpenSm config file
+OPENSM_CONFIG_FILE=opensm.conf
+AC_MSG_CHECKING(for --with-opensm-conf-file )
+AC_ARG_WITH(opensm-conf-file,
+ AC_HELP_STRING([--with-opensm-conf-file=file],
+ [define a default OpenSM config file (default opensm.conf)]),
+ [ case "$withval" in
+ no)
+ ;;
+ *)
+ OPENSM_CONFIG_FILE=$withval
+ ;;
+ esac ]
+)
+AC_MSG_RESULT(${OPENSM_CONFIG_FILE})
+AC_DEFINE_UNQUOTED(HAVE_DEFAULT_OPENSM_CONFIG_FILE,
+ ["$CONF_DIR/$OPENSM_CONFIG_FILE"],
+ [Define a default OpenSM config file])
+AC_SUBST(OPENSM_CONFIG_FILE)
+
dnl Check for a different default node name map file
NODENAMEMAPFILE=ib-node-name-map
AC_MSG_CHECKING(for --with-node-name-map )
diff --git a/opensm/include/opensm/osm_base.h b/opensm/include/opensm/osm_base.h
index 62d472e..289e49e 100644
--- a/opensm/include/opensm/osm_base.h
+++ b/opensm/include/opensm/osm_base.h
@@ -213,6 +213,27 @@ BEGIN_C_DECLS
#define OSM_DEFAULT_LOG_FILE "/var/log/opensm.log"
#endif
/***********/
+
+/****d* OpenSM: Base/OSM_DEFAULT_CONFIG_FILE
+* NAME
+* OSM_DEFAULT_CONFIG_FILE
+*
+* DESCRIPTION
+* Specifies the default OpenSM config file name
+*
+* SYNOPSIS
+*/
+#ifdef __WIN__
+#define OSM_DEFAULT_CONFIG_FILE strcat(GetOsmCachePath(), "opensm.conf")
+#elif defined(HAVE_DEFAULT_OPENSM_CONFIG_FILE)
+#define OSM_DEFAULT_CONFIG_FILE HAVE_DEFAULT_OPENSM_CONFIG_FILE
+#elif defined (OPENSM_CONFIG_DIR)
+#define OSM_DEFAULT_CONFIG_FILE OPENSM_CONFIG_DIR "/opensm.conf"
+#else
+#define OSM_DEFAULT_CONFIG_FILE "/etc/opensm/opensm.conf"
+#endif /* __WIN__ */
+/***********/
+
/****d* OpenSM: Base/OSM_DEFAULT_PARTITION_CONFIG_FILE
* NAME
* OSM_DEFAULT_PARTITION_CONFIG_FILE
diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index e39037d..0576dcc 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -133,8 +133,7 @@ static void show_usage(void)
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");
+ " " OSM_DEFAULT_CONFIG_FILE " will be used (if exists).\n\n");
printf("-c\n"
"--cache-options\n"
" Cache the given command line options into the file\n"
@@ -594,8 +593,6 @@ int main(int argc, char *argv[])
{
osm_opensm_t osm;
osm_subn_opt_t opt;
- char conf_file[256];
- char *cache_dir;
ib_net64_t sm_key = 0;
ib_api_status_t status;
uint32_t temp, dbg_lvl;
@@ -684,13 +681,7 @@ int main(int argc, char *argv[])
osm_subn_set_default_opt(&opt);
- /* try to open the options file from the cache dir */
- cache_dir = getenv("OSM_CACHE_DIR");
- if (!cache_dir || !(*cache_dir))
- cache_dir = OSM_DEFAULT_CACHE_DIR;
- snprintf(conf_file, sizeof(conf_file), "%s/opensm.opts", cache_dir);
-
- if (osm_subn_parse_conf_file(conf_file, &opt) < 0)
+ if (osm_subn_parse_conf_file(OSM_DEFAULT_CONFIG_FILE, &opt) < 0)
printf("\nosm_subn_parse_conf_file failed!\n");
printf("Command Line Arguments:\n");
@@ -1040,9 +1031,15 @@ int main(int argc, char *argv[])
if (opt.guid == 0 || cl_hton64(opt.guid) == CL_HTON64(INVALID_GUID))
opt.guid = get_port_guid(&osm, opt.guid);
- if (cache_options == TRUE
- && osm_subn_write_conf_file(conf_file, &opt))
- printf("\nosm_subn_write_conf_file failed!\n");
+ if (cache_options == TRUE) {
+ char conf_file[256];
+ char *cache_dir = getenv("OSM_CACHE_DIR");
+ if (!cache_dir || !(*cache_dir))
+ cache_dir = OSM_DEFAULT_CACHE_DIR;
+ snprintf(conf_file, sizeof(conf_file), "%s/opensm.opts", cache_dir);
+ if (osm_subn_write_conf_file(conf_file, &opt))
+ printf("\nosm_subn_write_conf_file failed!\n");
+ }
status = osm_opensm_bind(&osm, opt.guid);
if (status != IB_SUCCESS) {
--
1.5.4.1.122.gaa8d
More information about the general
mailing list