From 97b2570a5e526273476d3990bcef0ac074b34d67 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 19 Nov 2014 13:33:06 +0000 Subject: [PATCH] lib: Split out sys_[read|write] & friends Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- source3/include/proto.h | 5 -- source3/lib/recvfile.c | 1 + source3/lib/sys_rw.c | 101 +++++++++++++++++++++++++++ source3/lib/sys_rw.h | 36 ++++++++++ source3/lib/system.c | 90 ------------------------ source3/lib/util.c | 1 + source3/lib/util_file.c | 1 + source3/lib/util_sock.c | 1 + source3/lib/util_transfer_file.c | 1 + source3/libsmb/unexpected.c | 1 + source3/modules/vfs_aio_fork.c | 1 + source3/modules/vfs_aio_linux.c | 1 + source3/modules/vfs_aio_posix.c | 1 + source3/modules/vfs_default.c | 1 + source3/modules/vfs_fruit.c | 1 + source3/printing/print_cups.c | 1 + source3/rpc_server/samr/srv_samr_chgpasswd.c | 1 + source3/smbd/scavenger.c | 1 + source3/winbindd/winbindd_dual.c | 1 + source3/wscript_build | 7 +- 20 files changed, 158 insertions(+), 96 deletions(-) create mode 100644 source3/lib/sys_rw.c create mode 100644 source3/lib/sys_rw.h diff --git a/source3/include/proto.h b/source3/include/proto.h index 82e1032490e..68a3053a7b5 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 273c51f7703..403d5e892e8 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 00000000000..6d8f149f1ce --- /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 . + */ + +#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 00000000000..ee1584e904f --- /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 . + */ + +#ifndef __LIB_SYS_RW_H__ +#define __LIB_SYS_RW_H__ + +#include + +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 6478e6f512c..7531d771ce9 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 7b2afa8073c..49eef505ad3 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -31,6 +31,7 @@ #include #include "libcli/security/security.h" #include "serverid.h" +#include "lib/sys_rw.h" #ifdef HAVE_SYS_PRCTL_H #include diff --git a/source3/lib/util_file.c b/source3/lib/util_file.c index 8319f04a093..27a078fe79a 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 d865ffba7c6..2bed9a90632 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 00a2c9d9de9..d415d7f98e0 100644 --- a/source3/lib/util_transfer_file.c +++ b/source3/lib/util_transfer_file.c @@ -22,6 +22,7 @@ #include #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 2c01bb75154..ee1c3601cae 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 12e6f802579..c2148a104fb 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 618897527e2..6c975925d31 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 #include diff --git a/source3/modules/vfs_aio_posix.c b/source3/modules/vfs_aio_posix.c index 3629541e615..ef5f7067272 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 /* The signal we'll use to signify aio done. */ diff --git a/source3/modules/vfs_default.c b/source3/modules/vfs_default.c index 613101a09a9..1e1c318a893 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 ebafe3a75dd..18a6823bb06 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 0ec71ab04a5..68f367cc51d 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 diff --git a/source3/rpc_server/samr/srv_samr_chgpasswd.c b/source3/rpc_server/samr/srv_samr_chgpasswd.c index 684ccee0fb9..e899306bf5c 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 122305e04bf..013b4d2405d 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 f71d111c7d0..b9c110f9b2e 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 469424d136d..787c4e25514 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=''' -- 2.11.4.GIT