Functions osm_subn_parse_conf_file() and osm_subn_write_conf_file() will
get config file name as parameter. Also it is stored as part of config
options and used by osm_subn_rescan_conf_files().

Signed-off-by: Sasha Khapyorsky <[EMAIL PROTECTED]>
---
 opensm/include/opensm/osm_subnet.h |   10 +++++-
 opensm/opensm/main.c               |   13 +++++++-
 opensm/opensm/osm_subnet.c         |   53 ++++++++---------------------------
 3 files changed, 31 insertions(+), 45 deletions(-)

diff --git a/opensm/include/opensm/osm_subnet.h 
b/opensm/include/opensm/osm_subnet.h
index b1dd659..98afbd4 100644
--- a/opensm/include/opensm/osm_subnet.h
+++ b/opensm/include/opensm/osm_subnet.h
@@ -205,6 +205,7 @@ typedef struct _osm_qos_options_t {
 * SYNOPSIS
 */
 typedef struct _osm_subn_opt {
+       char *config_file;
        ib_net64_t guid;
        ib_net64_t m_key;
        ib_net64_t sm_key;
@@ -289,6 +290,9 @@ typedef struct _osm_subn_opt {
 /*
 * FIELDS
 *
+*      config_file
+*              The name of the config file.
+*
 *      guid
 *              The port guid that the SM is binding to.
 *
@@ -1057,7 +1061,8 @@ void osm_subn_set_default_opt(IN osm_subn_opt_t * const 
p_opt);
 *
 * SYNOPSIS
 */
-ib_api_status_t osm_subn_parse_conf_file(IN osm_subn_opt_t * const p_opt);
+ib_api_status_t osm_subn_parse_conf_file(char *conf_file,
+                                        IN osm_subn_opt_t * const p_opt);
 /*
 * PARAMETERS
 *
@@ -1109,7 +1114,8 @@ ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t 
* const p_subn);
 *
 * SYNOPSIS
 */
-ib_api_status_t osm_subn_write_conf_file(IN osm_subn_opt_t * const p_opt);
+ib_api_status_t osm_subn_write_conf_file(char *file_name,
+                                        IN osm_subn_opt_t * const p_opt);
 /*
 * PARAMETERS
 *
diff --git a/opensm/opensm/main.c b/opensm/opensm/main.c
index fb41d50..91ee143 100644
--- a/opensm/opensm/main.c
+++ b/opensm/opensm/main.c
@@ -589,6 +589,8 @@ 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;
@@ -674,7 +676,14 @@ int main(int argc, char *argv[])
        printf("%s\n", OSM_VERSION);
 
        osm_subn_set_default_opt(&opt);
-       if (osm_subn_parse_conf_file(&opt) != IB_SUCCESS)
+
+       /* 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) != IB_SUCCESS)
                printf("\nosm_subn_parse_conf_file failed!\n");
 
        printf("Command Line Arguments:\n");
@@ -1013,7 +1022,7 @@ int main(int argc, char *argv[])
                opt.guid = get_port_guid(&osm, opt.guid);
 
        if (cache_options == TRUE
-           && osm_subn_write_conf_file(&opt) != IB_SUCCESS)
+           && osm_subn_write_conf_file(conf_file, &opt) != IB_SUCCESS)
                printf("\nosm_subn_write_conf_file failed!\n");
 
        status = osm_opensm_bind(&osm, opt.guid);
diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c
index 47d735f..f3f4c52 100644
--- a/opensm/opensm/osm_subnet.c
+++ b/opensm/opensm/osm_subnet.c
@@ -71,14 +71,6 @@
 #include <opensm/osm_event_plugin.h>
 #include <opensm/osm_qos_policy.h>
 
-#if defined(PATH_MAX)
-#define OSM_PATH_MAX   (PATH_MAX + 1)
-#elif defined (_POSIX_PATH_MAX)
-#define OSM_PATH_MAX   (_POSIX_PATH_MAX + 1)
-#else
-#define OSM_PATH_MAX   256
-#endif
-
 /**********************************************************************
  **********************************************************************/
 void osm_subn_construct(IN osm_subn_t * const p_subn)
@@ -787,26 +779,20 @@ osm_parse_prefix_routes_file(IN osm_subn_t * const p_subn)
  **********************************************************************/
 ib_api_status_t osm_subn_rescan_conf_files(IN osm_subn_t * const p_subn)
 {
-       char *p_cache_dir = getenv("OSM_CACHE_DIR");
-       char file_name[OSM_PATH_MAX];
        FILE *opts_file;
        char line[1024];
        char *p_key, *p_val, *p_last;
 
-       /* try to open the options file from the cache dir */
-       if (!p_cache_dir || !(*p_cache_dir))
-               p_cache_dir = OSM_DEFAULT_CACHE_DIR;
+       if (!p_subn->opt.config_file)
+               return 0;
 
-       strcpy(file_name, p_cache_dir);
-       strcat(file_name, "/opensm.opts");
-
-       opts_file = fopen(file_name, "r");
+       opts_file = fopen(p_subn->opt.config_file, "r");
        if (!opts_file) {
                if (errno == ENOENT)
                        return IB_SUCCESS;
                OSM_LOG(&p_subn->p_osm->log, OSM_LOG_ERROR,
                        "cannot open file \'%s\': %s\n",
-                       file_name, strerror(errno));
+                       p_subn->opt.config_file, strerror(errno));
                return IB_ERROR;
        }
 
@@ -1142,21 +1128,13 @@ static void subn_verify_conf_file(IN osm_subn_opt_t * 
const p_opts)
 
 /**********************************************************************
  **********************************************************************/
-ib_api_status_t osm_subn_parse_conf_file(IN osm_subn_opt_t * const p_opts)
+ib_api_status_t osm_subn_parse_conf_file(char *file_name,
+                                        IN osm_subn_opt_t * const p_opts)
 {
-       char *p_cache_dir = getenv("OSM_CACHE_DIR");
-       char file_name[OSM_PATH_MAX];
-       FILE *opts_file;
        char line[1024];
+       FILE *opts_file;
        char *p_key, *p_val, *p_last;
 
-       /* try to open the options file from the cache dir */
-       if (!p_cache_dir || !(*p_cache_dir))
-               p_cache_dir = OSM_DEFAULT_CACHE_DIR;
-
-       strcpy(file_name, p_cache_dir);
-       strcat(file_name, "/opensm.opts");
-
        opts_file = fopen(file_name, "r");
        if (!opts_file) {
                if (errno == ENOENT)
@@ -1166,10 +1144,11 @@ ib_api_status_t osm_subn_parse_conf_file(IN 
osm_subn_opt_t * const p_opts)
                return IB_ERROR;
        }
 
-       sprintf(line, " Reading Cached Option File: %s\n", file_name);
-       printf(line);
+       printf(" Reading Cached Option File: %s\n", file_name);
        cl_log_event("OpenSM", CL_LOG_INFO, line, NULL, 0);
 
+       p_opts->config_file = file_name;
+
        while (fgets(line, 1023, opts_file) != NULL) {
                /* get the first token */
                p_key = strtok_r(line, " \t\n", &p_last);
@@ -1405,19 +1384,11 @@ ib_api_status_t osm_subn_parse_conf_file(IN 
osm_subn_opt_t * const p_opts)
 
 /**********************************************************************
  **********************************************************************/
-ib_api_status_t osm_subn_write_conf_file(IN osm_subn_opt_t * const p_opts)
+ib_api_status_t osm_subn_write_conf_file(char *file_name,
+                                        IN osm_subn_opt_t * const p_opts)
 {
-       char *p_cache_dir = getenv("OSM_CACHE_DIR");
-       char file_name[OSM_PATH_MAX];
        FILE *opts_file;
 
-       /* try to open the options file from the cache dir */
-       if (!p_cache_dir || !(*p_cache_dir))
-               p_cache_dir = OSM_DEFAULT_CACHE_DIR;
-
-       strcpy(file_name, p_cache_dir);
-       strcat(file_name, "/opensm.opts");
-
        opts_file = fopen(file_name, "w");
        if (!opts_file) {
                printf("cannot open file \'%s\' for writing: %s\n",
-- 
1.5.4.1.122.gaa8d

_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to