Index: main/config.c =================================================================== --- main/config.c (revision 139446) +++ main/config.c (working copy) @@ -1013,6 +1013,7 @@ 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,10 @@ close(fd); return -1; } - stat(fn, &s); + 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)