OPTION(ENABLE_REDIRECTOR "Enable redirector install [default: OFF]" OFF)
OPTION(ENABLE_PROFILING "Enable profiling [default: OFF]" OFF)
OPTION(ENABLE_GPERF_TOOLS "Enable google perftools [default: OFF]" OFF)
+OPTION(ENABLE_STATIC "Enable static compiling [default: OFF]" OFF)
# Build optimized code for following CPU (default i386)
#SET(CPU_TUNE "i686")
MESSAGE(FATAL_ERROR "Error: yacc and lex are required for build")
ENDIF(NOT LEX_EXECUTABLE OR NOT YACC_EXECUTABLE)
-pkg_check_modules(GLIB2 REQUIRED glib-2.0>=2.16 gmodule-2.0)
+IF(ENABLE_STATIC MATCHES "ON")
+ pkg_check_modules(GLIB2 REQUIRED glib-2.0>=2.16)
+ pkg_check_modules(PCRE REQUIRED libpcre)
+ELSE(ENABLE_STATIC MATCHES "ON")
+ pkg_check_modules(GLIB2 REQUIRED glib-2.0>=2.16 gmodule-2.0)
+ENDIF(ENABLE_STATIC MATCHES "ON")
pkg_check_modules(GMIME2 gmime-2.0)
# Try to link with gmime24
FOREACH(arg ${GLIB2_CFLAGS})
SET(GLIB_CFLAGS "${GLIB_CFLAGS} ${arg}")
ENDFOREACH(arg ${GLIB2_CFLAGS})
-FOREACH(arg ${GLIB2_LDFLAGS})
- SET(GLIB_LDFLAGS "${GLIB_LDFLAGS} ${arg}")
-ENDFOREACH(arg ${GLIB2_LDFLAGS})
+
+IF(ENABLE_STATIC MATCHES "ON")
+ FOREACH(arg ${GLIB2_STATIC_LDFLAGS})
+ SET(GLIB_LDFLAGS "${GLIB_LDFLAGS} ${arg}")
+ ENDFOREACH(arg ${GLIB2_LDFLAGS})
+ELSE(ENABLE_STATIC MATCHES "ON")
+ FOREACH(arg ${GLIB2_LDFLAGS})
+ SET(GLIB_LDFLAGS "${GLIB_LDFLAGS} ${arg}")
+ ENDFOREACH(arg ${GLIB2_LDFLAGS})
+ENDIF(ENABLE_STATIC MATCHES "ON")
# Gmime2
FOREACH(arg ${GMIME2_CFLAGS})
SET(GMIME_CFLAGS "${GMIME_CFLAGS} ${arg}")
ENDFOREACH(arg ${GMIME2_CFLAGS})
-FOREACH(arg ${GMIME2_LDFLAGS})
- SET(GMIME_LDFLAGS "${GMIME_LDFLAGS} ${arg}")
-ENDFOREACH(arg ${GMIME2_LDFLAGS})
+
+IF(ENABLE_STATIC MATCHES "ON")
+ FOREACH(arg ${GMIME2_STATIC_LDFLAGS})
+ SET(GMIME_LDFLAGS "${GMIME_LDFLAGS} ${arg}")
+ ENDFOREACH(arg ${GMIME2_LDFLAGS})
+ELSE(ENABLE_STATIC MATCHES "ON")
+ FOREACH(arg ${GMIME2_LDFLAGS})
+ SET(GMIME_LDFLAGS "${GMIME_LDFLAGS} ${arg}")
+ ENDFOREACH(arg ${GMIME2_LDFLAGS})
+ENDIF(ENABLE_STATIC MATCHES "ON")
INCLUDE_DIRECTORIES(${GLIB2_INCLUDE_DIRS})
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg")
ENDIF(ENABLE_PROFILING MATCHES "ON")
+IF(ENABLE_STATIC MATCHES "ON")
+ SET(BUILD_STATIC 1)
+ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
+ MESSAGE(STATUS "Static build of rspamd, no custom plugins support")
+ENDIF(ENABLE_STATIC MATCHES "ON")
+
IF(ENABLE_GPERF_TOOLS MATCHES "ON")
FIND_PATH(GPERF_INCLUDE google/profiler.h PATHS /opt/include
/usr/include
ENDIF(ENABLE_PERL MATCHES "ON")
IF(ENABLE_LUA MATCHES "ON")
- TARGET_LINK_LIBRARIES(rspamd "${LUA_LIBRARY}")
TARGET_LINK_LIBRARIES(rspamd rspamd_lua)
+ TARGET_LINK_LIBRARIES(rspamd "${LUA_LIBRARY}")
ENDIF(ENABLE_LUA MATCHES "ON")
TARGET_LINK_LIBRARIES(rspamd m)
TARGET_LINK_LIBRARIES(rspamd rspamd_json)
TARGET_LINK_LIBRARIES(rspamd ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(rspamd ${GMIME2_LIBRARIES})
+IF(ENABLE_STATIC MATCHES "ON")
+ TARGET_LINK_LIBRARIES(rspamd ${PCRE_LIBRARIES})
+ENDIF(ENABLE_STATIC MATCHES "ON")
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ TARGET_LINK_LIBRARIES(rspamd rt)
+ TARGET_LINK_LIBRARIES(rspamd dl)
+ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
IF(ENABLE_GPERF_TOOLS MATCHES "ON")
TARGET_LINK_LIBRARIES(rspamd profiler)
TARGET_LINK_LIBRARIES(test/rspamd-test event)
TARGET_LINK_LIBRARIES(test/rspamd-test ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(test/rspamd-test ${GMIME2_LIBRARIES})
+IF(ENABLE_STATIC MATCHES "ON")
+ TARGET_LINK_LIBRARIES(test/rspamd-test ${PCRE_LIBRARIES})
+ENDIF(ENABLE_STATIC MATCHES "ON")
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ TARGET_LINK_LIBRARIES(test/rspamd-test rt)
+ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
ADD_EXECUTABLE(utils/url-extracter ${UTILSDEPENDS} ${CONTRIBSRC} ${UTILSSRC})
SET_TARGET_PROPERTIES(utils/url-extracter PROPERTIES LINKER_LANGUAGE C)
ENDIF(LIBUTIL_LIBRARY)
TARGET_LINK_LIBRARIES(utils/url-extracter ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(utils/url-extracter ${GMIME2_LIBRARIES})
+IF(ENABLE_STATIC MATCHES "ON")
+ TARGET_LINK_LIBRARIES(utils/url-extracter ${PCRE_LIBRARIES})
+ENDIF(ENABLE_STATIC MATCHES "ON")
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ TARGET_LINK_LIBRARIES(utils/url-extracter rt)
+ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
ADD_EXECUTABLE(utils/expression-parser ${UTILSDEPENDS} ${CONTRIBSRC} ${EXPRSRC})
SET_TARGET_PROPERTIES(utils/expression-parser PROPERTIES LINKER_LANGUAGE C)
ENDIF(LIBUTIL_LIBRARY)
TARGET_LINK_LIBRARIES(utils/expression-parser ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(utils/expression-parser ${GMIME2_LIBRARIES})
+IF(ENABLE_STATIC MATCHES "ON")
+ TARGET_LINK_LIBRARIES(utils/expression-parser ${PCRE_LIBRARIES})
+ENDIF(ENABLE_STATIC MATCHES "ON")
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ TARGET_LINK_LIBRARIES(utils/expression-parser rt)
+ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
##################### INSTALLATION ##########################################
# include <glib/gprintf.h>
#endif
+#ifndef BUILD_STATIC
+
#define MODULE_INIT_FUNC "module_init"
#define MODULE_FINIT_FUNC "module_fin"
#define MODULE_BEFORE_CONNECT_FUNC "before_connect"
struct custom_filter {
char *filename; /*< filename */
GModule *handle; /*< returned by dlopen */
- void (*init_func)(void); /*< called at start of worker */
+ void (*init_func)(struct config_file *cfg); /*< called at start of worker */
void* (*before_connect)(void); /*< called when clients connects */
gboolean (*process_line)(const char *line, size_t len, char **output, void *user_data); /*< called when client send data line */
void (*after_connect)(char **output, char **log_line, void *user_data); /*< called when client disconnects */
void (*fin_func)(void);
};
+#endif
+
static struct timeval io_tv;
/* Detect whether this worker is mime worker */
static gboolean is_mime;
static gboolean write_socket (void *arg);
+sig_atomic_t wanna_die = 0;
+
#ifndef HAVE_SA_SIGINFO
static void
sig_handler (int signo)
sig_handler (int signo, siginfo_t *info, void *unused)
#endif
{
+ struct timeval tv;
+
switch (signo) {
case SIGINT:
case SIGTERM:
- close_log ();
+ if (!wanna_die) {
+ wanna_die = 1;
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+ event_loopexit (&tv);
+
#ifdef WITH_GPERF_TOOLS
- ProfilerStop ();
-#endif
-#ifdef WITH_PROFILER
- exit (0);
-#else
- _exit (1);
+ ProfilerStop ();
#endif
+ }
break;
}
}
struct rspamd_worker *worker = (struct rspamd_worker *)arg;
/* Do not accept new connections, preparing to end worker's process */
struct timeval tv;
- tv.tv_sec = SOFT_SHUTDOWN_TIME;
- tv.tv_usec = 0;
- event_del (&worker->sig_ev);
- event_del (&worker->bind_ev);
- do_reopen_log = 1;
- msg_info ("worker's shutdown is pending in %d sec", SOFT_SHUTDOWN_TIME);
- event_loopexit (&tv);
+ if (! wanna_die) {
+ tv.tv_sec = SOFT_SHUTDOWN_TIME;
+ tv.tv_usec = 0;
+ event_del (&worker->sig_ev);
+ event_del (&worker->bind_ev);
+ do_reopen_log = 1;
+ msg_info ("worker's shutdown is pending in %d sec", SOFT_SHUTDOWN_TIME);
+ event_loopexit (&tv);
+ }
return;
}
}
}
+#ifndef BUILD_STATIC
static void
fin_custom_filters (struct worker_task *task)
{
return res;
}
+#else
+/* Stubs */
+static void
+fin_custom_filters (struct worker_task *task)
+{
+
+}
+static gboolean
+parse_line_custom (struct worker_task *task, f_str_t *in)
+{
+ return FALSE;
+}
+#endif
/*
* Free all structures of worker_task
new_task->dispatcher->peer_addr = new_task->client_addr.s_addr;
/* Init custom filters */
+#ifndef BUILD_STATIC
if (is_custom) {
cur = custom_filters;
while (cur) {
/* Keep user data in the same order as custom filters */
new_task->rcpt = g_list_reverse (new_task->rcpt);
}
+#endif
+
}
+#ifndef BUILD_STATIC
static gboolean
-load_custom_filter (const char *file)
+load_custom_filter (struct config_file *cfg, const char *file)
{
struct custom_filter *filt;
struct stat st;
g_free (filt);
return FALSE;
}
-
+
+ filt->init_func (cfg);
filt->filename = g_strdup (file);
custom_filters = g_list_prepend (custom_filters, filt);
}
for (i = 0; i < gp.gl_pathc; i ++) {
- if (! load_custom_filter (gp.gl_pathv[i])) {
+ if (! load_custom_filter (worker->srv->cfg, gp.gl_pathv[i])) {
globfree (&gp);
return FALSE;
}
g_list_free (custom_filters);
}
+#endif
+
/*
* Start worker process
*/
/* Accept event */
event_set (&worker->bind_ev, worker->cf->listen_sock, EV_READ | EV_PERSIST, accept_socket, (void *)worker);
event_add (&worker->bind_ev, NULL);
-
+
+#ifndef BUILD_STATIC
/* Check if this worker is not usual rspamd worker, but uses custom filters from specified path */
is_custom_str = g_hash_table_lookup (worker->cf->params, "custom_filters");
if (is_custom_str && g_module_supported () && load_custom_filters (worker, is_custom_str)) {
is_custom = TRUE;
}
else {
+#endif
/* Maps events */
start_map_watch ();
/* Check whether we are mime worker */
else {
is_mime = TRUE;
}
+#ifndef BUILD_STATIC
}
+#endif
event_loop (0);
- close_log ();
- exit (EXIT_SUCCESS);
-
+#ifndef BUILD_STATIC
if (is_custom) {
unload_custom_filters ();
}
+#endif
+
+ close_log ();
+ exit (EXIT_SUCCESS);
}
/*