Changeset 25fec2caf0dfcfa3c997f8f87f6c42d4e176cea0

Show
Ignore:
Timestamp:
09/16/09 05:01:19 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253077279 +0000
git-parent:

[7010bc5b07e615c0314ff1c0ebb27bdf8420cca3]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1253077279 +0000
Message:

auto-save on REST add, refs #171

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check_rest.c

    r7010bc5 r25fec2c  
    482482    if(!uuid_conf || strcasecmp(uuid_conf, pats[1])) 
    483483      FAIL("internal error uuid"); 
    484     /* update check here */ 
    485484 
    486485    /* make sure this isn't a dup */ 
     
    507506  } 
    508507 
     508  if(noit_conf_write_file(NULL) != 0) 
     509    noitL(noit_error, "local config write failed\n"); 
    509510  noit_conf_mark_changed(); 
    510511  noit_poller_reload(xpath); 
  • src/noit_conf.c

    r7010bc5 r25fec2c  
    597597} 
    598598int 
    599 noit_conf_write_file(noit_console_closure_t ncct, 
    600                      int argc, char **argv, 
    601                      noit_console_state_t *state, void *closure) { 
     599noit_conf_write_file_console(noit_console_closure_t ncct, 
     600                             int argc, char **argv, 
     601                             noit_console_state_t *state, void *closure) { 
     602  int rv; 
     603  char *err = NULL; 
     604  rv = noit_conf_write_file(&err); 
     605  nc_printf(ncct, "%s\n", err); 
     606  if(err) free(err); 
     607  return rv; 
     608
     609int 
     610noit_conf_write_file(char **err) { 
    602611  int fd, len; 
    603612  char master_file_tmp[PATH_MAX]; 
     613  char errstr[1024]; 
    604614  xmlOutputBufferPtr out; 
    605615  xmlCharEncodingHandlerPtr enc; 
     
    610620  fd = open(master_file_tmp, O_CREAT|O_EXCL|O_WRONLY, 0640); 
    611621  if(fd < 0) { 
    612     nc_printf(ncct, "Failed to open tmp file: %s\n", strerror(errno)); 
     622    snprintf(errstr, sizeof(errstr), "Failed to open tmp file: %s", 
     623             strerror(errno)); 
     624    if(err) *err = strdup(errstr); 
    613625    return -1; 
    614626  } 
     
    618630    close(fd); 
    619631    unlink(master_file_tmp); 
    620     nc_printf(ncct, "internal error: OutputBufferCreate failed\n"); 
     632    if(err) *err = strdup("internal error: OutputBufferCreate failed"); 
    621633    return -1; 
    622634  } 
     
    624636  close(fd); 
    625637  if(len <= 0) { 
    626     nc_printf(ncct, "internal error: writing to tmp file failed.\n"); 
     638    if(err) *err = strdup("internal error: writing to tmp file failed."); 
    627639    return -1; 
    628640  } 
    629641  if(rename(master_file_tmp, master_config_file) != 0) { 
    630     nc_printf(ncct, "Failed to replace file: %s\n", strerror(errno)); 
     642    snprintf(errstr, sizeof(errstr), "Failed to replace file: %s", 
     643             strerror(errno)); 
     644    if(err) *err = strdup(errstr); 
    631645    return -1; 
    632646  } 
    633   nc_printf(ncct, "%d bytes written.\n", len); 
     647  snprintf(errstr, sizeof(errstr), "%d bytes written.", len); 
     648  if(err) *err = strdup(errstr); 
    634649  return 0; 
    635650} 
  • src/noit_conf.h

    r7010bc5 r25fec2c  
    112112                           noit_console_state_t *state, void *closure); 
    113113API_EXPORT(int) 
    114   noit_conf_write_file(noit_console_closure_t ncct, 
    115                        int argc, char **argv, 
    116                        noit_console_state_t *state, void *closure); 
     114  noit_conf_write_file_console(noit_console_closure_t ncct, 
     115                               int argc, char **argv, 
     116                               noit_console_state_t *state, void *closure); 
     117API_EXPORT(int) 
     118  noit_conf_write_file(char **err); 
    117119 
    118120API_EXPORT(char *) 
  • src/noit_conf_checks.c

    r0256945 r25fec2c  
    13141314  NEW_STATE(_write_state); 
    13151315  ADD_CMD(_write_state, "terminal", noit_conf_write_terminal, NULL, NULL, NULL); 
    1316   ADD_CMD(_write_state, "file", noit_conf_write_file, NULL, NULL, NULL); 
     1316  ADD_CMD(_write_state, "file", noit_conf_write_file_console, NULL, NULL, NULL); 
    13171317  /* write memory?  It's to a file, but I like router syntax */ 
    1318   ADD_CMD(_write_state, "memory", noit_conf_write_file, NULL, NULL, NULL); 
     1318  ADD_CMD(_write_state, "memory", noit_conf_write_file_console, NULL, NULL, NULL); 
    13191319 
    13201320  /* attribute <attrname> <value> */