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);
* 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;
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;
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;
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) {
/**
* 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
*/
{
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);
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);
}
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);
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);
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;
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;
}
/* 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) {
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 {
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;
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;