}
/* Given an open log file, checks the size and rotates it if there is a
- * max size set less then the current size */
+ * max size set lower then the current size */
static void silc_log_checksize(SilcLog log)
{
char newname[127];
if (!log || !log->fp || !log->maxsize)
return; /* we are not interested */
+
if ((size = ftell(log->fp)) < 0) {
/* OMG, EBADF is here.. we'll try our best.. */
FILE *oldfp = log->fp;
fclose(oldfp); /* we can discard the error */
log->fp = NULL; /* make sure we don't get here recursively */
- SILC_LOG_ERROR(("Error while checking size of the log file %s, fp=%d",
+ SILC_LOG_ERROR(("Error while checking size of the log file %s, fp=%p",
log->filename, oldfp));
return;
}
log->filename, log->typename, strerror(errno)));
return FALSE;
}
+
return TRUE;
}
fprintf(fp, "[%s] [%s] %s\n", silc_get_time(), typename, string);
if (silc_log_quick || silc_log_starting) {
fflush(fp);
- if (log)
+ if (log) /* we may have been redirected to stderr */
silc_log_checksize(log);
}
}
}
- /* remove old file */
+ /* clean the logging channel */
if (log->filename) {
- if (log->fp) {
- fflush(fp);
- fclose(fp);
- }
+ if (log->fp)
+ fclose(log->fp);
silc_free(log->filename);
log->filename = NULL;
log->fp = NULL;
void silc_log_set_debug_string(const char *debug_string)
{
silc_free(silc_log_debug_string);
- if ((strchr(debug_string, '(') &&
- strchr(debug_string, ')')) ||
- strchr(debug_string, '$'))
+ if ((strchr(debug_string, '(') && strchr(debug_string, ')')) ||
+ strchr(debug_string, '$'))
silc_log_debug_string = strdup(debug_string);
else
silc_log_debug_string = silc_string_regexify(debug_string);