*/
struct rspamd_logger_s {
rspamd_log_func_t log_func;
- struct rspamd_config *cfg;
+ enum rspamd_log_type log_type;
+ gint log_facility;
+ gint log_level;
+ gchar *log_file;
+ gboolean log_buffered;
+ gboolean log_silent_workers;
+ guint32 log_buf_size;
+
struct rspamd_logger_error_log *errlog;
struct rspamd_cryptobox_pubkey *pk;
struct rspamd_cryptobox_keypair *keypair;
rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
{
if (!rspamd_log->opened) {
- switch (rspamd_log->cfg->log_type) {
+ switch (rspamd_log->log_type) {
case RSPAMD_LOG_CONSOLE:
/* Do nothing with console */
rspamd_log->fd = -1;
case RSPAMD_LOG_SYSLOG:
#ifdef HAVE_SYSLOG_H
openlog ("rspamd", LOG_NDELAY | LOG_PID,
- rspamd_log->cfg->log_facility);
+ rspamd_log->log_facility);
#endif
break;
case RSPAMD_LOG_FILE:
- rspamd_log->fd = open (rspamd_log->cfg->log_file,
+ rspamd_log->fd = open (rspamd_log->log_file,
O_CREAT | O_WRONLY | O_APPEND,
S_IWUSR | S_IRUSR | S_IRGRP | S_IROTH);
if (rspamd_log->fd == -1) {
fprintf (stderr,
- "open_log: cannot open desired log file: %s, %s",
- rspamd_log->cfg->log_file, strerror (errno));
+ "open_log: cannot open desired log file: %s, %s my pid: %d",
+ rspamd_log->log_file, strerror (errno), getpid ());
return -1;
}
if (fchown (rspamd_log->fd, uid, gid) == -1) {
fprintf (stderr,
"open_log: cannot chown desired log file: %s, %s",
- rspamd_log->cfg->log_file, strerror (errno));
+ rspamd_log->log_file, strerror (errno));
close (rspamd_log->fd);
return -1;
}
}
void
-rspamd_log_close_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
+rspamd_log_close_priv (rspamd_logger_t *rspamd_log, gboolean termination, uid_t uid, gid_t gid)
{
gchar tmpbuf[256];
rspamd_log_flush (rspamd_log);
rspamd_log->enabled = FALSE;
rspamd_log->opened = FALSE;
}
+
+ if (termination && rspamd_log->log_file) {
+ g_free (rspamd_log->log_file);
+ rspamd_log->log_file = NULL;
+ }
}
gint
rspamd_log_reopen_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
{
- rspamd_log_close_priv (rspamd_log, uid, gid);
+ rspamd_log_close_priv (rspamd_log, FALSE, uid, gid);
if (rspamd_log_open_priv (rspamd_log, uid, gid) == 0) {
msg_info ("log file reopened");
* Close log file or destroy other structures
*/
void
-rspamd_log_close (rspamd_logger_t *logger)
+rspamd_log_close (rspamd_logger_t *logger, gboolean termination)
{
- rspamd_log_close_priv (logger, -1, -1);
+ rspamd_log_close_priv (logger, termination, -1, -1);
}
/**
break;
}
- logger->cfg = cfg;
+ logger->log_type = cfg->log_type;
+ logger->log_facility = cfg->log_facility;
+ logger->log_level = cfg->log_level;
+ logger->log_buffered = cfg->log_buffered;
+ logger->log_silent_workers = cfg->log_silent_workers;
+ logger->log_buf_size = cfg->log_buf_size;
+
+ if (logger->log_file) {
+ g_free (logger->log_file);
+ logger->log_file = NULL;
+ }
+ if (cfg->log_file) {
+ logger->log_file = g_strdup (cfg->log_file);
+ }
+
logger->flags = cfg->log_flags;
/* Set up buffer */
direct_write_log_line (rspamd_log,
rspamd_log->io_buf.buf,
rspamd_log->io_buf.used,
- FALSE, rspamd_log->cfg->log_level);
+ FALSE, rspamd_log->log_level);
rspamd_log->io_buf.used = 0;
}
}
{
g_assert (rspamd_log != NULL);
- if ((log_level & RSPAMD_LOG_FORCED) || log_level <= rspamd_log->cfg->log_level) {
+ if ((log_level & RSPAMD_LOG_FORCED) || log_level <= rspamd_log->log_level) {
return TRUE;
}
TRUE)) {
rspamd_main->cfg = old_cfg;
rspamd_log_close_priv (rspamd_main->logger,
+ FALSE,
rspamd_main->workers_uid,
rspamd_main->workers_gid);
rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"),
" is restarting");
g_hash_table_foreach (rspamd_main->workers, kill_old_workers, NULL);
rspamd_log_close_priv (rspamd_main->logger,
+ FALSE,
rspamd_main->workers_uid,
rspamd_main->workers_gid);
reread_config (rspamd_main);
exit (EXIT_SUCCESS);
}
- rspamd_log_close_priv (rspamd_main->logger, rspamd_main->workers_uid,
- rspamd_main->workers_gid);
+ rspamd_log_close_priv (rspamd_main->logger, FALSE,
+ rspamd_main->workers_uid, rspamd_main->workers_gid);
if (config_test || dump_cache) {
if (!load_rspamd_config (rspamd_main, rspamd_main->cfg, FALSE, 0,
msg_info_main ("terminating...");
- rspamd_log_close (rspamd_main->logger);
REF_RELEASE (rspamd_main->cfg);
+ rspamd_log_close (rspamd_main->logger, TRUE);
g_hash_table_unref (rspamd_main->spairs);
g_hash_table_unref (rspamd_main->workers);
rspamd_mempool_delete (rspamd_main->server_pool);