summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2014-11-19 13:33:06 +0000
committerJeremy Allison <jra@samba.org>2014-12-07 00:12:07 +0100
commit97b2570a5e526273476d3990bcef0ac074b34d67 (patch)
tree7a495f0757d199b4a9f736048bd971160b7bedf4
parenta25e913cf58c0490755d5a555e2175ae2e74e24e (diff)
downloadsamba-97b2570a5e526273476d3990bcef0ac074b34d67.tar.gz
samba-97b2570a5e526273476d3990bcef0ac074b34d67.tar.xz
samba-97b2570a5e526273476d3990bcef0ac074b34d67.zip
lib: Split out sys_[read|write] & friends
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
-rw-r--r--source3/include/proto.h5
-rw-r--r--source3/lib/recvfile.c1
-rw-r--r--source3/lib/sys_rw.c101
-rw-r--r--source3/lib/sys_rw.h36
-rw-r--r--source3/lib/system.c90
-rw-r--r--source3/lib/util.c1
-rw-r--r--source3/lib/util_file.c1
-rw-r--r--source3/lib/util_sock.c1
-rw-r--r--source3/lib/util_transfer_file.c1
-rw-r--r--source3/libsmb/unexpected.c1
-rw-r--r--source3/modules/vfs_aio_fork.c1
-rw-r--r--source3/modules/vfs_aio_linux.c1
-rw-r--r--source3/modules/vfs_aio_posix.c1
-rw-r--r--source3/modules/vfs_default.c1
-rw-r--r--source3/modules/vfs_fruit.c1
-rw-r--r--source3/printing/print_cups.c1
-rw-r--r--source3/rpc_server/samr/srv_samr_chgpasswd.c1
-rw-r--r--source3/smbd/scavenger.c1
-rw-r--r--source3/winbindd/winbindd_dual.c1
-rwxr-xr-xsource3/wscript_build7
20 files changed, 158 insertions, 96 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 82e1032490..68a3053a7b 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -242,11 +242,6 @@ int sys_set_nfs_quota(const char *path, const char *bdev,
/* The following definitions come from lib/system.c */
-ssize_t sys_read(int fd, void *buf, size_t count);
-ssize_t sys_write(int fd, const void *buf, size_t count);
-ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt);
-ssize_t sys_pread(int fd, void *buf, size_t count, off_t off);
-ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off);
ssize_t sys_send(int s, const void *msg, size_t len, int flags);
ssize_t sys_recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
int sys_fcntl_ptr(int fd, int cmd, void *arg);
diff --git a/source3/lib/recvfile.c b/source3/lib/recvfile.c
index 273c51f770..403d5e892e 100644
--- a/source3/lib/recvfile.c
+++ b/source3/lib/recvfile.c
@@ -25,6 +25,7 @@
#include "includes.h"
#include "system/filesys.h"
+#include "lib/sys_rw.h"
/* Do this on our own in TRANSFER_BUF_SIZE chunks.
* It's safe to make direct syscalls to lseek/write here
diff --git a/source3/lib/sys_rw.c b/source3/lib/sys_rw.c
new file mode 100644
index 0000000000..6d8f149f1c
--- /dev/null
+++ b/source3/lib/sys_rw.c
@@ -0,0 +1,101 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Andrew Tridgell 1992-1998
+ * Copyright (C) Jeremy Allison 1998-2005
+ * Copyright (C) Timur Bakeyev 2005
+ * Copyright (C) Bjoern Jacke 2006-2007
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "replace.h"
+#include "system/filesys.h"
+#include "lib/sys_rw.h"
+
+/*******************************************************************
+A read wrapper that will deal with EINTR/EWOULDBLOCK
+********************************************************************/
+
+ssize_t sys_read(int fd, void *buf, size_t count)
+{
+ ssize_t ret;
+
+ do {
+ ret = read(fd, buf, count);
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
+ errno == EWOULDBLOCK));
+
+ return ret;
+}
+
+/*******************************************************************
+A write wrapper that will deal with EINTR/EWOULDBLOCK.
+********************************************************************/
+
+ssize_t sys_write(int fd, const void *buf, size_t count)
+{
+ ssize_t ret;
+
+ do {
+ ret = write(fd, buf, count);
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
+ errno == EWOULDBLOCK));
+
+ return ret;
+}
+
+/*******************************************************************
+A writev wrapper that will deal with EINTR.
+********************************************************************/
+
+ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
+{
+ ssize_t ret;
+
+ do {
+ ret = writev(fd, iov, iovcnt);
+ } while (ret == -1 && (errno == EINTR || errno == EAGAIN ||
+ errno == EWOULDBLOCK));
+
+ return ret;
+}
+
+/*******************************************************************
+A pread wrapper that will deal with EINTR
+********************************************************************/
+
+ssize_t sys_pread(int fd, void *buf, size_t count, off_t off)
+{
+ ssize_t ret;
+
+ do {
+ ret = pread(fd, buf, count, off);
+ } while (ret == -1 && errno == EINTR);
+ return ret;
+}
+
+/*******************************************************************
+A write wrapper that will deal with EINTR
+********************************************************************/
+
+ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off)
+{
+ ssize_t ret;
+
+ do {
+ ret = pwrite(fd, buf, count, off);
+ } while (ret == -1 && errno == EINTR);
+ return ret;
+}
diff --git a/source3/lib/sys_rw.h b/source3/lib/sys_rw.h
new file mode 100644
index 0000000000..ee1584e904
--- /dev/null
+++ b/source3/lib/sys_rw.h
@@ -0,0 +1,36 @@
+/*
+ * Unix SMB/CIFS implementation.
+ * Samba system utilities
+ * Copyright (C) Andrew Tridgell 1992-1998
+ * Copyright (C) Jeremy Allison 1998-2005
+ * Copyright (C) Timur Bakeyev 2005
+ * Copyright (C) Bjoern Jacke 2006-2007
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __LIB_SYS_RW_H__
+#define __LIB_SYS_RW_H__
+
+#include <unistd.h>
+
+struct iovec;
+
+ssize_t sys_read(int fd, void *buf, size_t count);
+ssize_t sys_write(int fd, const void *buf, size_t count);
+ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt);
+ssize_t sys_pread(int fd, void *buf, size_t count, off_t off);
+ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off);
+
+#endif
diff --git a/source3/lib/system.c b/source3/lib/system.c
index 6478e6f512..7531d771ce 100644
--- a/source3/lib/system.c
+++ b/source3/lib/system.c
@@ -50,96 +50,6 @@
expansions/etc make sense to the OS should be acceptable to Samba.
*/
-
-
-/*******************************************************************
-A read wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_read(int fd, void *buf, size_t count)
-{
- ssize_t ret;
-
- do {
- ret = read(fd, buf, count);
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-
- return ret;
-}
-
-/*******************************************************************
-A write wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_write(int fd, const void *buf, size_t count)
-{
- ssize_t ret;
-
- do {
- ret = write(fd, buf, count);
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-
- return ret;
-}
-
-/*******************************************************************
-A writev wrapper that will deal with EINTR.
-********************************************************************/
-
-ssize_t sys_writev(int fd, const struct iovec *iov, int iovcnt)
-{
- ssize_t ret;
-
-#if 0
- /* Try to confuse write_data_iov a bit */
- if ((random() % 5) == 0) {
- return sys_write(fd, iov[0].iov_base, iov[0].iov_len);
- }
- if (iov[0].iov_len > 1) {
- return sys_write(fd, iov[0].iov_base,
- (random() % (iov[0].iov_len-1)) + 1);
- }
-#endif
-
- do {
- ret = writev(fd, iov, iovcnt);
- } while (ret == -1 && (errno == EINTR || errno == EAGAIN || errno == EWOULDBLOCK));
-
- return ret;
-}
-
-/*******************************************************************
-A pread wrapper that will deal with EINTR
-********************************************************************/
-
-#if defined(HAVE_PREAD)
-ssize_t sys_pread(int fd, void *buf, size_t count, off_t off)
-{
- ssize_t ret;
-
- do {
- ret = pread(fd, buf, count, off);
- } while (ret == -1 && errno == EINTR);
- return ret;
-}
-#endif
-
-/*******************************************************************
-A write wrapper that will deal with EINTR
-********************************************************************/
-
-#if defined(HAVE_PWRITE)
-ssize_t sys_pwrite(int fd, const void *buf, size_t count, off_t off)
-{
- ssize_t ret;
-
- do {
- ret = pwrite(fd, buf, count, off);
- } while (ret == -1 && errno == EINTR);
- return ret;
-}
-#endif
-
/*******************************************************************
A send wrapper that will deal with EINTR or EAGAIN or EWOULDBLOCK.
********************************************************************/
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 7b2afa8073..49eef505ad 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -31,6 +31,7 @@
#include <ccan/hash/hash.h>
#include "libcli/security/security.h"
#include "serverid.h"
+#include "lib/sys_rw.h"
#ifdef HAVE_SYS_PRCTL_H
#include <sys/prctl.h>
diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c
index 8319f04a09..27a078fe79 100644
--- a/source3/lib/util_file.c
+++ b/source3/lib/util_file.c
@@ -18,6 +18,7 @@
*/
#include "includes.h"
+#include "lib/sys_rw.h"
/**
Load from a pipe into memory.
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index d865ffba7c..2bed9a9063 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -28,6 +28,7 @@
#include "../lib/util/tevent_unix.h"
#include "../lib/util/tevent_ntstatus.h"
#include "../lib/tsocket/tsocket.h"
+#include "lib/sys_rw.h"
const char *client_addr(int fd, char *addr, size_t addrlen)
{
diff --git a/source3/lib/util_transfer_file.c b/source3/lib/util_transfer_file.c
index 00a2c9d9de..d415d7f98e 100644
--- a/source3/lib/util_transfer_file.c
+++ b/source3/lib/util_transfer_file.c
@@ -22,6 +22,7 @@
#include <includes.h>
#include "transfer_file.h"
+#include "lib/sys_rw.h"
/****************************************************************************
Transfer some data between two fd's.
diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c
index 2c01bb7515..ee1c3601ca 100644
--- a/source3/libsmb/unexpected.c
+++ b/source3/libsmb/unexpected.c
@@ -22,6 +22,7 @@
#include "../lib/util/tevent_ntstatus.h"
#include "lib/async_req/async_sock.h"
#include "libsmb/nmblib.h"
+#include "lib/sys_rw.h"
static const char *nmbd_socket_dir(void)
{
diff --git a/source3/modules/vfs_aio_fork.c b/source3/modules/vfs_aio_fork.c
index 12e6f80257..c2148a104f 100644
--- a/source3/modules/vfs_aio_fork.c
+++ b/source3/modules/vfs_aio_fork.c
@@ -26,6 +26,7 @@
#include "smbd/globals.h"
#include "lib/async_req/async_sock.h"
#include "lib/util/tevent_unix.h"
+#include "lib/sys_rw.h"
#if !defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL) && !defined(HAVE_STRUCT_MSGHDR_MSG_ACCRIGHTS)
# error Can not pass file descriptors
diff --git a/source3/modules/vfs_aio_linux.c b/source3/modules/vfs_aio_linux.c
index 618897527e..6c975925d3 100644
--- a/source3/modules/vfs_aio_linux.c
+++ b/source3/modules/vfs_aio_linux.c
@@ -24,6 +24,7 @@
#include "smbd/smbd.h"
#include "smbd/globals.h"
#include "lib/util/tevent_unix.h"
+#include "lib/sys_rw.h"
#include <sys/eventfd.h>
#include <libaio.h>
diff --git a/source3/modules/vfs_aio_posix.c b/source3/modules/vfs_aio_posix.c
index 3629541e61..ef5f706727 100644
--- a/source3/modules/vfs_aio_posix.c
+++ b/source3/modules/vfs_aio_posix.c
@@ -24,6 +24,7 @@
#include "smbd/smbd.h"
#include "smbd/globals.h"
#include "lib/util/tevent_unix.h"
+#include "lib/sys_rw.h"
#include <aio.h>
/* The signal we'll use to signify aio done. */
diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c
index 613101a09a..1e1c318a89 100644
--- a/source3/modules/vfs_default.c
+++ b/source3/modules/vfs_default.c
@@ -32,6 +32,7 @@
#include "lib/util/tevent_unix.h"
#include "lib/asys/asys.h"
#include "lib/util/tevent_ntstatus.h"
+#include "lib/sys_rw.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_VFS
diff --git a/source3/modules/vfs_fruit.c b/source3/modules/vfs_fruit.c
index ebafe3a75d..18a6823bb0 100644
--- a/source3/modules/vfs_fruit.c
+++ b/source3/modules/vfs_fruit.c
@@ -29,6 +29,7 @@
#include "messages.h"
#include "libcli/security/security.h"
#include "../libcli/smb/smb2_create_ctx.h"
+#include "lib/sys_rw.h"
/*
* Enhanced OS X and Netatalk compatibility
diff --git a/source3/printing/print_cups.c b/source3/printing/print_cups.c
index 0ec71ab04a..68f367cc51 100644
--- a/source3/printing/print_cups.c
+++ b/source3/printing/print_cups.c
@@ -26,6 +26,7 @@
#include "printing.h"
#include "printing/pcap.h"
#include "librpc/gen_ndr/ndr_printcap.h"
+#include "lib/sys_rw.h"
#ifdef HAVE_CUPS
#include <cups/cups.h>
diff --git a/source3/rpc_server/samr/srv_samr_chgpasswd.c b/source3/rpc_server/samr/srv_samr_chgpasswd.c
index 684ccee0fb..e899306bf5 100644
--- a/source3/rpc_server/samr/srv_samr_chgpasswd.c
+++ b/source3/rpc_server/samr/srv_samr_chgpasswd.c
@@ -54,6 +54,7 @@
#include "rpc_server/samr/srv_samr_util.h"
#include "passdb.h"
#include "auth.h"
+#include "lib/sys_rw.h"
#ifndef ALLOW_CHANGE_PASSWORD
#if (defined(HAVE_TERMIOS_H) && defined(HAVE_DUP2) && defined(HAVE_SETSID))
diff --git a/source3/smbd/scavenger.c b/source3/smbd/scavenger.c
index 122305e04b..013b4d2405 100644
--- a/source3/smbd/scavenger.c
+++ b/source3/smbd/scavenger.c
@@ -26,6 +26,7 @@
#include "smbd/scavenger.h"
#include "locking/proto.h"
#include "lib/util/util_process.h"
+#include "lib/sys_rw.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_SCAVENGER
diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index f71d111c7d..b9c110f9b2 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -38,6 +38,7 @@
#include "messages.h"
#include "../lib/util/tevent_unix.h"
#include "lib/param/loadparm.h"
+#include "lib/sys_rw.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_WINBIND
diff --git a/source3/wscript_build b/source3/wscript_build
index 469424d136..787c4e2551 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -253,6 +253,11 @@ bld.SAMBA3_SUBSYSTEM('KRBCLIENT',
source='libads/kerberos.c libads/ads_status.c',
public_deps='krb5samba k5crypto gssapi LIBTSOCKET CLDAP LIBNMB')
+bld.SAMBA3_LIBRARY('sys_rw',
+ source='lib/sys_rw.c',
+ deps='replace',
+ private_library=True)
+
bld.SAMBA3_SUBSYSTEM('samba3util',
source='''lib/system.c
lib/sendfile.c
@@ -264,7 +269,7 @@ bld.SAMBA3_SUBSYSTEM('samba3util',
lib/util_sock.c
lib/util_transfer_file.c
lib/sock_exec.c''',
- deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash')
+ deps='ndr samba-security NDR_SECURITY samba-util util_tdb ccan-hash sys_rw')
if bld.CONFIG_GET("CTDB_CFLAGS") and bld.CONFIG_GET("CTDB_INCLUDE"):
SAMBA_CLUSTER_SUPPORT_SOURCES='''