[Ocfs2-tools-commits] jlbec commits r727 - trunk/o2cb_ctl

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Mon Mar 21 18:31:37 CST 2005


Author: jlbec
Date: 2005-03-21 18:31:35 -0600 (Mon, 21 Mar 2005)
New Revision: 727

Modified:
   trunk/o2cb_ctl/o2cb_config.c
   trunk/o2cb_ctl/o2cb_config.h
   trunk/o2cb_ctl/o2cb_ctl.c
Log:

o Don't break if /etc/ocfs2/cluster.conf isn't there.



Modified: trunk/o2cb_ctl/o2cb_config.c
===================================================================
--- trunk/o2cb_ctl/o2cb_config.c	2005-03-21 23:54:01 UTC (rev 726)
+++ trunk/o2cb_ctl/o2cb_config.c	2005-03-22 00:31:35 UTC (rev 727)
@@ -219,48 +219,61 @@
     return rc;
 }
 
-O2CBConfig *o2cb_config_load(const char *filename)
+gint o2cb_config_load(const gchar *filename, O2CBConfig **config)
 {
     gint rc;
     JConfigCtxt *ctxt;
     JConfig *cf;
-    O2CBConfig *config;
+    struct stat stat_buf;
 
-    ctxt = j_config_new_context();
-    if (!ctxt)
-        return NULL;
-    j_config_context_set_verbose(ctxt, FALSE);
+    rc = stat(filename, &stat_buf);
+    if (rc)
+    {
+        rc = -errno;
+        if (rc != -ENOENT)
+            return rc;
+        cf = j_config_parse_memory("", strlen(""));
+        if (!cf)
+            return -ENOMEM;
+    }
+    else
+    {
+        ctxt = j_config_new_context();
+        if (!ctxt)
+            return -ENOMEM;
+        j_config_context_set_verbose(ctxt, FALSE);
 
-    cf = j_config_parse_file_with_context(ctxt, filename);
-    if (j_config_context_get_error(ctxt))
-    {
-        if (cf)
+        cf = j_config_parse_file_with_context(ctxt, filename);
+        if (j_config_context_get_error(ctxt))
         {
-            j_config_free(cf);
-            cf = NULL;
+            if (cf)
+            {
+                j_config_free(cf);
+                cf = NULL;
+            }
         }
+        j_config_context_free(ctxt);
+
+        if (!cf)
+            return -EIO;
     }
-    j_config_context_free(ctxt);
 
-    if (!cf)
-        return NULL;
-
-    config = o2cb_config_initialize();
-    if (config)
+    *config = o2cb_config_initialize();
+    if (*config)
     {
-        rc = o2cb_config_fill(config, cf);
+        rc = o2cb_config_fill(*config, cf);
         if (rc)
         {
-            o2cb_config_free(config);
-            config = NULL;
+            o2cb_config_free(*config);
+            *config = NULL;
         }
         else
-            config->co_valid = TRUE;
+            (*config)->co_valid = TRUE;
     }
 
     j_config_free(cf);
 
-    return config;
+    return 0;
 }  /* o2cb_config_load() */
 
 static gint o2cb_node_store(JConfig *cf, O2CBCluster *cluster,
@@ -350,7 +363,14 @@
 
     if (!rc)
     {
-        if (!j_config_dump_file(cf, filename))
+        rc = mkdir("/etc/ocfs2", 0644);
+        if (rc)
+        {
+            rc = -errno;
+            if (rc == -EEXIST)
+                rc = 0;
+        }
+        if (!rc && !j_config_dump_file(cf, filename))
             rc = -EIO;
     }
 

Modified: trunk/o2cb_ctl/o2cb_config.h
===================================================================
--- trunk/o2cb_ctl/o2cb_config.h	2005-03-21 23:54:01 UTC (rev 726)
+++ trunk/o2cb_ctl/o2cb_config.h	2005-03-22 00:31:35 UTC (rev 727)
@@ -30,7 +30,7 @@
 typedef struct _O2CBNode	O2CBNode;
 
 O2CBConfig *o2cb_config_initialize(void);
-O2CBConfig *o2cb_config_load(const gchar *filename);
+gint o2cb_config_load(const gchar *filename, O2CBConfig **config);
 gint o2cb_config_store(O2CBConfig *config, const gchar *filename);
 void o2cb_config_free(O2CBConfig *config);
 

Modified: trunk/o2cb_ctl/o2cb_ctl.c
===================================================================
--- trunk/o2cb_ctl/o2cb_ctl.c	2005-03-21 23:54:01 UTC (rev 726)
+++ trunk/o2cb_ctl/o2cb_ctl.c	2005-03-22 00:31:35 UTC (rev 727)
@@ -477,8 +477,10 @@
 
 static gint load_config(O2CBContext *ctxt)
 {
-    ctxt->oc_config = o2cb_config_load(O2CB_CONFIG_FILE);
-    if (!ctxt->oc_config)
+    gint rc;
+
+    rc = o2cb_config_load(O2CB_CONFIG_FILE, &ctxt->oc_config);
+    if (rc)
     {
         fprintf(stderr,
                 PROGNAME ": Unable to load cluster configuration file \"%s\"\n",



More information about the Ocfs2-tools-commits mailing list