From 7e66b3bd08dbca9356013a3777f786076d1dacea Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Wed, 30 Apr 2014 12:45:17 +0100 Subject: [PATCH] Rework worker utilities. --- src/libmime/CMakeLists.txt | 3 +- src/libserver/CMakeLists.txt | 4 +- src/{libmime => libserver}/worker_util.c | 0 src/libserver/worker_util.h | 67 ++++++++++++++++++++++++ src/libutil/util.h | 7 --- src/main.h | 32 +---------- 6 files changed, 72 insertions(+), 41 deletions(-) rename src/{libmime => libserver}/worker_util.c (100%) create mode 100644 src/libserver/worker_util.h diff --git a/src/libmime/CMakeLists.txt b/src/libmime/CMakeLists.txt index 303b7a088..e612dce19 100644 --- a/src/libmime/CMakeLists.txt +++ b/src/libmime/CMakeLists.txt @@ -6,8 +6,7 @@ SET(LIBRSPAMDMIMESRC message.c protocol.c smtp_utils.c - smtp_proto.c - worker_util.c) + smtp_proto.c) # Librspamdmime ADD_LIBRARY(rspamd-mime ${LINK_TYPE} ${LIBRSPAMDMIMESRC}) diff --git a/src/libserver/CMakeLists.txt b/src/libserver/CMakeLists.txt index bd5df18b9..99a4debb2 100644 --- a/src/libserver/CMakeLists.txt +++ b/src/libserver/CMakeLists.txt @@ -17,7 +17,9 @@ SET(LIBRSPAMDSERVERSRC statfile_sync.c symbols_cache.c task.c - url.c) + url.c + worker_util.c) + SET(TOKENIZERSSRC ../tokenizers/tokenizers.c ../tokenizers/osb.c) diff --git a/src/libmime/worker_util.c b/src/libserver/worker_util.c similarity index 100% rename from src/libmime/worker_util.c rename to src/libserver/worker_util.c diff --git a/src/libserver/worker_util.h b/src/libserver/worker_util.h new file mode 100644 index 000000000..d88b93a8a --- /dev/null +++ b/src/libserver/worker_util.h @@ -0,0 +1,67 @@ +/* Copyright (c) 2014, Vsevolod Stakhov + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED ''AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL AUTHOR BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef WORKER_UTIL_H_ +#define WORKER_UTIL_H_ + +#include "config.h" +#include "util.h" + +/** + * Return worker's control structure by its type + * @param type + * @return worker's control structure or NULL + */ +worker_t* get_worker_by_type (GQuark type); + +/** + * Set counter for a symbol + */ +double set_counter (const gchar *name, guint32 value); + +#ifndef HAVE_SA_SIGINFO +typedef void (*rspamd_sig_handler_t) (gint); +#else +typedef void (*rspamd_sig_handler_t) (gint, siginfo_t *, void *); +#endif + +struct rspamd_worker; + +/** + * Prepare worker's startup + * @param worker worker structure + * @param name name of the worker + * @param sig_handler handler of main signals + * @param accept_handler handler of accept event for listen sockets + * @return event base suitable for a worker + */ +struct event_base * +prepare_worker (struct rspamd_worker *worker, const char *name, + void (*accept_handler)(int, short, void *)); + +/** + * Stop accepting new connections for a worker + * @param worker + */ +void worker_stop_accept (struct rspamd_worker *worker); + +#endif /* WORKER_UTIL_H_ */ diff --git a/src/libutil/util.h b/src/libutil/util.h index 4359d4288..dfa34a458 100644 --- a/src/libutil/util.h +++ b/src/libutil/util.h @@ -259,13 +259,6 @@ gboolean rspamd_strtoul (const gchar *s, gsize len, gulong *value); */ gint rspamd_fallocate (gint fd, off_t offset, off_t len); -/** - * Return worker's control structure by its type - * @param type - * @return worker's control structure or NULL - */ -extern worker_t* get_worker_by_type (GQuark type); - /** * Utils for working with threads to be compatible with all glib versions */ diff --git a/src/main.h b/src/main.h index 57a7907e5..d93c00e09 100644 --- a/src/main.h +++ b/src/main.h @@ -22,6 +22,7 @@ #include "roll_history.h" #include "http.h" #include "task.h" +#include "worker_util.h" /* Default values */ #define FIXED_CONFIG_FILE RSPAMD_CONFDIR "/rspamd.conf" @@ -195,37 +196,6 @@ void register_custom_controller_command (const gchar *name, controller_func_t ha */ extern struct rspamd_main *rspamd_main; -/* Worker task manipulations */ - -/** - * Set counter for a symbol - */ -double set_counter (const gchar *name, guint32 value); - -#ifndef HAVE_SA_SIGINFO -typedef void (*rspamd_sig_handler_t) (gint); -#else -typedef void (*rspamd_sig_handler_t) (gint, siginfo_t *, void *); -#endif - -/** - * Prepare worker's startup - * @param worker worker structure - * @param name name of the worker - * @param sig_handler handler of main signals - * @param accept_handler handler of accept event for listen sockets - * @return event base suitable for a worker - */ -struct event_base * -prepare_worker (struct rspamd_worker *worker, const char *name, - void (*accept_handler)(int, short, void *)); - -/** - * Stop accepting new connections for a worker - * @param worker - */ -void worker_stop_accept (struct rspamd_worker *worker); - #endif /* -- 2.39.5