Replace CreateDirectory with SHCreateDirectoryEx, so that
intermediate directories in the database path are created.

This fixes an issue where opensm fails to start unless the
path has been created beforehand.

Signed-off-by: Sean Hefty <[email protected]>
---
change from v1: used common error handling

 opensm/osm_db_files.c |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)
 mode change 100644 => 100755 opensm/osm_db_files.c

diff --git a/opensm/osm_db_files.c b/opensm/osm_db_files.c
index 18ac830..3182da4
--- a/opensm/osm_db_files.c
+++ b/opensm/osm_db_files.c
@@ -169,19 +169,19 @@ int osm_db_init(IN osm_db_t * p_db, IN osm_log_t * p_log)
        /* Create the directory if it doesn't exist */
        /* There is a difference in creating directory between windows and 
linux */
 #ifdef __WIN__
-       /* Check if the directory exists. If not - create it. */
-       CreateDirectory(p_db_imp->db_dir_name, NULL);
+       {
+               int ret;
+
+               ret = SHCreateDirectoryEx(NULL, p_db_imp->db_dir_name, NULL);
+               if (ret != ERROR_SUCCESS && ret != ERROR_ALREADY_EXISTS &&
+                       ret != ERROR_FILE_EXISTS)
+                       goto err;
+       }
 #else                          /* __WIN__ */
        /* make sure the directory exists */
        if (lstat(p_db_imp->db_dir_name, &dstat)) {
-               if (mkdir(p_db_imp->db_dir_name, 0755)) {
-                       OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6101: "
-                               "Failed to create the db directory:%s\n",
-                               p_db_imp->db_dir_name);
-                       free(p_db_imp);
-                       OSM_LOG_EXIT(p_log);
-                       return 1;
-               }
+               if (mkdir(p_db_imp->db_dir_name, 0755))
+                       goto err;
        }
 #endif
 
@@ -193,6 +193,14 @@ int osm_db_init(IN osm_db_t * p_db, IN osm_log_t * p_log)
        OSM_LOG_EXIT(p_log);
 
        return 0;
+
+err:
+       OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 6101: "
+               "Failed to create the db directory:%s\n",
+               p_db_imp->db_dir_name);
+       free(p_db_imp);
+       OSM_LOG_EXIT(p_log);
+       return 1;
 }
 
 osm_db_domain_t *osm_db_domain_init(IN osm_db_t * p_db, IN char *domain_name)


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

Reply via email to