Browse Source

* Fix strict aliasing while compiling with optimization

* Fix tanhl detection for platforms that have not implementation of it
* Remove several compile warnings
tags/0.3.1
Vsevolod Stakhov 14 years ago
parent
commit
0612e84b3c

+ 1
- 0
CMakeLists.txt View File

@@ -280,6 +280,7 @@ CHECK_FUNCTION_EXISTS(vfork HAVE_VFORK)
CHECK_FUNCTION_EXISTS(wait4 HAVE_WAIT4)
CHECK_FUNCTION_EXISTS(waitpid HAVE_WAITPID)
CHECK_FUNCTION_EXISTS(flock HAVE_FLOCK)
CHECK_FUNCTION_EXISTS(tanhl HAVE_TANHL)

CHECK_SYMBOL_EXISTS(PATH_MAX limits.h HAVE_PATH_MAX)
CHECK_SYMBOL_EXISTS(MAXPATHLEN sys/param.h HAVE_MAXPATHLEN)

+ 2
- 0
config.h.in View File

@@ -96,6 +96,8 @@

#cmakedefine HAVE_FLOCK 1

#cmakedefine HAVE_TANHL 1

#cmakedefine HAVE_SA_SIGINFO 1

#cmakedefine DEBUG_MODE 1

+ 8
- 0
src/cfg_utils.c View File

@@ -727,7 +727,15 @@ internal_normalizer_func (struct config_file *cfg, long double score, void *data
return score;
}
else {
#ifdef HAVE_TANHL
return max * tanhl (score / max);
#else
/*
* As some implementations of libm does not support tanhl, try to use
* tanh
*/
return max * tanh ((double) (score / max));
#endif
}

return score;

+ 12
- 5
src/cfg_xml.c View File

@@ -744,11 +744,12 @@ handle_lua (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable
lua_file = basename (tmp2);
if (lua_dir && lua_file) {
cur_dir = g_malloc (PATH_MAX);
getcwd (cur_dir, PATH_MAX);
if (chdir (lua_dir) != -1) {
if (getcwd (cur_dir, PATH_MAX) != NULL && chdir (lua_dir) != -1) {
if (luaL_dofile (L, lua_file) != 0) {
msg_err ("cannot load lua file %s: %s", val, lua_tostring (L, -1));
chdir (cur_dir);
if (chdir (cur_dir) == -1) {
msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno));;
}
g_free (cur_dir);
g_free (tmp1);
g_free (tmp2);
@@ -757,14 +758,18 @@ handle_lua (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GHashTable
}
else {
msg_err ("cannot chdir to %s: %s", lua_dir, strerror (errno));;
chdir (cur_dir);
if (chdir (cur_dir) == -1) {
msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno));;
}
g_free (cur_dir);
g_free (tmp1);
g_free (tmp2);
return FALSE;
}
chdir (cur_dir);
if (chdir (cur_dir) == -1) {
msg_err ("cannot chdir to %s: %s", cur_dir, strerror (errno));;
}
g_free (cur_dir);
g_free (tmp1);
g_free (tmp2);
@@ -814,9 +819,11 @@ handle_module_path (struct config_file *cfg, struct rspamd_xml_userdata *ctx, GH
cfg->script_modules = g_list_prepend (cfg->script_modules, cur);
}
globfree (&globbuf);
g_free (pattern);
}
else {
msg_err ("glob failed: %s", strerror (errno));
g_free (pattern);
return FALSE;
}
}

+ 1
- 1
src/classifiers/winnow.c View File

