summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-27 14:21:27 +0300
committerVsevolod Stakhov <vsevolod@rambler-co.ru>2009-03-27 14:21:27 +0300
commita83e5f18a2b6d9dc3196045867bcd842cfea3323 (patch)
tree5272d1159063abc10b92033f0a914aa2d36d06d2
parentfdccb337ed73f14b204721cf464ca03a7eca49b6 (diff)
downloadrspamd-a83e5f18a2b6d9dc3196045867bcd842cfea3323.tar.gz
rspamd-a83e5f18a2b6d9dc3196045867bcd842cfea3323.zip
* Add ability to build rspamd without perl support
* Fix creating of uinx socket * Improve some build issues
-rw-r--r--CMakeLists.txt112
-rw-r--r--config.h.in2
-rw-r--r--src/cfg_file.y5
-rw-r--r--src/cfg_utils.c1
-rw-r--r--src/filter.c9
-rw-r--r--src/main.c14
-rw-r--r--src/util.c4
-rw-r--r--src/worker.c6
8 files changed, 101 insertions, 52 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc9f50f8b..07e61b18b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -18,6 +18,7 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR)
OPTION(DEBUG_MODE "Enable debug output [default: ON]" ON)
OPTION(ENABLE_OPTIMIZATION "Enable optimization [default: OFF]" OFF)
+OPTION(ENABLE_PERL "Enable perl support [default: ON]" ON)
OPTION(SKIP_RELINK_RPATH "Skip relinking and full RPATH for the install tree" OFF)
OPTION(ENABLE_REDIRECTOR "Enable redirector install [default: OFF]" OFF)
@@ -32,27 +33,33 @@ INCLUDE(CheckFunctionExists)
INCLUDE(CheckSymbolExists)
INCLUDE(CheckLibraryExists)
INCLUDE(FindPkgConfig)
-INCLUDE(FindPerl)
-
-IF(NOT PERL_EXECUTABLE)
- MESSAGE(FATAL_ERROR "Error: Perl is not found but is required")
-ENDIF(NOT PERL_EXECUTABLE)
-
-# Find perl libraries and cflags
-EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ccopts OUTPUT_VARIABLE PERL_CFLAGS)
-EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ldopts OUTPUT_VARIABLE PERL_LDFLAGS)
-STRING(REGEX REPLACE "[\r\n]" " " PERL_CFLAGS ${PERL_CFLAGS})
-STRING(REGEX REPLACE " +$" "" PERL_CFLAGS ${PERL_CFLAGS})
-STRING(REGEX REPLACE "[\r\n]" " " PERL_LDFLAGS ${PERL_LDFLAGS})
-STRING(REGEX REPLACE " +$" "" PERL_LDFLAGS ${PERL_LDFLAGS})
-# Handle DynaLoader
-STRING(REGEX MATCH "/[^ ]*/DynaLoader.a" PERL_DYNALOADER ${PERL_LDFLAGS})
-STRING(REGEX REPLACE "/[^ ]*/DynaLoader.a " "" PERL_LDFLAGS ${PERL_LDFLAGS})
-
-IF(PERL_DYNALOADER)
- EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy ${PERL_DYNALOADER} ${rspamd_BINARY_DIR}/compat/libdynaloader.so)
- LINK_DIRECTORIES(${rspamd_BINARY_DIR}/compat/)
-ENDIF(PERL_DYNALOADER)
+
+IF(ENABLE_PERL MATCHES "ON")
+
+ INCLUDE(FindPerl)
+
+ IF(NOT PERL_EXECUTABLE)
+ MESSAGE(FATAL_ERROR "Error: Perl is not found but is required")
+ ENDIF(NOT PERL_EXECUTABLE)
+
+ # Find perl libraries and cflags
+ EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ccopts OUTPUT_VARIABLE PERL_CFLAGS)
+ EXECUTE_PROCESS(COMMAND ${PERL_EXECUTABLE} -MExtUtils::Embed -e ldopts OUTPUT_VARIABLE PERL_LDFLAGS)
+ STRING(REGEX REPLACE "[\r\n]" " " PERL_CFLAGS ${PERL_CFLAGS})
+ STRING(REGEX REPLACE " +$" "" PERL_CFLAGS ${PERL_CFLAGS})
+ STRING(REGEX REPLACE "[\r\n]" " " PERL_LDFLAGS ${PERL_LDFLAGS})
+ STRING(REGEX REPLACE " +$" "" PERL_LDFLAGS ${PERL_LDFLAGS})
+ # Handle DynaLoader
+ STRING(REGEX MATCH "/[^ ]*/DynaLoader.a" PERL_DYNALOADER ${PERL_LDFLAGS})
+ STRING(REGEX REPLACE "/[^ ]*/DynaLoader.a " "" PERL_LDFLAGS ${PERL_LDFLAGS})
+
+ IF(PERL_DYNALOADER)
+ EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy ${PERL_DYNALOADER} ${rspamd_BINARY_DIR}/compat/libdynaloader.so)
+ LINK_DIRECTORIES(${rspamd_BINARY_DIR}/compat/)
+ ENDIF(PERL_DYNALOADER)
+ELSE(ENABLE_PERL MATCHES "ON")
+ SET(WITHOUT_PERL 1)
+ENDIF(ENABLE_PERL MATCHES "ON")
# Lex and yacc
FIND_PROGRAM(LEX_EXECUTABLE lex)
@@ -214,6 +221,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_WARN_FLAGS} -std=c99")
# Platform specific routines
IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_BSD_SOURCE -DFREEBSD")
CONFIGURE_FILE(freebsd/rspamd.sh.in freebsd/rspamd.sh @ONLY)
IF(ENABLE_REDIRECTOR MATCHES "ON")
@@ -222,6 +230,10 @@ IF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
ENDIF(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
+IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE -DLINUX")
+ENDIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+
IF(ENABLE_REDIRECTOR MATCHES "ON")
CONFIGURE_FILE(utils/redirector.pl.in utils/redirector.pl @ONLY)
ENDIF(ENABLE_REDIRECTOR MATCHES "ON")
@@ -238,7 +250,6 @@ SET(RSPAMDSRC src/modules.c
src/upstream.c
src/statfile.c
src/protocol.c
- src/perl.c
src/message.c
src/fuzzy.c
src/expressions.c
@@ -253,6 +264,10 @@ SET(RSPAMDSRC src/modules.c
src/lmtp.c
src/lmtp_proto.c)
+IF(ENABLE_PERL MATCHES "ON")
+ LIST(APPEND RSPAMDSRC src/perl.c)
+ENDIF(ENABLE_PERL MATCHES "ON")
+
SET(TOKENIZERSSRC src/tokenizers/tokenizers.c
src/tokenizers/osb.c)
@@ -303,17 +318,19 @@ ADD_CUSTOM_COMMAND(OUTPUT src/modules.c
COMMAND ../utils/gen-modules.sh ${PLUGINSSRC}
WORKING_DIRECTORY src)
-ADD_CUSTOM_COMMAND(OUTPUT perl/Makefile
- COMMAND ${PERL_EXECUTABLE} ./Makefile.PL
- WORKING_DIRECTORY perl)
-ADD_CUSTOM_TARGET(perlxs
- COMMAND make
- DEPENDS perl/Makefile
- WORKING_DIRECTORY perl
- VERBATIM)
+IF(ENABLE_PERL MATCHES "ON")
+ ADD_CUSTOM_COMMAND(OUTPUT perl/Makefile
+ COMMAND ${PERL_EXECUTABLE} ./Makefile.PL
+ WORKING_DIRECTORY perl)
+ ADD_CUSTOM_TARGET(perlxs
+ COMMAND make
+ DEPENDS perl/Makefile
+ WORKING_DIRECTORY perl
+ VERBATIM)
+ CONFIGURE_FILE(perl/Makefile.PL.in perl/Makefile.PL)
+ENDIF(ENABLE_PERL MATCHES "ON")
CONFIGURE_FILE(config.h.in src/config.h)
-CONFIGURE_FILE(perl/Makefile.PL.in perl/Makefile.PL)
CONFIGURE_FILE(rspamc.pl.in rspamc.pl @ONLY)
ADD_EXECUTABLE(rspamd ${RSPAMDSRC} ${CONTRIBSRC} ${TOKENIZERSSRC}
@@ -321,34 +338,41 @@ ADD_EXECUTABLE(rspamd ${RSPAMDSRC} ${CONTRIBSRC} ${TOKENIZERSSRC}
${LEX_OUTPUT})
SET_TARGET_PROPERTIES(rspamd PROPERTIES LINKER_LANGUAGE C)
SET_TARGET_PROPERTIES(rspamd PROPERTIES VERSION ${RSPAMD_VERSION})
-SET_TARGET_PROPERTIES(rspamd PROPERTIES COMPILE_FLAGS ${PERL_CFLAGS}
- LINK_FLAGS ${PERL_LDFLAGS})
-TARGET_LINK_LIBRARIES(rspamd ${GLIB2_LIBRARIES})
+
+IF(ENABLE_PERL MATCHES "ON")
+
+ SET_TARGET_PROPERTIES(rspamd PROPERTIES COMPILE_FLAGS ${PERL_CFLAGS}
+ LINK_FLAGS ${PERL_LDFLAGS})
+ IF(PERL_DYNALOADER)
+ TARGET_LINK_LIBRARIES(rspamd dynaloader)
+ ENDIF(PERL_DYNALOADER)
+ ADD_DEPENDENCIES(rspamd perlxs ${LEX_OUTPUT} ${YACC_OUTPUT})
+
+ENDIF(ENABLE_PERL MATCHES "ON")
+
+TARGET_LINK_LIBRARIES(rspamd m)
TARGET_LINK_LIBRARIES(rspamd event)
-IF(PERL_DYNALOADER)
- TARGET_LINK_LIBRARIES(rspamd dynaloader)
-ENDIF(PERL_DYNALOADER)
+TARGET_LINK_LIBRARIES(rspamd ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(rspamd ${GMIME2_LIBRARIES})
-ADD_DEPENDENCIES(rspamd perlxs ${LEX_OUTPUT} ${YACC_OUTPUT})
ADD_EXECUTABLE(test/rspamd-test ${TESTDEPENDS} ${CONTRIBSRC} ${TESTSRC})
SET_TARGET_PROPERTIES(test/rspamd-test PROPERTIES LINKER_LANGUAGE C)
-SET_TARGET_PROPERTIES(test/rspamd-test PROPERTIES COMPILE_FLAGS ${PERL_CFLAGS}
- LINK_FLAGS ${PERL_LDFLAGS})
-TARGET_LINK_LIBRARIES(test/rspamd-test ${GLIB2_LIBRARIES})
+TARGET_LINK_LIBRARIES(test/rspamd-test m)
TARGET_LINK_LIBRARIES(test/rspamd-test event)
+TARGET_LINK_LIBRARIES(test/rspamd-test ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(test/rspamd-test ${GMIME2_LIBRARIES})
ADD_EXECUTABLE(utils/url-extracter ${UTILSDEPENDS} ${CONTRIBSRC} ${UTILSSRC})
SET_TARGET_PROPERTIES(utils/url-extracter PROPERTIES LINKER_LANGUAGE C)
-SET_TARGET_PROPERTIES(utils/url-extracter PROPERTIES COMPILE_FLAGS ${PERL_CFLAGS}
- LINK_FLAGS ${PERL_LDFLAGS})
+TARGET_LINK_LIBRARIES(utils/url-extracter m)
TARGET_LINK_LIBRARIES(utils/url-extracter ${GLIB2_LIBRARIES})
TARGET_LINK_LIBRARIES(utils/url-extracter ${GMIME2_LIBRARIES})
INSTALL(PROGRAMS rspamd-${RSPAMD_VERSION} DESTINATION bin RENAME rspamd)
INSTALL(PROGRAMS rspamc.pl DESTINATION bin RENAME rspamc)
-INSTALL(CODE "EXECUTE_PROCESS(COMMAND make install WORKING_DIRECTORY perl)")
+IF(ENABLE_PERL MATCHES "ON")
+ INSTALL(CODE "EXECUTE_PROCESS(COMMAND make install WORKING_DIRECTORY perl)")
+ENDIF(ENABLE_PERL MATCHES "ON")
IF(ENABLE_REDIRECTOR MATCHES "ON")
INSTALL(PROGRAMS utils/redirector.pl DESTINATION bin RENAME rspamd-redirector)
diff --git a/config.h.in b/config.h.in
index a2162144b..5aee03618 100644
--- a/config.h.in
+++ b/config.h.in
@@ -94,6 +94,8 @@
#cmakedefine HAVE_CLOCK_VIRTUAL 1
#cmakedefine HAVE_CLOCK_PROCESS_CPUTIME_ID 1
+#cmakedefine WITHOUT_PERL 1
+
#define RVERSION "${RSPAMD_VERSION}"
#define RSPAMD_MASTER_SITE_URL "${RSPAMD_MASTER_SITE_URL}"
diff --git a/src/cfg_file.y b/src/cfg_file.y
index 7e86c3d9f..a12e047c4 100644
--- a/src/cfg_file.y
+++ b/src/cfg_file.y
@@ -385,6 +385,7 @@ requirebody:
requirecmd:
MODULE EQSIGN QUOTEDSTRING {
+#ifndef WITHOUT_PERL
struct stat st;
struct perl_module *cur;
if (stat ($3, &st) == -1) {
@@ -398,6 +399,10 @@ requirecmd:
}
cur->path = $3;
LIST_INSERT_HEAD (&cfg->perl_modules, cur, next);
+#else
+ yyerror ("require command is not available when perl support is not compiled");
+ YYERROR;
+#endif
}
;
diff --git a/src/cfg_utils.c b/src/cfg_utils.c
index a9be83545..b7c540ec4 100644
--- a/src/cfg_utils.c
+++ b/src/cfg_utils.c
@@ -25,6 +25,7 @@
#include "config.h"
#include <math.h>
+
#include "cfg_file.h"
#include "main.h"
#include "filter.h"
diff --git a/src/filter.c b/src/filter.c
index d273a21ff..801b2f8bb 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -32,12 +32,15 @@
#include "main.h"
#include "message.h"
#include "cfg_file.h"
-#include "perl.h"
#include "util.h"
#include "expressions.h"
#include "classifiers/classifiers.h"
#include "tokenizers/tokenizers.h"
+#ifndef WITHOUT_PERL
+#include "perl.h"
+#endif
+
void
insert_result (struct worker_task *task, const char *metric_name, const char *symbol, double flag, GList *opts)
{
@@ -168,6 +171,7 @@ call_filter_by_name (struct worker_task *task, const char *name, enum filter_typ
break;
case PERL_FILTER:
res = 1;
+#ifndef WITHOUT_PERL
switch (sc_type) {
case SCRIPT_HEADER:
perl_call_header_filter (name, task);
@@ -182,6 +186,9 @@ call_filter_by_name (struct worker_task *task, const char *name, enum filter_typ
perl_call_message_filter (name, task);
break;
}
+#else
+ msg_err ("call_filter_by_name: trying to call perl function while perl support is disabled %s", name);
+#endif
break;
}
diff --git a/src/main.c b/src/main.c
index 90bf92156..bbe24dd1b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -26,9 +26,12 @@
#include "main.h"
#include "cfg_file.h"
#include "util.h"
-#include "perl.h"
#include "lmtp.h"
+#ifndef WITHOUT_PERL
+#include "perl.h"
+#endif
+
/* 2 seconds to fork new process in place of dead one */
#define SOFT_FORK_TIME 2
@@ -45,11 +48,13 @@ sig_atomic_t got_alarm;
extern int yynerrs;
extern FILE *yyin;
-extern void xs_init(pTHX);
static int dump_vars = 0;
+#ifndef WITHOUT_PERL
+extern void xs_init(pTHX);
extern PerlInterpreter *perl_interpreter;
+#endif
/* List of workers that are pending to start */
static GList *workers_pending = NULL;
@@ -378,7 +383,9 @@ main (int argc, char **argv, char **env)
struct rspamd_worker *cur, *cur_tmp, *active_worker;
FILE *f;
pid_t wrk;
+#ifndef WITHOUT_PERL
char *args[] = { "", "-e", "0", NULL };
+#endif
rspamd = (struct rspamd_main *)g_malloc (sizeof (struct rspamd_main));
bzero (rspamd, sizeof (struct rspamd_main));
@@ -521,6 +528,7 @@ main (int argc, char **argv, char **env)
exit (-errno);
}
+#ifndef WITHOUT_PERL
/* Init perl interpreter */
dTHXa (perl_interpreter);
PERL_SYS_INIT3 (&argc, &argv, &env);
@@ -533,6 +541,8 @@ main (int argc, char **argv, char **env)
PERL_SET_CONTEXT (perl_interpreter);
perl_construct (perl_interpreter);
perl_parse (perl_interpreter, xs_init, 3, args, NULL);
+#endif
+
/* Block signals to use sigsuspend in future */
sigprocmask(SIG_BLOCK, &signals.sa_mask, NULL);
diff --git a/src/util.c b/src/util.c
index 64f8910e6..bedb4114d 100644
--- a/src/util.c
+++ b/src/util.c
@@ -172,10 +172,10 @@ make_unix_socket (const char *path, struct sockaddr_un *addr, gboolean is_server
}
if (is_server) {
setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (const void *) &on, sizeof(int));
- r = bind (fd, (struct sockaddr *)&sin, sizeof (struct sockaddr_in));
+ r = bind (fd, (struct sockaddr *)addr, sizeof (struct sockaddr_in));
}
else {
- r = connect (fd, (struct sockaddr *)&sin, sizeof (struct sockaddr_in));
+ r = connect (fd, (struct sockaddr *)addr, sizeof (struct sockaddr_in));
}
if (r == -1) {
diff --git a/src/worker.c b/src/worker.c
index 02fcc8707..1f1548dd1 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -36,15 +36,15 @@
#include "modules.h"
#include "message.h"
+#ifndef WITHOUT_PERL
#include <EXTERN.h> /* from the Perl distribution */
#include <perl.h> /* from the Perl distribution */
-#define TASK_POOL_SIZE 4095
+extern PerlInterpreter *perl_interpreter;
+#endif
static struct timeval io_tv;
-extern PerlInterpreter *perl_interpreter;
-
static void write_socket (void *arg);
static