summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJeremy Harris <jgh146exb@wizmail.org>2017-05-06 20:19:31 +0100
committerJeremy Harris <jgh146exb@wizmail.org>2017-05-06 21:04:11 +0100
commit7d758a6a6842fac6c511039c29d76300e2e21ccd (patch)
tree2fe98fe2787486cb4fc164283148c9d37fc5e7f3 /src
parent40525d07a858c90293bc09188fb539a1cec3f8aa (diff)
Enable use of sendfile on FreeBSD
Diffstat (limited to 'src')
-rw-r--r--src/OS/os.c-FreeBSD25
-rw-r--r--src/OS/os.c-Linux12
-rw-r--r--src/OS/os.h-FreeBSD9
-rw-r--r--src/OS/os.h-Linux10
-rw-r--r--src/src/dkim_transport.c10
-rw-r--r--src/src/receive.c2
-rw-r--r--src/src/transport.c8
7 files changed, 58 insertions, 18 deletions
diff --git a/src/OS/os.c-FreeBSD b/src/OS/os.c-FreeBSD
new file mode 100644
index 000000000..a892e5940
--- /dev/null
+++ b/src/OS/os.c-FreeBSD
@@ -0,0 +1,25 @@
+/*************************************************
+* Exim - an Internet mail transport agent *
+*************************************************/
+
+/* Copyright (c) Jeremy Harris 2017 */
+/* See the file NOTICE for conditions of use and distribution. */
+
+/* FreeBSD-specific code. This is concatenated onto the generic
+src/os.c file. */
+
+
+/*************
+* Sendfile *
+*************/
+#include <sys/sendfile.h>
+
+ssize_t
+os_sendfile(int out, int in, off_t * off, size_t cnt)
+{
+off_t written;
+return sendfile(in, out, *off, cnt, NULL, &written, 0) < 0
+ ? (ssize_t) -1 : (ssize_t) written;
+}
+
+/* End of os.c-Linux */
diff --git a/src/OS/os.c-Linux b/src/OS/os.c-Linux
index 4bca77615..dd65c8b39 100644
--- a/src/OS/os.c-Linux
+++ b/src/OS/os.c-Linux
@@ -150,4 +150,16 @@ return yield;
#endif /* FIND_RUNNING_INTERFACES */
+
+/*************
+* Sendfile *
+*************/
+#include <sys/sendfile.h>
+
+ssize_t
+os_sendfile(int out, int in, off_t * off, size_t cnt)
+{
+return sendfile(out, in, off, cnt);
+}
+
/* End of os.c-Linux */
diff --git a/src/OS/os.h-FreeBSD b/src/OS/os.h-FreeBSD
index bf43e0a3c..9b47de3d1 100644
--- a/src/OS/os.h-FreeBSD
+++ b/src/OS/os.h-FreeBSD
@@ -1,5 +1,7 @@
/* Exim: OS-specific C header file for FreeBSD */
+#include <sys/types.h>
+
#define HAVE_BSD_GETLOADAVG
#define HAVE_SETCLASSRESOURCES
#define HAVE_MMAP
@@ -34,4 +36,11 @@ typedef struct flock flock_t;
/* for more specific version constraints, include <sys/param.h> and look at
* __FreeBSD_version */
+
+/* When using DKIM, setting OS_SENDFILE can increase
+performance on outgoing mail a bit. */
+
+#define OS_SENDFILE
+extern ssize_t os_sendfile(int, int, off_t *, size_t);
+
/* End */
diff --git a/src/OS/os.h-Linux b/src/OS/os.h-Linux
index 3e9303cab..57034649c 100644
--- a/src/OS/os.h-Linux
+++ b/src/OS/os.h-Linux
@@ -5,6 +5,7 @@ does not pull in <features.h>. Best to just pull it in now and have done
with the issue. */
#include <features.h>
+#include <sys/types.h>
#define CRYPT_H
@@ -15,13 +16,14 @@ with the issue. */
#define NO_IP_VAR_H
#define SIG_IGN_WORKS
-/* When using the DKIM, setting HAVE_LINUX_SENDFILE can increase
+/* When using DKIM, setting OS_SENDFILE can increase
performance on outgoing mail a bit. Note: With older glibc versions
this setting will conflict with the _FILE_OFFSET_BITS=64 setting
defined as part of the Linux CFLAGS. As of 2017 those are declared
to be too old to build by default. */
-#define HAVE_LINUX_SENDFILE
+#define OS_SENDFILE
+extern ssize_t os_sendfile(int, int, off_t *, size_t);
#define F_FREESP O_TRUNC
typedef struct flock flock_t;
@@ -30,8 +32,8 @@ typedef struct flock flock_t;
#define OS_STRSIGNAL
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD_kernel__)
-#define SIOCGIFCONF_GIVES_ADDR
-#define HAVE_SYS_MOUNT_H
+# define SIOCGIFCONF_GIVES_ADDR
+# define HAVE_SYS_MOUNT_H
#endif
#if defined(__linux__)
diff --git a/src/src/dkim_transport.c b/src/src/dkim_transport.c
index 882fc8772..95e750e5e 100644
--- a/src/src/dkim_transport.c
+++ b/src/src/dkim_transport.c
@@ -12,10 +12,6 @@
#ifndef DISABLE_DKIM /* rest of file */
-#ifdef HAVE_LINUX_SENDFILE
-# include <sys/sendfile.h>
-#endif
-
static BOOL
dkt_sign_fail(struct ob_dkim * dkim, int * errp)
@@ -47,7 +43,7 @@ DEBUG(D_transport) debug_printf("send file fd=%d size=%u\n", out_fd, (unsigned)(
/*XXX should implement timeout, like transport_write_block_fd() ? */
-#ifdef HAVE_LINUX_SENDFILE
+#ifdef OS_SENDFILE
/* We can use sendfile() to shove the file contents
to the socket. However only if we don't use TLS,
as then there's another layer of indirection
@@ -57,7 +53,7 @@ if (tls_out.active != out_fd)
ssize_t copied = 0;
while(copied >= 0 && off < size)
- copied = sendfile(out_fd, in_fd, &off, size - off);
+ copied = os_sendfile(out_fd, in_fd, &off, size - off);
if (copied < 0)
return FALSE;
}
@@ -255,7 +251,7 @@ else if (!(rc = dkt_sign_fail(dkim, &save_errno)))
goto CLEANUP;
}
-#ifndef HAVE_LINUX_SENDFILE
+#ifndef OS_SENDFILE
if (options & topt_use_bdat)
#endif
if ((k_file_size = lseek(dkim_fd, 0, SEEK_END)) < 0)
diff --git a/src/src/receive.c b/src/src/receive.c
index f8320bd20..6316ff961 100644
--- a/src/src/receive.c
+++ b/src/src/receive.c
@@ -919,7 +919,7 @@ BOOL fix_nl = FALSE;
for(;;)
{
- switch ((ch = (bdat_getc)(GETC_BUFFER_UNLIMITED)))
+ switch ((ch = bdat_getc(GETC_BUFFER_UNLIMITED)))
{
case EOF: return END_EOF;
case ERR: return END_PROTOCOL;
diff --git a/src/src/transport.c b/src/src/transport.c
index 0dc8785cb..5bcf8c1ae 100644
--- a/src/src/transport.c
+++ b/src/src/transport.c
@@ -11,10 +11,6 @@ transports. */
#include "exim.h"
-#ifdef HAVE_LINUX_SENDFILE
-# include <sys/sendfile.h>
-#endif
-
/* Structure for keeping list of addresses that have been added to
Envelope-To:, in order to avoid duplication. */
@@ -1065,7 +1061,7 @@ then we can just dump it using sendfile.
This should get used for CHUNKING output and also for writing the -K file for
dkim signing, when we had CHUNKING input. */
-#ifdef HAVE_LINUX_SENDFILE
+#ifdef OS_SENDFILE
if ( spool_file_wireformat
&& !(tctx->options & (topt_no_body | topt_end_dot))
&& !nl_check_length
@@ -1088,7 +1084,7 @@ if ( spool_file_wireformat
while(size > 0)
{
- if ((copied = sendfile(tctx->u.fd, deliver_datafile, &offset, size)) <= 0) break;
+ if ((copied = os_sendfile(tctx->u.fd, deliver_datafile, &offset, size)) <= 0) break;
size -= copied;
}
return copied >= 0;