gboolean is_debug;
gboolean throttling;
gboolean no_lock;
+ gboolean opened;
time_t throttling_time;
enum rspamd_log_type type;
pid_t pid;
gint
rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
{
- switch (rspamd_log->cfg->log_type) {
+ if (!rspamd_log->opened) {
+ switch (rspamd_log->cfg->log_type) {
case RSPAMD_LOG_CONSOLE:
/* Do nothing with console */
rspamd_log->enabled = TRUE;
- return 0;
+ break;
case RSPAMD_LOG_SYSLOG:
#ifdef HAVE_SYSLOG_H
openlog ("rspamd", LOG_NDELAY | LOG_PID,
rspamd_log->cfg->log_facility);
- rspamd_log->enabled = TRUE;
#endif
- return 0;
+ break;
case RSPAMD_LOG_FILE:
rspamd_log->fd = open (rspamd_log->cfg->log_file,
O_CREAT | O_WRONLY | O_APPEND,
close (rspamd_log->fd);
return -1;
}
- rspamd_log->enabled = TRUE;
- return 0;
+ break;
+ default:
+ return -1;
+ }
+
+ rspamd_log->opened = TRUE;
+ rspamd_log->enabled = TRUE;
}
- return -1;
+
+ return 0;
}
void
gchar tmpbuf[256];
rspamd_log_flush (rspamd_log);
- switch (rspamd_log->type) {
+ if (rspamd_log->opened) {
+ switch (rspamd_log->type) {
case RSPAMD_LOG_CONSOLE:
/* Do nothing special */
break;
rspamd_log->saved_loglevel | RSPAMD_LOG_FORCED,
tmpbuf,
rspamd_log);
- return;
}
if (fsync (rspamd_log->fd) == -1) {
close (rspamd_log->fd);
}
break;
- }
+ }
- rspamd_log->enabled = FALSE;
+ rspamd_log->enabled = FALSE;
+ rspamd_log->opened = FALSE;
+ }
}
gint
rspamd_log_reopen_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
{
rspamd_log_close_priv (rspamd_log, uid, gid);
+
if (rspamd_log_open_priv (rspamd_log, uid, gid) == 0) {
msg_info ("log file reopened");
return 0;
rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"),
&rspamd_main->logger, rspamd_main->server_pool);
+ rspamd_log_close_priv (rspamd_main->logger,
+ rspamd_main->workers_uid, rspamd_main->workers_gid);
+
if (rspamd_log_open_priv (rspamd_main->logger,
rspamd_main->workers_uid, rspamd_main->workers_gid) == -1) {
fprintf (stderr, "Fatal error, cannot open logfile, exiting\n");