[Reconnoiter-devel] [reconnoiter commit] r843 - trunk/src

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Wed Sep 16 01:01:19 EDT 2009


Author: jesus
Date: 2009-09-16 01:01:19 -0400 (Wed, 16 Sep 2009)
New Revision: 843

Modified:
   trunk/src/noit_check_rest.c
   trunk/src/noit_conf.c
   trunk/src/noit_conf.h
   trunk/src/noit_conf_checks.c
Log:
auto-save on REST add, refs #171

Modified: trunk/src/noit_check_rest.c
===================================================================
--- trunk/src/noit_check_rest.c	2009-09-16 04:19:24 UTC (rev 842)
+++ trunk/src/noit_check_rest.c	2009-09-16 05:01:19 UTC (rev 843)
@@ -481,7 +481,6 @@
     uuid_conf = (char *)xmlGetProp(node, (xmlChar *)"uuid");
     if(!uuid_conf || strcasecmp(uuid_conf, pats[1]))
       FAIL("internal error uuid");
-    /* update check here */
 
     /* make sure this isn't a dup */
     for(a = attr; a; a = a->next) {
@@ -506,6 +505,8 @@
     xmlAddChild(parent, node);
   }
 
+  if(noit_conf_write_file(NULL) != 0)
+    noitL(noit_error, "local config write failed\n");
   noit_conf_mark_changed();
   noit_poller_reload(xpath);
   if(restc->call_closure_free) restc->call_closure_free(restc->call_closure);

Modified: trunk/src/noit_conf.c
===================================================================
--- trunk/src/noit_conf.c	2009-09-16 04:19:24 UTC (rev 842)
+++ trunk/src/noit_conf.c	2009-09-16 05:01:19 UTC (rev 843)
@@ -596,11 +596,21 @@
   return 0;
 }
 int
-noit_conf_write_file(noit_console_closure_t ncct,
-                     int argc, char **argv,
-                     noit_console_state_t *state, void *closure) {
+noit_conf_write_file_console(noit_console_closure_t ncct,
+                             int argc, char **argv,
+                             noit_console_state_t *state, void *closure) {
+  int rv;
+  char *err = NULL;
+  rv = noit_conf_write_file(&err);
+  nc_printf(ncct, "%s\n", err);
+  if(err) free(err);
+  return rv;
+}
+int
+noit_conf_write_file(char **err) {
   int fd, len;
   char master_file_tmp[PATH_MAX];
+  char errstr[1024];
   xmlOutputBufferPtr out;
   xmlCharEncodingHandlerPtr enc;
 
@@ -609,7 +619,9 @@
   unlink(master_file_tmp);
   fd = open(master_file_tmp, O_CREAT|O_EXCL|O_WRONLY, 0640);
   if(fd < 0) {
-    nc_printf(ncct, "Failed to open tmp file: %s\n", strerror(errno));
+    snprintf(errstr, sizeof(errstr), "Failed to open tmp file: %s",
+             strerror(errno));
+    if(err) *err = strdup(errstr);
     return -1;
   }
   enc = xmlGetCharEncodingHandler(XML_CHAR_ENCODING_UTF8);
@@ -617,20 +629,23 @@
   if(!out) {
     close(fd);
     unlink(master_file_tmp);
-    nc_printf(ncct, "internal error: OutputBufferCreate failed\n");
+    if(err) *err = strdup("internal error: OutputBufferCreate failed");
     return -1;
   }
   len = xmlSaveFormatFileTo(out, master_config, "utf8", 1);
   close(fd);
   if(len <= 0) {
-    nc_printf(ncct, "internal error: writing to tmp file failed.\n");
+    if(err) *err = strdup("internal error: writing to tmp file failed.");
     return -1;
   }
   if(rename(master_file_tmp, master_config_file) != 0) {
-    nc_printf(ncct, "Failed to replace file: %s\n", strerror(errno));
+    snprintf(errstr, sizeof(errstr), "Failed to replace file: %s",
+             strerror(errno));
+    if(err) *err = strdup(errstr);
     return -1;
   }
-  nc_printf(ncct, "%d bytes written.\n", len);
+  snprintf(errstr, sizeof(errstr), "%d bytes written.", len);
+  if(err) *err = strdup(errstr);
   return 0;
 }
 char *

Modified: trunk/src/noit_conf.h
===================================================================
--- trunk/src/noit_conf.h	2009-09-16 04:19:24 UTC (rev 842)
+++ trunk/src/noit_conf.h	2009-09-16 05:01:19 UTC (rev 843)
@@ -111,9 +111,11 @@
                            int argc, char **argv,
                            noit_console_state_t *state, void *closure);
 API_EXPORT(int)
-  noit_conf_write_file(noit_console_closure_t ncct,
-                       int argc, char **argv,
-                       noit_console_state_t *state, void *closure);
+  noit_conf_write_file_console(noit_console_closure_t ncct,
+                               int argc, char **argv,
+                               noit_console_state_t *state, void *closure);
+API_EXPORT(int)
+  noit_conf_write_file(char **err);
 
 API_EXPORT(char *)
   noit_conf_xml_in_mem(size_t *len);

Modified: trunk/src/noit_conf_checks.c
===================================================================
--- trunk/src/noit_conf_checks.c	2009-09-16 04:19:24 UTC (rev 842)
+++ trunk/src/noit_conf_checks.c	2009-09-16 05:01:19 UTC (rev 843)
@@ -1313,9 +1313,9 @@
   /* write <terimal|memory|file> */
   NEW_STATE(_write_state);
   ADD_CMD(_write_state, "terminal", noit_conf_write_terminal, NULL, NULL, NULL);
-  ADD_CMD(_write_state, "file", noit_conf_write_file, NULL, NULL, NULL);
+  ADD_CMD(_write_state, "file", noit_conf_write_file_console, NULL, NULL, NULL);
   /* write memory?  It's to a file, but I like router syntax */
-  ADD_CMD(_write_state, "memory", noit_conf_write_file, NULL, NULL, NULL);
+  ADD_CMD(_write_state, "memory", noit_conf_write_file_console, NULL, NULL, NULL);
 
   /* attribute <attrname> <value> */
   NEW_STATE(_attr_state);



More information about the Reconnoiter-devel mailing list