#include "upstream.h"
#include "memcached.h"
#include "symbols_cache.h"
+#include "utlist.h"
#define DEFAULT_BIND_PORT 768
#define DEFAULT_CONTROL_PORT 7608
} type; /**< type of data */
};
+struct rspamd_worker_bind_conf {
+ gchar *bind_host;
+ guint16 bind_port;
+ gboolean is_unix;
+ struct rspamd_worker_bind_conf *next;
+};
/**
* Config params for rspamd worker
struct worker_conf {
worker_t *worker; /**< pointer to worker type */
GQuark type; /**< type of worker */
- gchar *bind_host; /**< bind line */
- gchar *bind_addr; /**< bind address in case of TCP socket */
- guint16 bind_port; /**< bind port in case of TCP socket */
- guint16 bind_family; /**< bind type (AF_UNIX or AF_INET) */
+ struct rspamd_worker_bind_conf *bind_conf; /**< bind configuration */
guint16 count; /**< number of workers */
GList *listen_socks; /**< listening sockets desctiptors */
guint32 rlimit_nofile; /**< max files limit */
* @param type type of credits
* @return 1 if line was successfully parsed and 0 in case of error
*/
-gint parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str);
+gboolean parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str);
/**
* Init default values
return parse_host_port_priority (pool, str, addr, NULL, priority);
}
-gint
+gboolean
parse_bind_line (struct config_file *cfg, struct worker_conf *cf, gchar *str)
{
- gchar **host;
- guint16 *family, *port;
- gchar **addr;
+ struct rspamd_worker_bind_conf *cnf;
if (str == NULL)
return 0;
- host = &cf->bind_host;
- port = &cf->bind_port;
- *port = DEFAULT_BIND_PORT;
- family = &cf->bind_family;
- addr = &cf->bind_addr;
+ cnf = memory_pool_alloc0 (cfg->cfg_pool, sizeof (struct rspamd_worker_bind_conf));
+ cnf->bind_port = DEFAULT_BIND_PORT;
if (str[0] == '/' || str[0] == '.') {
#ifdef HAVE_DIRNAME
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 0;
+ return FALSE;
}
else {
close (fd);
}
}
#endif
- *host = memory_pool_strdup (cfg->cfg_pool, str);
- *addr = *host;
- *family = AF_UNIX;
- return 1;
+ cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str);
+ cnf->is_unix = TRUE;
+ LL_PREPEND (cf->bind_conf, cnf);
+ return TRUE;
}
else {
- if (parse_host_port (cfg->cfg_pool, str, addr, port)) {
- *host = memory_pool_strdup (cfg->cfg_pool, str);
- *family = AF_INET;
-
- return 1;
+ cnf->bind_host = memory_pool_strdup (cfg->cfg_pool, str);
+ if (parse_host_port (cfg->cfg_pool, str, &cnf->bind_host, &cnf->bind_port)) {
+ LL_PREPEND (cf->bind_conf, cnf);
+ return TRUE;
}
}
- return 0;
+ return FALSE;
}
void
rspamd_fprintf (f, "<worker>" EOL);
rspamd_fprintf (f, " <type>%s</type>" EOL, g_quark_to_string (wrk->type));
- escaped_str = g_markup_escape_text (wrk->bind_host, -1);
- rspamd_fprintf (f, " <bind_socket>%s</bind_socket>" EOL, escaped_str);
- g_free (escaped_str);
rspamd_fprintf (f, " <count>%ud</count>" EOL, wrk->count);
rspamd_fprintf (f, " <maxfiles>%ud</maxfiles>" EOL, wrk->rlimit_nofile);
struct worker_conf *cf;
gint i;
gpointer p;
+ struct rspamd_worker_bind_conf *bcf;
cur = rspamd->cfg->workers;
}
else {
if (cf->worker->has_socket) {
- if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER (
- make_listen_key (cf->bind_addr, cf->bind_port, cf->bind_family)))) == NULL) {
- /* Create listen socket */
- ls = create_listen_socket (cf->bind_addr, cf->bind_port, cf->bind_family,
- cf->worker->listen_type);
- if (ls == NULL) {
- exit (-errno);
+ LL_FOREACH (cf->bind_conf, bcf) {
+ if ((p = g_hash_table_lookup (listen_sockets, GINT_TO_POINTER (
+ make_listen_key (bcf->bind_host, bcf->bind_port, bcf->is_unix)))) == NULL) {
+ /* Create listen socket */
+ ls = create_listen_socket (bcf->bind_host, bcf->bind_port,
+ bcf->is_unix ? AF_UNIX : AF_INET,
+ cf->worker->listen_type);
+ if (ls == NULL) {
+ exit (-errno);
+ }
+ g_hash_table_insert (listen_sockets, GINT_TO_POINTER (
+ make_listen_key (bcf->bind_host, bcf->bind_port, bcf->is_unix)),
+ ls);
}
- g_hash_table_insert (listen_sockets, GINT_TO_POINTER (
- make_listen_key (cf->bind_addr, cf->bind_port, cf->bind_family)),
- ls);
- }
- else {
- /* We had socket for this type of worker */
- ls = p;
+ else {
+ /* We had socket for this type of worker */
+ ls = p;
+ }
+ cf->listen_socks = g_list_prepend (cf->listen_socks, ls);
}
- cf->listen_socks = ls;
}
if (cf->worker->unique) {