1
0
mirror of https://github.com/samba-team/samba.git synced 2025-03-27 22:50:26 +03:00

lib: Split out sys_[read|write] & friends

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
This commit is contained in:
Volker Lendecke 2014-11-19 13:33:06 +00:00 committed by Jeremy Allison
parent a25e913cf5
commit 97b2570a5e
20 changed files with 158 additions and 96 deletions

View 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);

View 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

101
source3/lib/sys_rw.c Normal file
View File

@ -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;
}

36
source3/lib/sys_rw.h Normal file
View File

@ -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

View File

@ -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.
********************************************************************/

View 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>

View File

@ -18,6 +18,7 @@
*/
#include "includes.h"
#include "lib/sys_rw.h"
/**
Load from a pipe into memory.

View 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)
{

View File

@ -22,6 +22,7 @@
#include <includes.h>
#include "transfer_file.h"
#include "lib/sys_rw.h"
/****************************************************************************
Transfer some data between two fd's.

View 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)
{

View 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

View 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>

View 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. */

View 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

View 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

View 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>

View 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))

View 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

View 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

View File

@ -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='''