From: Anoop C S Date: Fri, 27 Sep 2019 06:37:40 +0000 (+0530) Subject: s3: VFS: Use SMB_VFS_FCNTL to set fd flags in open_file() X-Git-Tag: talloc-2.3.1~467 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0abd1189a60eea4501b5279ebc4bff2b5689f888;p=thirdparty%2Fsamba.git s3: VFS: Use SMB_VFS_FCNTL to set fd flags in open_file() Signed-off-by: Anoop C S Reviewed-by: Ralph Boehme Reviewed-by: Jeremy Allison Autobuild-User(master): Ralph Böhme Autobuild-Date(master): Tue Oct 8 09:57:19 UTC 2019 on sn-devel-184 --- diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 5860155263b..9493021c48d 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -1327,7 +1327,7 @@ static NTSTATUS open_file(files_struct *fsp, * too. With blocking file descriptors this * does not happen. */ - ret = set_blocking(fsp->fh->fd, true); + ret = vfs_set_blocking(fsp, true); if (ret == -1) { status = map_nt_error_from_unix(errno); DBG_WARNING("Could not set fd to blocking: " diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 11c9dc0f8b1..e9d04474df6 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -1230,6 +1230,7 @@ int vfs_allocate_file_space(files_struct *fsp, uint64_t len); int vfs_set_filelen(files_struct *fsp, off_t len); int vfs_slow_fallocate(files_struct *fsp, off_t offset, off_t len); int vfs_fill_sparse(files_struct *fsp, off_t len); +int vfs_set_blocking(files_struct *fsp, bool set); off_t vfs_transfer_file(files_struct *in, files_struct *out, off_t n); const char *vfs_readdirname(connection_struct *conn, void *p, SMB_STRUCT_STAT *sbuf, char **talloced); diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index bef79e4c64e..5332f00e876 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -711,6 +711,37 @@ int vfs_fill_sparse(files_struct *fsp, off_t len) return ret; } +/******************************************************************************* + Set a fd into blocking/nonblocking mode through VFS +*******************************************************************************/ + +int vfs_set_blocking(files_struct *fsp, bool set) +{ + int val; +#ifdef O_NONBLOCK +#define FLAG_TO_SET O_NONBLOCK +#else +#ifdef SYSV +#define FLAG_TO_SET O_NDELAY +#else /* BSD */ +#define FLAG_TO_SET FNDELAY +#endif +#endif + val = SMB_VFS_FCNTL(fsp, F_GETFL, 0); + if (val == -1) { + return -1; + } + + if (set) { + val &= ~FLAG_TO_SET; + } else { + val |= FLAG_TO_SET; + } + + return SMB_VFS_FCNTL(fsp, F_SETFL, val); +#undef FLAG_TO_SET +} + /**************************************************************************** Transfer some data (n bytes) between two file_struct's. ****************************************************************************/