[ofa-general] [PATCH][v2.0] dat: look for dat.conf in multiple locations, including sysconfdir

Arlin Davis arlin.r.davis at intel.com
Tue Oct 14 11:09:21 PDT 2008



Current static registration (SR) assumes DAT_OVERRIDE or /etc/dat.conf. 
Change SR to include sysconfdir. SR file access in the following order:

- DAT_OVERRIDE
- sysconfdir
- /etc

if DAT_OVERRIDE is set, assume administration override
and do not failover to other locations.

Signed-off-by: Arlin Davis <ardavis at ichips.intel.com>

---
 Makefile.am               |    4 ++--
 dat/udat/udat_sr_parser.c |   45 ++++++++++++++++++++++++++++++++-------------
 2 files changed, 34 insertions(+), 15 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 4929f83..bfc93f7 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -22,9 +22,9 @@ XPROGRAMS_SCM =
 endif
 
 if DEBUG
-AM_CFLAGS = -g -Wall -D_GNU_SOURCE -DDAPL_DBG
+AM_CFLAGS = -g -Wall -D_GNU_SOURCE -DDAPL_DBG -DDAT_CONF="\"$(sysconfdir)/dat.conf\""
 else
-AM_CFLAGS = -g -Wall -D_GNU_SOURCE
+AM_CFLAGS = -g -Wall -D_GNU_SOURCE -DDAT_CONF="\"$(sysconfdir)/dat.conf\""
 endif
 
 datlibdir = $(libdir)
diff --git a/dat/udat/udat_sr_parser.c b/dat/udat/udat_sr_parser.c
index 644e1c9..5b3f318 100644
--- a/dat/udat/udat_sr_parser.c
+++ b/dat/udat/udat_sr_parser.c
@@ -279,27 +279,44 @@ static DAT_SR_STACK_NODE 	*g_token_stack = NULL;
  * Function: dat_sr_load
  ***********************************************************************/
 
+
 DAT_RETURN
 dat_sr_load (void)
 {
     char 			*sr_path;
     DAT_OS_FILE 		*sr_file;
 
-    sr_path = dat_os_getenv (DAT_SR_CONF_ENV);
-    if ( sr_path == NULL )
-    {
-	sr_path = DAT_SR_CONF_DEFAULT;
-    }
+    sr_path = dat_os_getenv(DAT_SR_CONF_ENV);
 
-    dat_os_dbg_print (DAT_OS_DBG_TYPE_SR,
-		     "DAT Registry: static registry file <%s> \n", sr_path);
-
-    sr_file = dat_os_fopen (sr_path);
-    if ( sr_file == NULL )
+    /* environment override */
+    if ((sr_path != NULL) && ((sr_file = dat_os_fopen(sr_path)) == NULL)) 
     {
-	goto bail;
+        goto bail;
+    } 
+    
+    if (sr_path == NULL) { 
+
+#ifdef DAT_CONF
+	sr_path = DAT_CONF;
+#else
+     	sr_path = DAT_SR_CONF_DEFAULT;
+#endif
+        sr_file = dat_os_fopen (sr_path);
+        if (sr_file == NULL) 
+        {
+#ifdef DAT_CONF
+	    /* try default after sysconfdir fails */
+            sr_path = DAT_SR_CONF_DEFAULT;
+	    sr_file = dat_os_fopen(sr_path);
+	    if (sr_file == NULL) 
+#endif
+	        goto bail;
+        }
     }
 
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_GENERIC,
+		     "DAT Registry: using config file %s\n", sr_path);
+
     for (;;)
     {
 	if ( DAT_SUCCESS == dat_sr_parse_eof (sr_file) )
@@ -312,6 +329,8 @@ dat_sr_load (void)
 	}
 	else
 	{
+	    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
+			     "ERROR: parsing dat.conf\n");
             goto cleanup;
 	}
     }
@@ -324,8 +343,8 @@ dat_sr_load (void)
 cleanup:
     dat_os_fclose(sr_file);	
 bail:
-    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR, 
-		     "ERROR: unable to parse static registry file, dat.conf\n");
+    dat_os_dbg_print(DAT_OS_DBG_TYPE_ERROR,
+		     "DAT Registry: dat.conf, bad filename - %s\n", sr_path);
     return DAT_INTERNAL_ERROR;
 
 }
-- 
1.5.2.5





More information about the general mailing list