if (log_ctx->fp) {
SCClearErrUnlocked(log_ctx->fp);
- ret = SCFwriteUnlocked(buffer, buffer_len, 1, log_ctx->fp);
- SCFflushUnlocked(log_ctx->fp);
+ if (1 != SCFwriteUnlocked(buffer, buffer_len, 1, log_ctx->fp)) {
+ /* Only the first error is logged */
+ if (!log_ctx->output_errors) {
+ SCLogError(SC_ERR_LOG_OUTPUT, "%s error while writing to %s",
+ SCFerrorUnlocked(log_ctx->fp) ? strerror(errno) : "unknown error",
+ log_ctx->filename);
+ }
+ log_ctx->output_errors++;
+ } else {
+ SCFflushUnlocked(log_ctx->fp);
+ }
}
return ret;
if (log_ctx->fp) {
clearerr(log_ctx->fp);
- ret = fwrite(buffer, buffer_len, 1, log_ctx->fp);
- fflush(log_ctx->fp);
+ if (1 != fwrite(buffer, buffer_len, 1, log_ctx->fp)) {
+ /* Only the first error is logged */
+ if (!log_ctx->output_errors) {
+ SCLogError(SC_ERR_LOG_OUTPUT, "%s error while writing to %s",
+ ferror(log_ctx->fp) ? strerror(errno) : "unknown error",
+ log_ctx->filename);
+ }
+ log_ctx->output_errors++;
+ } else {
+ fflush(log_ctx->fp);
+ }
}
}
{
if (log_ctx->fp)
fclose(log_ctx->fp);
+
+ if (log_ctx->output_errors) {
+ SCLogError(SC_ERR_LOG_OUTPUT, "There were %" PRIu64 " output errors to %s",
+ log_ctx->output_errors, log_ctx->filename);
+ }
}
static void SCLogFileClose(LogFileCtx *log_ctx)