]> source.dussan.org Git - rspamd.git/commitdiff
* Add limits support to each worker (max open files and max core size)
authorVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 18 Dec 2009 14:48:06 +0000 (17:48 +0300)
committerVsevolod Stakhov <vsevolod@rambler-co.ru>
Fri, 18 Dec 2009 14:48:06 +0000 (17:48 +0300)
* Fix dependency on lex and yacc sources

CMakeLists.txt
src/cfg_file.h
src/cfg_file.l
src/cfg_file.y
src/cfg_utils.c
src/main.c
src/plugins/spf.c

index 5d6678d67c825661659c49b4101ca207ced52f7a..cc652ee3b99983a4f785be83eab427b582546fa7 100644 (file)
@@ -443,15 +443,18 @@ STRING(REPLACE "_file.l" "_lex.c" LEX_OUTPUT ${LEX_SRC})
 ############################ TARGETS SECTION ###############################
 
 ADD_CUSTOM_COMMAND(OUTPUT ${LEX_OUTPUT}
-                                       COMMAND ${LEX_EXECUTABLE} -o${LEX_OUTPUT} ${LEX_SRC})
+                                       COMMAND ${LEX_EXECUTABLE} -o${LEX_OUTPUT} ${LEX_SRC}
+                                       DEPENDS ${LEX_SRC})
 ADD_CUSTOM_COMMAND(OUTPUT ${YACC_OUTPUT}
-                                       COMMAND ${YACC_EXECUTABLE} -d -o ${YACC_OUTPUT} ${YACC_SRC})
+                                       COMMAND ${YACC_EXECUTABLE} -d -o ${YACC_OUTPUT} ${YACC_SRC}
+                                       DEPENDS ${YACC_SRC})
 ADD_CUSTOM_COMMAND(OUTPUT src/modules.c
                                        COMMAND ../utils/gen-modules.sh ${PLUGINSSRC}
                                        WORKING_DIRECTORY src)
 
 IF(PERL_EXECUTABLE)
        ADD_CUSTOM_COMMAND(OUTPUT perl/Makefile 
+                                               PRE_BUILD
                                                COMMAND ${PERL_EXECUTABLE} ./Makefile.PL
                                                WORKING_DIRECTORY perl)
        CONFIGURE_FILE(perl/Makefile.PL.in perl/Makefile.PL)
index bb07a40c50e1f068e1bd200bda8a426ed4866927..16b59c45fb4999f0e62b4e0ae9b6f57d3604b94c 100644 (file)
@@ -197,8 +197,10 @@ struct worker_conf {
        uint16_t bind_port;                                                             /**< bind port in case of TCP socket                                    */
        uint16_t bind_family;                                                   /**< bind type (AF_UNIX or AF_INET)                                             */
        int count;                                                                              /**< number of workers                                                                  */
-       GHashTable *params;                                                             /**< params for worker                                                                  */
        int listen_sock;                                                                /**< listening socket desctiptor                                                */
+       uint32_t rlimit_nofile;                                                 /**< max files limit                                                                    */
+       uint32_t rlimit_maxcore;                                                /**< maximum core file size                                                             */
+       GHashTable *params;                                                             /**< params for worker                                                                  */
        GQueue *active_workers;                                                 /**< linked list of spawned workers                                             */
        gboolean has_socket;                                                    /**< whether we should make listening socket in main process */
 };
