lib: Split out sys_[read|write] & friends
authorVolker Lendecke <vl@samba.org>
Wed, 19 Nov 2014 13:33:06 +0000 (13:33 +0000)
committerJeremy Allison <jra@samba.org>
Sat, 6 Dec 2014 23:12:07 +0000 (00:12 +0100)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
20 files changed:
source3/include/proto.h
source3/lib/recvfile.c
source3/lib/sys_rw.c [new file with mode: 0644]
source3/lib/sys_rw.h [new file with mode: 0644]
source3/lib/system.c
source3/lib/util.c
source3/lib/util_file.c
source3/lib/util_sock.c
source3/lib/util_transfer_file.c
source3/libsmb/unexpected.c
source3/modules/vfs_aio_fork.c
source3/modules/vfs_aio_linux.c
source3/modules/vfs_aio_posix.c
source3/modules/vfs_default.c
source3/modules/vfs_fruit.c
source3/printing/print_cups.c
source3/rpc_server/samr/srv_samr_chgpasswd.c
source3/smbd/scavenger.c
source3/winbindd/winbindd_dual.c
source3/wscript_build

index 82e1032490ef7b9ac2466bc72b643d934f3f3fcc..68a3053a7b507973a8af2a671e58625b6fe1f992 100644 (file)
@@ -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);
index 273c51f7703717112fe5920f81ae8dba6ad4f986..403d5e892e8f5782c3d5f5d67e959af63f4bada5 100644 (file)
@@ -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 (file)
index 0000000..6d8f149
--- /dev/null
@@ -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 (file)
index 0000000..ee1584e
--- /dev/null
@@ -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
index 6478e6f512cc8266d8e2a2934946db6bf6dbcc0e..7531d771ce98ba4964149955af02d7ede4e23146 100644 (file)
      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.
 ********************************************************************/
index 7b2afa8073c1187ae818c8e86cf4ff053299190f..49eef505ad329df888661e5ef3f06ba8db0dacec 100644 (file)
@@ -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>
index 8319f04a0930278e66470ccf3c30e3ed1e9e255f..27a078fe79a17a1c33c3d00b9ffd576badfc972b 100644 (file)
@@ -18,6 +18,7 @@
  */
 
 #include "includes.h"
+#include "lib/sys_rw.h"
 
 /**
  Load from a pipe into memory.
index d865ffba7c6d5ad91afa2877ce90956d50e9bb61..2bed9a90632672fc94720179d19b2de6747c09d8 100644 (file)
@@ -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)
 {
index 00a2c9d9de98188baf661878e4b0b35439e6acea..d415d7f98e0d1b0b25a15d4f0bcc7d291ea2f7cd 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <includes.h>
 #include "transfer_file.h"
+#include "lib/sys_rw.h"
 
 /****************************************************************************
  Transfer some data between two fd's.
index 2c01bb7515407784f174b9637167a8633c561d74..ee1c3601caea023a03175c65509f7714e00d8cb3 100644 (file)
@@ -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)
 {
index 12e6f8025794aec991652fd75436fde0686ff2c8..c2148a104fb8f100ed5376ff09a76c927fba6de2 100644 (file)
@@ -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
index 618897527e280a5dd29291f757e7b5daa00e449a..6c975925d31da75822824e56691966dcfe850951 100644 (file)
@@ -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>
 
index 3629541e6158dac761381c98e0c4d4bb3618b5dc..ef5f706727228300be18990654e8a998609daa4c 100644 (file)
@@ -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. */
index 613101a09a95292c64a63b755b9721f93ec14cb3..1e1c318a8934c6986fe85d7db989f673edaa86e8 100644 (file)
@@ -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
index ebafe3a75dd7eeca4727b1593d1839ddecf13c40..18a6823bb06a73cb8d1b5975d49350a63cc8a3c7 100644 (file)
@@ -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
index 0ec71ab04a5ff9aadd1b678a3d576ea7b74f2786..68f367cc51da9e2aff55252421f903cfc4374311 100644 (file)
@@ -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>
index 684ccee0fb92e2db2842eec0fdcae5ea1e4d9b0f..e899306bf5cfbcb2459e851ee4464f85c8d2e902 100644 (file)
@@ -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))
index 122305e04bf02a92411720fe7ac8cb50de07a48c..013b4d2405d319d5aaa9938c362d380d3479a028 100644 (file)
@@ -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
index f71d111c7d0b86f8650353e91a3aed19c4ed0548..b9c110f9b2e829773821083ec4246d98a8864711 100644 (file)
@@ -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
index 469424d136d84166a67aee3cfe4dd04723487e1a..787c4e25514f50b1d863ef51b0a65a315d86d26c 100755 (executable)
@@ -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='''