]> source.dussan.org Git - rspamd.git/commitdiff
Fix reload of rspamd.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 25 Dec 2013 17:44:37 +0000 (17:44 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 25 Dec 2013 17:44:37 +0000 (17:44 +0000)
src/cfg_utils.c
src/logger.c
src/logger.h
src/main.c
src/util.c

index d6c2b3fc99cfb17f92fc1929494ea0fa2f2c9f53..8e57ea1c9ae097614467363f21b9cf0c89d20fed 100644 (file)
@@ -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);
index c4592af331dbeb39a780c8a208327d32653f37e7..c0f2e48884bd4ada1c878193c749e12b64c68d5a 100644 (file)
@@ -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) {
index 676b3013190a09aa00470ca37f044e2fcbc8706f..50b9fe41bd0f95adc6f10cfa64d427c2bd111740 100644 (file)
@@ -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
  */
index 7bbe6319909dfb45d45e96bfaaae2df542b0bf71..a9bf5c7e3a68d74cddc27b56b41328cb26b33c4d 100644 (file)
@@ -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);
 
index 53d73b53a89224a748be8f96c813ef837e63b468..50dbf7a37100048c3e8163aab688d8a089d73afb 100644 (file)
@@ -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;