@@ -267,6 +269,7 @@ struct config_file {
        GList *views;                                                                   /**< views                                                                                              */
     GHashTable* domain_settings;                    /**< settings per-domains                               */
     GHashTable* user_settings;                      /**< settings per-user                                  */
+
 };
 
 /**
index fdb151b45ea19929bd7869a006adbc7f56d630bb..5eea28ba398cfad5ad9c478695652172b2c44d34 100644 (file)
@@ -63,6 +63,9 @@ settings                        return SETTINGS;
 user_settings                   return USER_SETTINGS;
 domain_settings                 return DOMAIN_SETTINGS;
 
+maxfiles                                               return MAXFILES;
+maxcore                                                        return MAXCORE;
+
 filters                                                        return FILTERS;
 factors                                                        return FACTORS;
 grow_factor                                            return GROW_FACTOR;
index 15a9a91dae4f86960e0c23f6f4f0b42a5b125fe1..a4f7034d0e1111e5628d15b144b7e1597019f529 100644 (file)
@@ -58,7 +58,7 @@ struct rspamd_view *cur_view = NULL;
 %token  STATFILE ALIAS PATTERN WEIGHT STATFILE_POOL_SIZE SIZE TOKENIZER CLASSIFIER BINLOG BINLOG_MASTER BINLOG_ROTATE
 %token DELIVERY LMTP ENABLED AGENT SECTION LUACODE RAW_MODE PROFILE_FILE COUNT
 %token  VIEW IP FROM SYMBOLS CLIENT_IP
-%token  AUTOLEARN MIN_MARK MAX_MARK
+%token  AUTOLEARN MIN_MARK MAX_MARK MAXFILES MAXCORE
 %token  SETTINGS USER_SETTINGS DOMAIN_SETTINGS SYMBOL PATH SKIP_CHECK GROW_FACTOR
 
 %type  <string>        STRING
@@ -229,6 +229,8 @@ workercmd:
        | bindsock
        | workertype
        | workercount
+       | workerlimitfiles
+       | workerlimitcore
        | workerparam
        ;
 
@@ -302,6 +304,20 @@ workercount:
        }
        ;
 
+workerlimitfiles:
+       MAXFILES EQSIGN NUMBER {
+               cur_worker = check_worker_conf (cfg, cur_worker);
+               cur_worker->rlimit_nofile = $3;
+       }
+       ;
+
+workerlimitcore:
+       MAXCORE EQSIGN NUMBER  {
+               cur_worker = check_worker_conf (cfg, cur_worker);
+               cur_worker->rlimit_maxcore = $3;
+       }
+       ;
+
 workerparam:
        STRING EQSIGN QUOTEDSTRING {
                cur_worker = check_worker_conf (cfg, cur_worker);
index f8518e1641c22fb0b64a711025d2e1b9d4877ab0..865c81f7f51a32809991c0c5ca37545089678421 100644 (file)
@@ -34,6 +34,9 @@
 
 #define DEFAULT_SCORE 10.0
 
+#define DEFAULT_RLIMIT_NOFILE 2048
+#define DEFAULT_RLIMIT_MAXCORE 0
+
 extern int                      yylineno;
 extern char                    *yytext;
 
@@ -644,6 +647,8 @@ check_worker_conf (struct config_file *cfg, struct worker_conf *c)
 #else
                c->count = DEFAULT_WORKERS_NUM;
 #endif
+               c->rlimit_nofile = DEFAULT_RLIMIT_NOFILE;
+               c->rlimit_maxcore = DEFAULT_RLIMIT_MAXCORE;
        }
        
        return c;
index 49ef09b5996a9580220c456701235cb62a7e3d38..dd17b98d1f3f21bcacfcf8cc11633b113234552d 100644 (file)
@@ -329,6 +329,31 @@ reread_config (struct rspamd_main *rspamd)
        }
 }
 
+static void
+set_worker_limits (struct worker_conf *cf)
+{
+       struct rlimit                   rlmt;
+
+       if (cf->rlimit_nofile != 0) {
+               rlmt.rlim_cur = (rlim_t) cf->rlimit_nofile;
+               rlmt.rlim_max = (rlim_t) cf->rlimit_nofile;
+
+               if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
+                       msg_warn ("set_worker_limits: cannot set files rlimit: %d, %s", cf->rlimit_nofile, strerror (errno));
+        }
+       }
+
+       if (cf->rlimit_maxcore != 0) {
+               rlmt.rlim_cur = (rlim_t) cf->rlimit_maxcore;
+               rlmt.rlim_max = (rlim_t) cf->rlimit_maxcore;
+
+               if (setrlimit(RLIMIT_CORE, &rlmt) == -1) {
+                       msg_warn ("set_worker_limits: cannot set max core rlimit: %d, %s", cf->rlimit_maxcore, strerror (errno));
+        }
+       }
+
+}
+
 static struct rspamd_worker    *
 fork_worker (struct rspamd_main *rspamd, struct worker_conf *cf)
 {
@@ -347,6 +372,8 @@ fork_worker (struct rspamd_main *rspamd, struct worker_conf *cf)
                case 0:
                        /* Drop privilleges */
                        drop_priv (cfg);
+                       /* Set limits */
+                       set_worker_limits (cf);
                        switch (cf->type) {
                        case TYPE_CONTROLLER:
                                setproctitle ("controller process");
index b597da1e580ca54a90f34f45bf3f34107d7481d4..581f08b84f34d7dda202b239d73878787b79d08d 100644 (file)
@@ -144,28 +144,30 @@ spf_plugin_callback (struct spf_record *record, struct worker_task *task)
                s = ntohl (task->from_addr.s_addr);
                while (cur) {
                        addr = cur->data;
-                       if (addr->mask == 0) {
-                               m = 0;
-                       }
-                       else {
-                               m = G_MAXUINT32 << (32 - addr->mask);
-                       }
-                       if ((s & m) == (addr->addr & m)) {
-                               switch (addr->mech) {
-                                       case SPF_FAIL:
-                                               insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_fail, 1, g_list_prepend (NULL, addr->spf_string));
-                                               break;
-                                       case SPF_SOFT_FAIL:
-                                       case SPF_NEUTRAL:
-                                               insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_softfail, 1, g_list_prepend (NULL, addr->spf_string));
-                                               break;
-                                       default:
-                                               insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_allow, 1, g_list_prepend (NULL, addr->spf_string));
-                                               break;
-                               }
-                               /* Stop parsing */
-                               break;
-                       }
+            if (addr != NULL) {
+                if (addr->mask == 0) {
+                    m = 0;
+                }
+                else {
+                    m = G_MAXUINT32 << (32 - addr->mask);
+                }
+                if ((s & m) == (addr->addr & m)) {
+                    switch (addr->mech) {
+                        case SPF_FAIL:
+                            insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_fail, 1, g_list_prepend (NULL, addr->spf_string));
+                            break;
+                        case SPF_SOFT_FAIL:
+                        case SPF_NEUTRAL:
+                            insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_softfail, 1, g_list_prepend (NULL, addr->spf_string));
+                            break;
+                        default:
+                            insert_result (task, spf_module_ctx->metric, spf_module_ctx->symbol_allow, 1, g_list_prepend (NULL, addr->spf_string));
+                            break;
+                    }
+                    /* Stop parsing */
+                    break;
+                }
+            }
                        cur = g_list_next (cur);
                }
        }