JH/10 Enable use of sendfile in Linux builds as default. It was disabled in
4.77 as the kernel support then wasn't solid, having issues in 64bit
- mode. Now, it's been long enough.
+ mode. Now, it's been long enough. Add support for FreeBSD also.
JH/11 Bug 2104: Fix continued use of a transport connection with TLS. In the
case where the routing stage had gathered several addresses to send to
--- /dev/null
+/*************************************************
+* 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 */
#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 */
/* Exim: OS-specific C header file for FreeBSD */
+#include <sys/types.h>
+
#define HAVE_BSD_GETLOADAVG
#define HAVE_SETCLASSRESOURCES
#define HAVE_MMAP
/* 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 */
with the issue. */
#include <features.h>
+#include <sys/types.h>
#define CRYPT_H
#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;
#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__)
#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)
/*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
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;
}
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)
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;
#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. */
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
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;