]> source.dussan.org Git - rspamd.git/commitdiff
* Add ability to build rspamd static
authorcebka@lenovo-laptop <cebka@lenovo-laptop>
Fri, 19 Feb 2010 15:13:54 +0000 (18:13 +0300)
committercebka@lenovo-laptop <cebka@lenovo-laptop>
Fri, 19 Feb 2010 15:13:54 +0000 (18:13 +0300)
CMakeLists.txt
config.h.in
src/worker.c

index db420d556083175b0efb6a0a8ab207a7caebeb64..270188dfb8aa2a3679d0a0cebd725555d7dcbda9 100644 (file)
@@ -24,6 +24,7 @@ OPTION(SKIP_RELINK_RPATH   "Skip relinking and full RPATH for the install tree"
 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")
@@ -93,7 +94,12 @@ IF(NOT LEX_EXECUTABLE OR NOT YACC_EXECUTABLE)
        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
@@ -111,16 +117,30 @@ ENDIF(NOT GLIB2_FOUND OR NOT GMIME2_FOUND)
 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})
@@ -146,6 +166,12 @@ IF(ENABLE_PROFILING MATCHES "ON")
        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
@@ -494,8 +520,8 @@ IF(ENABLE_PERL MATCHES "ON")
 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)
@@ -507,6 +533,13 @@ TARGET_LINK_LIBRARIES(rspamd event)
 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)
@@ -521,6 +554,12 @@ ENDIF(LIBUTIL_LIBRARY)
 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)
@@ -530,6 +569,12 @@ IF(LIBUTIL_LIBRARY)
 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)
@@ -539,6 +584,12 @@ IF(LIBUTIL_LIBRARY)
 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 ##########################################
 
index 948a986c49aa12a2f3830fae384a8e4b6dd173dc..468e5d6d4d7fdaecf6a8fbe3773c6b85fd424014 100644 (file)
 
 #cmakedefine HAVE_ASM_PAUSE      1
 
+#cmakedefine BUILD_STATIC        1
+
 #define RVERSION          "${RSPAMD_VERSION}"
 #define RSPAMD_MASTER_SITE_URL "${RSPAMD_MASTER_SITE_URL}"
 
 #include <signal.h>
 #include <event.h>
 #include <glib.h>
+
+#ifndef BUILD_STATIC
 #include <gmodule.h>
+#endif
 
 #ifndef NO_GMIME
 #include <gmime/gmime.h>
index 0f1be10471fb94eacb44d8b578fee564ea5f6b50..77a6e64eee68b3bd219eb5cfc872bc9baa637ef8 100644 (file)
@@ -50,6 +50,8 @@ extern PerlInterpreter         *perl_interpreter;
 #   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"
@@ -59,13 +61,15 @@ extern PerlInterpreter         *perl_interpreter;
 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;
@@ -76,6 +80,8 @@ static GList                   *custom_filters;
 
 static gboolean                 write_socket (void *arg);
 
+sig_atomic_t                    wanna_die = 0;
+
 #ifndef HAVE_SA_SIGINFO
 static void
 sig_handler (int signo)
@@ -84,18 +90,21 @@ static void
 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;
        }
 }
@@ -109,13 +118,15 @@ sigusr_handler (int fd, short what, void *arg)
        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;
 }
 
@@ -132,6 +143,7 @@ rcpt_destruct (void *pointer)
        }
 }
 
+#ifndef BUILD_STATIC   
 static void
 fin_custom_filters (struct worker_task *task)
 {
@@ -190,6 +202,19 @@ parse_line_custom (struct worker_task *task, f_str_t *in)
 
        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
@@ -457,6 +482,7 @@ accept_socket (int fd, short what, void *arg)
        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) {
@@ -470,10 +496,13 @@ accept_socket (int fd, short what, void *arg)
                /* 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;
@@ -503,7 +532,8 @@ load_custom_filter (const char *file)
                g_free (filt);
                return FALSE;
        }
-
+       
+       filt->init_func (cfg);
        filt->filename = g_strdup (file);
        custom_filters = g_list_prepend (custom_filters, filt);
 
@@ -526,7 +556,7 @@ load_custom_filters (struct rspamd_worker *worker, const char *path)
        }
        
        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;
                }
@@ -557,6 +587,8 @@ unload_custom_filters (void)
        g_list_free (custom_filters);
 }
 
+#endif
+
 /*
  * Start worker process
  */
@@ -589,13 +621,15 @@ start_worker (struct rspamd_worker *worker)
        /* 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 */
@@ -606,16 +640,20 @@ start_worker (struct rspamd_worker *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);
 }
 
 /*