RSPAMD_LOG_FLAG_USEC = (1 << 3),
RSPAMD_LOG_FLAG_RSPAMADM = (1 << 4),
RSPAMD_LOG_FLAG_ENFORCED = (1 << 5),
+ RSPAMD_LOG_FLAG_TTY = (1 << 6),
};
struct rspamd_worker_log_pipe {
}
}
else {
- fd = STDERR_FILENO;
+ fd = rspamd_log->fd;
}
}
else {
tlen = count;
}
- if (tlen > PIPE_BUF) {
+ if (tlen > PIPE_BUF || rspamd_log->flags & RSPAMD_LOG_FLAG_TTY) {
locked = TRUE;
#ifndef DISABLE_PTHREAD_MUTEX
if (!rspamd_log->opened) {
switch (rspamd_log->log_type) {
case RSPAMD_LOG_CONSOLE:
- /* Do nothing with console */
- rspamd_log->fd = -1;
+ /* Dup stderr fd to simplify processing */
+ rspamd_log->fd = dup (STDERR_FILENO);
+ if (isatty (STDERR_FILENO)) {
+ rspamd_log->flags |= RSPAMD_LOG_FLAG_TTY;
+ }
break;
case RSPAMD_LOG_SYSLOG:
#ifdef HAVE_SYSLOG_H
if (rspamd_log->opened) {
switch (rspamd_log->type) {
- case RSPAMD_LOG_CONSOLE:
- /* Do nothing special */
- break;
case RSPAMD_LOG_SYSLOG:
#ifdef HAVE_SYSLOG_H
closelog ();
close (rspamd_log->fd);
}
break;
+ case RSPAMD_LOG_CONSOLE:
+ if (rspamd_log->fd != -1) {
+ close (rspamd_log->fd);
+ }
+ break;
}
rspamd_log->enabled = FALSE;
switch (cfg->log_type) {
case RSPAMD_LOG_CONSOLE:
logger->log_func = file_log_function;
- logger->fd = -1;
break;
case RSPAMD_LOG_SYSLOG:
logger->log_func = syslog_log_function;