diff options
-rw-r--r-- | src/cfg_utils.c | 28 | ||||
-rw-r--r-- | src/logger.c | 8 | ||||
-rw-r--r-- | src/logger.h | 2 | ||||
-rw-r--r-- | src/main.c | 7 | ||||
-rw-r--r-- | src/util.c | 46 |
5 files changed, 34 insertions, 57 deletions
diff --git a/src/cfg_utils.c b/src/cfg_utils.c index d6c2b3fc9..8e57ea1c9 100644 --- a/src/cfg_utils.c +++ b/src/cfg_utils.c @@ -175,34 +175,6 @@ parse_bind_line (struct config_file *cfg, struct worker_conf *cf, const gchar *s cnf->bind_port = DEFAULT_BIND_PORT; if (str[0] == '/' || str[0] == '.') { -#ifdef HAVE_DIRNAME - /* Try to check path of bind credit */ - struct stat st; - gint fd; - gchar *copy = memory_pool_strdup (cfg->cfg_pool, str); - if (stat (copy, &st) == -1) { - if (errno == ENOENT) { - if ((fd = open (str, O_RDWR | O_TRUNC | O_CREAT, S_IWUSR | S_IRUSR)) == -1) { - msg_err ("cannot open path %s for making socket, %s", str, strerror (errno)); - return FALSE; - } - else { - close (fd); - unlink (str); - } - } - else { - msg_err ("cannot stat path %s for making socket, %s", str, strerror (errno)); - return 0; - } - } - else { - if (unlink (str) == -1) { - msg_err ("cannot remove path %s for making socket, %s", str, strerror (errno)); - return 0; - } - } -#endif cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str); cnf->is_unix = TRUE; LL_PREPEND (cf->bind_conf, cnf); diff --git a/src/logger.c b/src/logger.c index c4592af33..c0f2e4888 100644 --- a/src/logger.c +++ b/src/logger.c @@ -275,7 +275,7 @@ reopen_log (rspamd_logger_t *logger) * Setup logger */ void -rspamd_set_logger (enum rspamd_log_type type, GQuark ptype, struct rspamd_main *rspamd) +rspamd_set_logger (struct config_file *cfg, GQuark ptype, struct rspamd_main *rspamd) { gchar **strvec, *p, *err; gint num, i, k; @@ -287,7 +287,7 @@ rspamd_set_logger (enum rspamd_log_type type, GQuark ptype, struct rspamd_main * memset (rspamd->logger, 0, sizeof (rspamd_logger_t)); } - rspamd->logger->type = type; + rspamd->logger->type = cfg->log_type; rspamd->logger->pid = getpid (); rspamd->logger->process_type = ptype; @@ -298,7 +298,7 @@ rspamd_set_logger (enum rspamd_log_type type, GQuark ptype, struct rspamd_main * g_mutex_init (rspamd->logger->mtx); #endif - switch (type) { + switch (cfg->log_type) { case RSPAMD_LOG_CONSOLE: rspamd->logger->log_func = file_log_function; rspamd->logger->fd = STDERR_FILENO; @@ -311,7 +311,7 @@ rspamd_set_logger (enum rspamd_log_type type, GQuark ptype, struct rspamd_main * break; } - rspamd->logger->cfg = rspamd->cfg; + rspamd->logger->cfg = cfg; /* Set up buffer */ if (rspamd->cfg->log_buffered) { if (rspamd->cfg->log_buf_size != 0) { diff --git a/src/logger.h b/src/logger.h index 676b30131..50b9fe41b 100644 --- a/src/logger.h +++ b/src/logger.h @@ -15,7 +15,7 @@ typedef struct rspamd_logger_s rspamd_logger_t; /** * Init logger */ -void rspamd_set_logger (enum rspamd_log_type type, GQuark ptype, struct rspamd_main *main); +void rspamd_set_logger (struct config_file *cfg, GQuark ptype, struct rspamd_main *main); /** * Open log file or initialize other structures */ diff --git a/src/main.c b/src/main.c index 7bbe63199..a9bf5c7e3 100644 --- a/src/main.c +++ b/src/main.c @@ -303,7 +303,7 @@ config_logger (struct config_file *cfg, gpointer ud) { struct rspamd_main *rm = ud; - rspamd_set_logger (cfg->log_type, g_quark_try_string ("main"), rm); + rspamd_set_logger (cfg, g_quark_try_string ("main"), rm); if (open_log_priv (rm->logger, rm->workers_uid, rm->workers_gid) == -1) { fprintf (stderr, "Fatal error, cannot open logfile, exiting\n"); exit (EXIT_FAILURE); @@ -376,6 +376,7 @@ reread_config (struct rspamd_main *rspamd) memory_pool_add_destructor (tmp_cfg->cfg_pool, (pool_destruct_func)lua_close, tmp_cfg->lua_state); if (! load_rspamd_config (tmp_cfg, FALSE)) { + rspamd_set_logger (rspamd_main->cfg, g_quark_try_string ("main"), rspamd_main); msg_err ("cannot parse new config file, revert to old one"); free_config (tmp_cfg); } @@ -393,6 +394,7 @@ reread_config (struct rspamd_main *rspamd) rspamd->cfg->cache = g_new0 (struct symbols_cache, 1); rspamd->cfg->cache->static_pool = memory_pool_new (memory_pool_get_size ()); rspamd->cfg->cache->cfg = rspamd->cfg; + rspamd_main->cfg->cache->items_by_symbol = g_hash_table_new (rspamd_str_hash, rspamd_str_equal); /* Perform modules configuring */ l = g_list_first (rspamd->cfg->filters); @@ -1053,7 +1055,8 @@ main (gint argc, gchar **argv, gchar **env) rspamd_prng_seed (); /* First set logger to console logger */ - rspamd_set_logger (RSPAMD_LOG_CONSOLE, type, rspamd_main); + rspamd_main->cfg->log_type = RSPAMD_LOG_CONSOLE; + rspamd_set_logger (rspamd_main->cfg, type, rspamd_main); (void)open_log (rspamd_main->logger); g_log_set_default_handler (rspamd_glib_log_function, rspamd_main->logger); diff --git a/src/util.c b/src/util.c index 53d73b53a..50dbf7a37 100644 --- a/src/util.c +++ b/src/util.c @@ -221,6 +221,7 @@ gint make_unix_socket (const gchar *path, struct sockaddr_un *addr, gint type, gboolean is_server, gboolean async) { gint fd, s_error, r, optlen, serrno, on = 1; + struct stat st; if (path == NULL) return -1; @@ -232,10 +233,25 @@ make_unix_socket (const gchar *path, struct sockaddr_un *addr, gint type, gboole addr->sun_len = SUN_LEN (addr); #endif + if (is_server) { + /* Unlink socket if it exists already */ + if (lstat (addr->sun_path, &st) != -1) { + if (S_ISSOCK (st.st_mode)) { + if (unlink (addr->sun_path) == -1) { + msg_warn ("unlink %s failed: %d, '%s'", addr->sun_path, errno, strerror (errno)); + goto out; + } + } + else { + msg_warn ("%s is not a socket", addr->sun_path); + goto out; + } + } + } fd = socket (PF_LOCAL, type, 0); if (fd == -1) { - msg_warn ("socket failed: %d, '%s'", errno, strerror (errno)); + msg_warn ("socket failed %s: %d, '%s'", addr->sun_path, errno, strerror (errno)); return -1; } @@ -245,7 +261,7 @@ make_unix_socket (const gchar *path, struct sockaddr_un *addr, gint type, gboole /* Set close on exec */ if (fcntl (fd, F_SETFD, FD_CLOEXEC) == -1) { - msg_warn ("fcntl failed: %d, '%s'", errno, strerror (errno)); + msg_warn ("fcntl failed %s: %d, '%s'", addr->sun_path, errno, strerror (errno)); goto out; } if (is_server) { @@ -258,14 +274,14 @@ make_unix_socket (const gchar *path, struct sockaddr_un *addr, gint type, gboole if (r == -1) { if (errno != EINPROGRESS) { - msg_warn ("bind/connect failed: %d, '%s'", errno, strerror (errno)); + msg_warn ("bind/connect failed %s: %d, '%s'", addr->sun_path, errno, strerror (errno)); goto out; } if (!async) { /* Try to poll */ if (poll_sync_socket (fd, CONNECT_TIMEOUT * 1000, POLLOUT) <= 0) { errno = ETIMEDOUT; - msg_warn ("bind/connect failed: timeout"); + msg_warn ("bind/connect failed %s: timeout", addr->sun_path); goto out; } else { @@ -315,18 +331,11 @@ make_universal_socket (const gchar *credits, guint16 port, gchar portbuf[8]; if (*credits == '/') { - r = stat (credits, &st); if (is_server) { - if (r == -1) { - return make_unix_socket (credits, &un, type, is_server, async); - } - else { - /* Unix socket exists, it must be unlinked first */ - errno = EEXIST; - return -1; - } + return make_unix_socket (credits, &un, type, is_server, async); } else { + r = stat (credits, &st); if (r == -1) { /* Unix socket doesn't exists it must be created first */ errno = ENOENT; @@ -399,18 +408,11 @@ make_universal_sockets_list (const gchar *credits, guint16 port, cur = strv; while (*cur != NULL) { if (*credits == '/') { - r = stat (credits, &st); if (is_server) { - if (r == -1) { - fd = make_unix_socket (credits, &un, type, is_server, async); - } - else { - /* Unix socket exists, it must be unlinked first */ - errno = EEXIST; - goto err; - } + fd = make_unix_socket (credits, &un, type, is_server, async); } else { + r = stat (credits, &st); if (r == -1) { /* Unix socket doesn't exists it must be created first */ errno = ENOENT; |