From: Pekka Riikonen Date: Thu, 15 May 2014 18:25:46 +0000 (+0300) Subject: Fix log file cycling X-Git-Url: http://git.silc.fi/gitweb/?a=commitdiff_plain;h=1d76faba26d4ac45fb3b17d6e4257d3c461b4a2b;p=silc.git Fix log file cycling If log file cycling doesn't have permission to create a new log file it will end up closing the log file for good and stop logging. Fix this by checking if permission to cycle the log file exists and disable the feature if it doesn't. --- diff --git a/lib/silcutil/silclog.c b/lib/silcutil/silclog.c index 824efb70..232a3864 100644 --- a/lib/silcutil/silclog.c +++ b/lib/silcutil/silclog.c @@ -117,17 +117,26 @@ static void silc_log_checksize(SilcLog log) silc_time_string(0), log->typename, (unsigned long)log->maxsize / 1024); fflush(log->fp); - fclose(log->fp); memset(newname, 0, sizeof(newname)); silc_snprintf(newname, sizeof(newname) - 1, "%s.old", log->filename); unlink(newname); - rename(log->filename, newname); + if (rename(log->filename, newname)) { + fprintf(log->fp, + "[%s] [%s] Couldn't recycle log file '%s' for type '%s': %s", + silc_time_string(0), log->typename, + log->filename, log->typename, strerror(errno)); + log->maxsize = 0; + return; + } + fclose(log->fp); log->fp = fopen(log->filename, "w"); - if (!log->fp) + if (!log->fp) { SILC_LOG_WARNING(("Couldn't reopen log file '%s' for type '%s': %s", log->filename, log->typename, strerror(errno))); + log->maxsize = 0; + } #ifdef HAVE_CHMOD chmod(log->filename, 0600); #endif /* HAVE_CHMOD */