@@ -335,7 +335,7 @@ winnow_learn (struct classifier_ctx *ctx, statfile_pool_t *pool, stat_file_t *fi
char *value;
int nodes, minnodes, iterations = 0;
struct statfile *st;
stat_file_t *sel;
stat_file_t *sel = NULL;
long double res = 0., max = 0.;
GList *cur;


+ 1
- 1
src/evdns/CMakeLists.txt View File

@@ -2,4 +2,4 @@
SET(EVDNSSRC evdns.c)

ADD_LIBRARY(rspamd_evdns STATIC ${EVDNSSRC})
SET_TARGET_PROPERTIES(rspamd_evdns PROPERTIES COMPILE_FLAGS "-DRSPAMD_LIB")
SET_TARGET_PROPERTIES(rspamd_evdns PROPERTIES COMPILE_FLAGS "-fno-strict-aliasing -DRSPAMD_LIB")

+ 2
- 1
src/expressions.c View File

@@ -1306,9 +1306,10 @@ is_recipient_list_sorted (const InternetAddressList * ia)
return FALSE;
}
#ifdef GMIME24
num = internet_address_list_length ((InternetAddressList *)ia);
cur = ia;
for (i = 0; i < num; i ++) {
addr = internet_address_list_get_address (cur, i);
addr = internet_address_list_get_address ((InternetAddressList *)cur, i);
current.addr = (char *)internet_address_get_name (addr);
if (previous.addr != NULL) {
if (g_ascii_strcasecmp (current.addr, previous.addr) < 0) {

+ 7
- 9
src/lmtp.c View File

@@ -224,14 +224,13 @@ static void
accept_socket (int fd, short what, void *arg)
{
struct rspamd_worker *worker = (struct rspamd_worker *)arg;
struct sockaddr_storage ss;
struct sockaddr_in *sin;
union sa_union su;
struct worker_task *new_task;
struct rspamd_lmtp_proto *lmtp;
socklen_t addrlen = sizeof (ss);
socklen_t addrlen = sizeof (su.ss);
int nfd;

if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
if ((nfd = accept_from_socket (fd, (struct sockaddr *)&su.ss, &addrlen)) == -1) {
msg_warn ("accept failed: %s", strerror (errno));
return;
}
@@ -240,14 +239,13 @@ accept_socket (int fd, short what, void *arg)

new_task = construct_task (worker);

if (ss.ss_family == AF_UNIX) {
if (su.ss.ss_family == AF_UNIX) {
msg_info ("accepted connection from unix socket");
new_task->client_addr.s_addr = INADDR_NONE;
}
else if (ss.ss_family == AF_INET) {
sin = (struct sockaddr_in *)&ss;
msg_info ("accepted connection from %s port %d", inet_ntoa (sin->sin_addr), ntohs (sin->sin_port));
memcpy (&new_task->client_addr, &sin->sin_addr, sizeof (struct in_addr));
else if (su.ss.ss_family == AF_INET) {
msg_info ("accepted connection from %s port %d", inet_ntoa (su.s4.sin_addr), ntohs (su.s4.sin_port));
memcpy (&new_task->client_addr, &su.s4.sin_addr, sizeof (struct in_addr));
}

new_task->sock = nfd;

+ 4
- 1
src/logger.c View File

@@ -118,7 +118,10 @@ direct_write_log_line (void *data, int count, gboolean is_iov)
}
else if (errno == EFAULT || errno == EINVAL || errno == EFBIG || errno == ENOSPC) {
/* Rare case */
(void)write (rspamd_log->fd, errmsg, r);
if (write (rspamd_log->fd, errmsg, r) == -1) {
/* Don't know what to do */
exit (EXIT_FAILURE);
}
}
else if (errno == EPIPE) {
/* We write to some pipe and it disappears, disable logging */

+ 8
- 0
src/main.h View File

@@ -122,6 +122,14 @@ struct save_point {
};


/**
* Union that would be used for storing sockaddrs
*/
union sa_union {
struct sockaddr_storage ss;
struct sockaddr_in s4;
struct sockaddr_in6 s6;
};

/**
* Control session object

+ 3
- 1
src/memcached.c View File

@@ -139,7 +139,9 @@ write_handler (int fd, short what, memcached_ctx_t * ctx)
iov[1].iov_len = ctx->param->bufsize - ctx->param->bufpos;
iov[2].iov_base = CRLF;
iov[2].iov_len = sizeof (CRLF) - 1;
writev (ctx->sock, iov, 3);
if (writev (ctx->sock, iov, 3) == -1) {
memc_log (ctx, __LINE__, "memc_write: writev failed: %s", strerror (errno));
}
}
event_del (&ctx->mem_ev);
event_set (&ctx->mem_ev, ctx->sock, EV_READ | EV_PERSIST | EV_TIMEOUT, socket_callback, (void *)ctx);

+ 3
- 3
src/plugins/custom/ipmark/ipmark.c View File

@@ -175,7 +175,7 @@ read_radix_file (void)
FILE *f;
char buf[BUFSIZ];
struct in_addr ina;
int mask, value;
int mask = 0, value = 0;

f = fopen (filename, "r");
if (f != NULL) {
@@ -260,9 +260,9 @@ parse_line (const char *line, size_t len, char **output, void *user_data)
char *c = ip_buf, *err_str;
struct in_addr ina;
int state = 0, next_state = 0, dots = 0;
int16_t value;
int16_t value = 0;
uint32_t mask;
enum ipmark_command cmd;
enum ipmark_command cmd = COMMAND_ADD;

/* Parse input line */
p = line;

+ 3
- 3
src/settings.c View File

@@ -344,7 +344,7 @@ check_whitelist(struct worker_task *task, struct rspamd_settings *s)
gboolean
check_metric_settings (struct worker_task * task, struct metric * metric, double *score, double *rscore)
{
struct rspamd_settings *us, *ds;
struct rspamd_settings *us = NULL, *ds = NULL;
double *sc, *rs;

*rscore = DEFAULT_REJECT_SCORE;
@@ -393,7 +393,7 @@ check_metric_settings (struct worker_task * task, struct metric * metric, double
gboolean
check_factor_settings (struct worker_task * task, const char *symbol, double *factor)
{
struct rspamd_settings *us, *ds;
struct rspamd_settings *us = NULL, *ds = NULL;
double *fc;

if (check_setting (task, &us, &ds)) {
@@ -425,7 +425,7 @@ check_factor_settings (struct worker_task * task, const char *symbol, double *fa
gboolean
check_want_spam (struct worker_task * task)
{
struct rspamd_settings *us, *ds;
struct rspamd_settings *us = NULL, *ds = NULL;

if (check_setting (task, &us, &ds)) {
if (us != NULL) {

+ 8
- 10
src/smtp.c View File

@@ -326,14 +326,13 @@ static void
accept_socket (int fd, short what, void *arg)
{
struct rspamd_worker *worker = (struct rspamd_worker *)arg;
struct sockaddr_storage ss;
struct sockaddr_in *sin;
union sa_union su;
struct smtp_session *session;

socklen_t addrlen = sizeof (ss);
socklen_t addrlen = sizeof (su.ss);
int nfd;

if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
if ((nfd = accept_from_socket (fd, (struct sockaddr *)&su.ss, &addrlen)) == -1) {
msg_warn ("accept failed: %s", strerror (errno));
return;
}
@@ -345,14 +344,13 @@ accept_socket (int fd, short what, void *arg)
session = g_malloc (sizeof (struct smtp_session));
session->pool = memory_pool_new (memory_pool_get_size ());

if (ss.ss_family == AF_UNIX) {
if (su.ss.ss_family == AF_UNIX) {
msg_info ("accepted connection from unix socket");
session->client_addr.s_addr = INADDR_NONE;
}
else if (ss.ss_family == AF_INET) {
sin = (struct sockaddr_in *)&ss;
msg_info ("accepted connection from %s port %d", inet_ntoa (sin->sin_addr), ntohs (sin->sin_port));
memcpy (&session->client_addr, &sin->sin_addr, sizeof (struct in_addr));
else if (su.ss.ss_family == AF_INET) {
msg_info ("accepted connection from %s port %d", inet_ntoa (su.s4.sin_addr), ntohs (su.s4.sin_port));
memcpy (&session->client_addr, &su.s4.sin_addr, sizeof (struct in_addr));
}

session->sock = nfd;
@@ -380,7 +378,7 @@ static void
parse_smtp_banner (struct smtp_worker_ctx *ctx, const char *line)
{
int hostmax, banner_len = sizeof ("220 ") - 1;
char *p, *t, *hostbuf;
char *p, *t, *hostbuf = NULL;
gboolean has_crlf = FALSE;

p = (char *)line;

+ 1
- 1
src/statfile.c View File

@@ -418,7 +418,7 @@ statfile_pool_create (statfile_pool_t * pool, char *filename, size_t size)
};
struct stat_file_block block = { 0, 0, 0 };
int fd;
unsigned int buflen, nblocks;
unsigned int buflen = 0, nblocks;
char *buf = NULL;

if (statfile_pool_is_open (pool, filename) != NULL) {

+ 1
- 1
src/symbols_cache.c View File

@@ -525,7 +525,7 @@ call_symbol_callback (struct worker_task * task, struct symbols_cache * cache, g
{
struct timespec ts1, ts2;
uint64_t diff;
struct cache_item *item;
struct cache_item *item = NULL;
struct symbol_callback_data *s = *save;

if (s == NULL) {

+ 7
- 9
src/worker.c View File

@@ -443,16 +443,15 @@ static void
accept_socket (int fd, short what, void *arg)
{
struct rspamd_worker *worker = (struct rspamd_worker *)arg;
struct sockaddr_storage ss;
struct sockaddr_in *sin;
union sa_union su;
struct worker_task *new_task;
GList *cur;
struct custom_filter *filt;

socklen_t addrlen = sizeof (ss);
socklen_t addrlen = sizeof (su.ss);
int nfd;

if ((nfd = accept_from_socket (fd, (struct sockaddr *)&ss, &addrlen)) == -1) {
if ((nfd = accept_from_socket (fd, (struct sockaddr *)&su.ss, &addrlen)) == -1) {
msg_warn ("accept failed: %s", strerror (errno));
return;
}
@@ -463,14 +462,13 @@ accept_socket (int fd, short what, void *arg)
new_task = construct_task (worker);

if (ss.ss_family == AF_UNIX) {
if (su.ss.ss_family == AF_UNIX) {
msg_info ("accepted connection from unix socket");
new_task->client_addr.s_addr = INADDR_NONE;
}
else if (ss.ss_family == AF_INET) {
sin = (struct sockaddr_in *)&ss;
msg_info ("accepted connection from %s port %d", inet_ntoa (sin->sin_addr), ntohs (sin->sin_port));
memcpy (&new_task->client_addr, &sin->sin_addr, sizeof (struct in_addr));
else if (su.ss.ss_family == AF_INET) {
msg_info ("accepted connection from %s port %d", inet_ntoa (su.s4.sin_addr), ntohs (su.s4.sin_port));
memcpy (&new_task->client_addr, &su.s4.sin_addr, sizeof (struct in_addr));
}

new_task->sock = nfd;

Loading…
Cancel
Save