aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-08-25 15:52:59 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-08-25 15:52:59 +0000
commit8237a28acd1633ba4f981b3dc4e2582abe465977 (patch)
tree6e2feb97becadf08dc3c58386594a045f1034a95
parentb24ad3acaba42d7f6e73bc70436ab22e462db1d3 (diff)
Fix the logic in config_text_file_save so that if an
UpdateConfig manager action is issued and the file specified in DstFileName does not yet exist, an error is not returned. (closes issue #13341) Reported by: vadim Patches: 13341.patch uploaded by putnopvut (license 60) (with small modification from seanbright) git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@139769 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--main/config.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/main/config.c b/main/config.c
index 26404af95..6163f827a 100644
--- a/main/config.c
+++ b/main/config.c
@@ -1013,6 +1013,7 @@ int config_text_file_save(const char *configfile, const struct ast_config *cfg,
struct ast_comment *cmt;
struct stat s;
int blanklines = 0;
+ int stat_result = 0;
if (configfile[0] == '/') {
snprintf(fntmp, sizeof(fntmp), "%s.XXXXXX", configfile);
@@ -1124,10 +1125,11 @@ int config_text_file_save(const char *configfile, const struct ast_config *cfg,
close(fd);
return -1;
}
- stat(fn, &s);
- fchmod(fd, s.st_mode);
+ if (!(stat_result = stat(fn, &s))) {
+ fchmod(fd, s.st_mode);
+ }
fclose(f);
- if (unlink(fn) || link(fntmp, fn)) {
+ if ((!stat_result && unlink(fn)) || link(fntmp, fn)) {
if (option_debug)
ast_log(LOG_DEBUG, "Unable to open for writing: %s (%s)\n", fn, strerror(errno));
if (option_verbose > 1)