From 8f779ebb9bf521299500f55a6273e38869480f45 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 9 Apr 2003 23:28:30 +0300 Subject: [PATCH] Call safe_sendfile() only with sockets, and also with files under Linux. Hopefully helps for signal 12 under FreeBSD. --HG-- branch : HEAD --- src/lib/ostream-file.c | 9 +++++++++ src/lib/sendfile-util.c | 6 +----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/lib/ostream-file.c b/src/lib/ostream-file.c index 7ea288314a..4b7a474185 100644 --- a/src/lib/ostream-file.c +++ b/src/lib/ostream-file.c @@ -876,6 +876,15 @@ o_stream_create_file(int fd, pool_t pool, size_t max_buffer_size, fstream->optimal_block_size = I_MIN(st.st_blksize, MAX_OPTIMAL_BLOCK_SIZE); } +#ifndef HAVE_LINUX_SENDFILE + /* only Linux supports sendfile() with non-sockets. Other + systems fail more or less gracefully if it's tried, so + don't bother to even try with them. */ + fstream->no_sendfile = TRUE; +#endif + } else { + if (net_getsockname(fd, NULL, NULL) < 0) + fstream->no_sendfile = TRUE; } return ostream; } diff --git a/src/lib/sendfile-util.c b/src/lib/sendfile-util.c index 4ca4ff1817..995337bff5 100644 --- a/src/lib/sendfile-util.c +++ b/src/lib/sendfile-util.c @@ -92,12 +92,8 @@ ssize_t safe_sendfile(int out_fd, int in_fd, uoff_t *offset, size_t count) i_assert(count <= SSIZE_T_MAX); - /* outfd must be socket, or at least some Solaris versions will + /* NOTE: if outfd is not a socket, some Solaris versions will kernel panic */ - if (net_getsockname(out_fd, NULL, NULL) < 0) { - errno = EINVAL; - return -1; - } vec.sfv_fd = in_fd; vec.sfv_flag = 0; -- 2.47.3