[Ocfs2-tools-commits] jlbec commits r1054 - branches/ocfs2-tools-1.0/o2cb_ctl

svn-commits at oss.oracle.com svn-commits at oss.oracle.com
Thu Aug 18 14:07:14 CDT 2005


Author: jlbec
Date: 2005-08-18 14:07:13 -0500 (Thu, 18 Aug 2005)
New Revision: 1054

Modified:
   branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_config.c
   branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_ctl.c
Log:

Merged of [1049:1051] from trunk:
	[1050] - Don't rewrite unchanged cluster.conf.
	[1051] - Write to a temporary and rename.



Modified: branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_config.c
===================================================================
--- branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_config.c	2005-08-18 16:51:09 UTC (rev 1053)
+++ branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_config.c	2005-08-18 19:07:13 UTC (rev 1054)
@@ -23,6 +23,7 @@
 
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/socket.h>
@@ -339,10 +340,86 @@
     return rc;
 }
 
+static gint write_file(const gchar *text, const gchar *filename)
+{
+    int rc, fd;
+    GString *template;
+    FILE *file;
+    size_t written, len;
 
+    rc = mkdir("/etc/ocfs2", 0755);
+    if (rc)
+    {
+        rc = -errno;
+        if (rc == -EEXIST)
+            rc = 0;
+        else
+            goto out;
+    }
+
+    rc = -ENOMEM;
+    template = g_string_new(filename);
+    if (!template)
+        goto out;
+
+    g_string_append(template, "XXXXXX");
+    fd = mkstemp(template->str);
+    rc = -errno;
+    if (fd < 0)
+        goto out_free;
+
+    file = fdopen(fd, "w");
+    if (!file)
+    {
+        rc = -errno;
+        close(fd);
+        goto out_unlink;
+    }
+
+    len = strlen(text);
+    written = fwrite(text, sizeof(char), len, file);
+    if (written != len)
+    {
+        if (feof(file))
+            rc = -EIO;
+        else if (ferror(file))
+            rc = -errno;
+        else
+            rc = -EIO;
+
+        fclose(file);
+        goto out_unlink;
+    }
+
+    fchmod(fd, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+    rc = fclose(file);
+    if (rc)
+    {
+        rc = -errno;
+        goto out_unlink;
+    }
+
+    rc = rename(template->str, filename);
+    if (rc)
+        rc = -errno;
+    
+out_unlink:
+    if (rc)
+        unlink(template->str);
+
+out_free:
+    g_string_free(template, TRUE);
+
+out:
+    return rc;
+}
+
+
 gint o2cb_config_store(O2CBConfig *config, const gchar *filename)
 {
     int rc;
+    char *text;
     JConfig *cf;
     O2CBCluster *cluster;
     GList *list;
@@ -358,24 +435,20 @@
         cluster = (O2CBCluster *)list->data;
         rc = o2cb_cluster_store(cf, cluster);
         if (rc)
-            break;
+            goto out;
 
         list = list->next;
     }
 
-    if (!rc)
-    {
-        rc = mkdir("/etc/ocfs2", 0755);
-        if (rc)
-        {
-            rc = -errno;
-            if (rc == -EEXIST)
-                rc = 0;
-        }
-        if (!rc && !j_config_dump_file(cf, filename))
-            rc = -EIO;
-    }
+    rc = -ENOMEM;
+    text = j_config_dump_memory(cf);
+    if (!text)
+        goto out;
 
+    rc = write_file(text, filename);
+    g_free(text);
+
+out:
     return rc;
 }  /* o2cb_config_store() */
 

Modified: branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_ctl.c
===================================================================
--- branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_ctl.c	2005-08-18 16:51:09 UTC (rev 1053)
+++ branches/ocfs2-tools-1.0/o2cb_ctl/o2cb_ctl.c	2005-08-18 19:07:13 UTC (rev 1054)
@@ -67,6 +67,7 @@
     GList *oc_objects;
     GList *oc_attrs;
     gboolean oc_compact_info;
+    gboolean oc_changed;
     gboolean oc_modify_running;
     O2CBConfig *oc_config;
 };
@@ -987,6 +988,7 @@
         rc = o2cb_cluster_set_name(cluster, val);
         if (rc)
             return rc;
+        ctxt->oc_changed = TRUE;
     }
     /* FIXME: Should perhaps store config before changing online info */
     if (attr_set(ctxt, "online"))
@@ -1083,7 +1085,8 @@
         goto out_error;
     }
 
-    rc = write_config(ctxt);
+    if (ctxt->oc_changed)
+        rc = write_config(ctxt);
 
 out_error:
     return rc;
@@ -1355,7 +1358,7 @@
 
 out_error:
     return rc;
-}  /* run_change() */
+}  /* run_create() */
 
 gint main(gint argc, gchar *argv[])
 {



More information about the Ocfs2-tools-commits mailing list