summaryrefslogtreecommitdiffstats
path: root/src/libutil
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-08 13:15:15 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-10-08 13:15:15 +0100
commiteb737947eb2afe98f9dac1121fa37d1b746c5657 (patch)
tree02aa7752555cc4a47b1a9b423066bbdc52a7e8c5 /src/libutil
parente0bfa35ee937940f20a5675bc7582cfc83c2866b (diff)
downloadrspamd-eb737947eb2afe98f9dac1121fa37d1b746c5657.tar.gz
rspamd-eb737947eb2afe98f9dac1121fa37d1b746c5657.zip
Reorganize includes to reduce namespace pollution.
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/addr.c11
-rw-r--r--src/libutil/addr.h15
-rw-r--r--src/libutil/aio_event.c2
-rw-r--r--src/libutil/http.c2
-rw-r--r--src/libutil/logger.c12
-rw-r--r--src/libutil/map.c1
-rw-r--r--src/libutil/map.h2
-rw-r--r--src/libutil/mem_pool.c5
-rw-r--r--src/libutil/printf.c6
-rw-r--r--src/libutil/rrd.c2
-rw-r--r--src/libutil/sqlite_utils.c1
-rw-r--r--src/libutil/str_util.c2
-rw-r--r--src/libutil/unix-std.h88
-rw-r--r--src/libutil/util.c27
-rw-r--r--src/libutil/util.h5
15 files changed, 171 insertions, 10 deletions
diff --git a/src/libutil/addr.c b/src/libutil/addr.c
index 4a48ab7e8..1c7f4dbdf 100644
--- a/src/libutil/addr.c
+++ b/src/libutil/addr.c
@@ -26,6 +26,17 @@
#include "util.h"
#include "logger.h"
+#include "unix-std.h"
+/* pwd and grp */
+#ifdef HAVE_PWD_H
+#include <pwd.h>
+#endif
+
+#ifdef HAVE_GRP_H
+#include <grp.h>
+#endif
+
+
enum {
RSPAMD_IPV6_UNDEFINED = 0,
RSPAMD_IPV6_SUPPORTED,
diff --git a/src/libutil/addr.h b/src/libutil/addr.h
index a13c14b53..affd87158 100644
--- a/src/libutil/addr.h
+++ b/src/libutil/addr.h
@@ -24,6 +24,21 @@
#define ADDR_H_
#include "config.h"
+
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+#include <arpa/inet.h>
+#endif
+/* unix sockets */
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+
#include "mem_pool.h"
/**
diff --git a/src/libutil/aio_event.c b/src/libutil/aio_event.c
index 0686bbd0d..0c3a6f4fb 100644
--- a/src/libutil/aio_event.c
+++ b/src/libutil/aio_event.c
@@ -22,8 +22,10 @@
*/
#include "config.h"
+#include <event.h>
#include "aio_event.h"
#include "rspamd.h"
+#include "unix-std.h"
#ifdef HAVE_SYS_EVENTFD_H
#include <sys/eventfd.h>
diff --git a/src/libutil/http.c b/src/libutil/http.c
index fe7ac2d53..f363969b4 100644
--- a/src/libutil/http.c
+++ b/src/libutil/http.c
@@ -32,7 +32,7 @@
#include "ottery.h"
#include "keypair_private.h"
#include "cryptobox.h"
-#include <limits.h>
+#include "unix-std.h"
#define ENCRYPTED_VERSION " HTTP/1.0"
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index 3367829a6..b83aa5cd6 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -29,6 +29,11 @@
#include "rspamd.h"
#include "map.h"
#include "xxhash.h"
+#include "unix-std.h"
+
+#ifdef HAVE_SYSLOG_H
+#include <syslog.h>
+#endif
/* How much message should be repeated before it is count to be repeated one */
#define REPEATS_MIN 3
@@ -174,9 +179,11 @@ rspamd_log_open_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
rspamd_log->enabled = TRUE;
return 0;
case RSPAMD_LOG_SYSLOG:
+#ifdef HAVE_SYSLOG_H
openlog ("rspamd", LOG_NDELAY | LOG_PID,
rspamd_log->cfg->log_facility);
rspamd_log->enabled = TRUE;
+#endif
return 0;
case RSPAMD_LOG_FILE:
rspamd_log->fd = open (rspamd_log->cfg->log_file,
@@ -212,7 +219,9 @@ rspamd_log_close_priv (rspamd_logger_t *rspamd_log, uid_t uid, gid_t gid)
/* Do nothing special */
break;
case RSPAMD_LOG_SYSLOG:
+#ifdef HAVE_SYSLOG_H
closelog ();
+#endif
break;
case RSPAMD_LOG_FILE:
if (rspamd_log->enabled) {
@@ -576,7 +585,7 @@ syslog_log_function (const gchar *log_domain,
gpointer arg)
{
rspamd_logger_t *rspamd_log = arg;
-
+#ifdef HAVE_SYSLOG_H
struct {
GLogLevelFlags glib_level;
gint syslog_level;
@@ -607,6 +616,7 @@ syslog_log_function (const gchar *log_domain,
module != NULL ? module : "",
function != NULL ? function : "",
message);
+#endif
}
/**
diff --git a/src/libutil/map.c b/src/libutil/map.c
index 28faf13c4..6c813a133 100644
--- a/src/libutil/map.c
+++ b/src/libutil/map.c
@@ -32,6 +32,7 @@
#include "util.h"
#include "mem_pool.h"
#include "blake2.h"
+#include "unix-std.h"
static const gchar *hash_fill = "1";
diff --git a/src/libutil/map.h b/src/libutil/map.h
index 64421ec1b..95c7de27b 100644
--- a/src/libutil/map.h
+++ b/src/libutil/map.h
@@ -2,6 +2,8 @@
#define RSPAMD_MAP_H
#include "config.h"
+#include <event.h>
+
#include "mem_pool.h"
#include "radix.h"
diff --git a/src/libutil/mem_pool.c b/src/libutil/mem_pool.c
index 849e70c03..e87a1578b 100644
--- a/src/libutil/mem_pool.c
+++ b/src/libutil/mem_pool.c
@@ -28,6 +28,11 @@
#include "logger.h"
#include "utlist.h"
#include "ottery.h"
+#include "unix-std.h"
+
+#ifdef HAVE_SCHED_YIELD
+#include <sched.h>
+#endif
/* Sleep time for spin lock in nanoseconds */
#define MUTEX_SLEEP_TIME 10000000L
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 3813524a0..67a2f3d98 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -25,7 +25,7 @@
#include "printf.h"
#include "fstring.h"
-#include "rspamd.h"
+#include <math.h>
/**
* From FreeBSD libutil code
@@ -449,7 +449,6 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
if (*fmt == '*') {
d = (gint)va_arg (args, gint);
if (G_UNLIKELY (d < 0)) {
- msg_err ("critical error: fraction width is less than 0");
return 0;
}
frac_width = (guint)d;
@@ -466,7 +465,6 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
case '*':
d = (gint)va_arg (args, gint);
if (G_UNLIKELY (d < 0)) {
- msg_err ("critical error: size is less than 0");
return 0;
}
slen = (glong)d;
@@ -715,7 +713,7 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
continue;
case 'N':
- c = LF;
+ c = '\n';
RSPAMD_PRINTF_APPEND (&c, 1);
continue;
diff --git a/src/libutil/rrd.c b/src/libutil/rrd.c
index b7bd75d08..c5793a590 100644
--- a/src/libutil/rrd.c
+++ b/src/libutil/rrd.c
@@ -26,6 +26,8 @@
#include "rrd.h"
#include "util.h"
#include "logger.h"
+#include "unix-std.h"
+#include <math.h>
#define msg_err_rrd(...) rspamd_default_log_function (G_LOG_LEVEL_CRITICAL, \
"rrd", file->id, \
diff --git a/src/libutil/sqlite_utils.c b/src/libutil/sqlite_utils.c
index 980d07abc..0458a0a02 100644
--- a/src/libutil/sqlite_utils.c
+++ b/src/libutil/sqlite_utils.c
@@ -25,6 +25,7 @@
#include "config.h"
#include "libutil/logger.h"
#include "libutil/sqlite_utils.h"
+#include "unix-std.h"
static GQuark
diff --git a/src/libutil/str_util.c b/src/libutil/str_util.c
index 96a26e1c1..9031305b0 100644
--- a/src/libutil/str_util.c
+++ b/src/libutil/str_util.c
@@ -25,8 +25,8 @@
#include "config.h"
#include "util.h"
-#include "mem_pool.h"
#include "xxhash.h"
+#include <math.h>
static const guchar lc_map[256] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
diff --git a/src/libutil/unix-std.h b/src/libutil/unix-std.h
new file mode 100644
index 000000000..988669c4b
--- /dev/null
+++ b/src/libutil/unix-std.h
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2015, 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 BY AUTHOR ''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 RSPAMD_UNIX_STD_H_H
+#define RSPAMD_UNIX_STD_H_H
+
+#include "config.h"
+
+/*
+ * Default unix system includes
+ */
+
+/* sys/file.h */
+#ifdef HAVE_SYS_FILE_H
+#include <sys/file.h>
+#endif
+
+/* sys/uio.h */
+#ifdef HAVE_SYS_UIO_H
+#include <sys/uio.h>
+#endif
+
+/* sys/mman */
+#ifdef HAVE_SYS_MMAN_H
+#include <sys/mman.h>
+#endif
+
+
+/* timedb */
+#ifdef HAVE_SYS_TIMEB_H
+#include <sys/timeb.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/* sysexits */
+#ifdef HAVE_SYSEXITS_H
+#include <sysexits.h>
+#endif
+
+/* strings */
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
+/* fcntl */
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+#endif
+
+#include <signal.h>
+
+#ifdef HAVE_LIBGEN_H
+#include <libgen.h>
+#endif
+
+#endif
diff --git a/src/libutil/util.c b/src/libutil/util.c
index daf427ef3..dae26a5c0 100644
--- a/src/libutil/util.c
+++ b/src/libutil/util.c
@@ -27,8 +27,7 @@
#include "util.h"
#include "cfg_file.h"
#include "rspamd.h"
-#include "filter.h"
-#include "message.h"
+#include "unix-std.h"
#include "xxhash.h"
#include "ottery.h"
@@ -49,10 +48,32 @@
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
-
+/* libutil */
+#ifdef HAVE_LIBUTIL_H
+#include <libutil.h>
+#endif
#ifdef __APPLE__
#include <mach/mach_time.h>
#endif
+#ifdef WITH_GPERF_TOOLS
+#include <google/profiler.h>
+#endif
+/* poll */
+#ifdef HAVE_POLL_H
+#include <poll.h>
+#endif
+
+#ifdef HAVE_SIGINFO_H
+#include <siginfo.h>
+#endif
+/* sys/wait */
+#ifdef HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
+/* sys/resource.h */
+#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/resource.h>
+#endif
#include "blake2.h"
diff --git a/src/libutil/util.h b/src/libutil/util.h
index a78c4dfda..e563718f8 100644
--- a/src/libutil/util.h
+++ b/src/libutil/util.h
@@ -8,6 +8,11 @@
#include "addr.h"
#include "str_util.h"
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#include <event.h>
+
struct rspamd_config;
struct rspamd_main;
struct workq;