From fbc611f431db443c23486f768ca5e2bc4db95c24 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Tue, 29 Mar 2005 00:42:51 +0000 Subject: r6108: Added smbsh/smbwrapper for Linux to example/libsmbclient tree; provided more complete libsmbclient testbrowse utility (This used to be commit 15736b97c837a16d9c009b8bff18b31429ccbe83) --- examples/libsmbclient/smbwrapper/select.c | 124 ++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 examples/libsmbclient/smbwrapper/select.c (limited to 'examples/libsmbclient/smbwrapper/select.c') diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c new file mode 100644 index 0000000000..aa90169ee7 --- /dev/null +++ b/examples/libsmbclient/smbwrapper/select.c @@ -0,0 +1,124 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + Samba select/poll implementation + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Derrell Lipman 2003-2005 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + * WHY THIS FILE? + * + * This file implements the two functions in the select() family, as required + * by samba. The samba native functions, though, implement a pipe to help + * alleviate a deadlock problem, but which creates problems of its own (the + * timeout stops working correctly). Those functions also require that all + * signal handlers call a function which writes to the pipe -- a task which is + * difficult to do in the smbwrapper environment. + */ + + +#include +#include +#include + +int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) +{ + int ret; + fd_set *readfds2, readfds_buf; + + /* If readfds is NULL we need to provide our own set. */ + if (readfds) { + readfds2 = readfds; + } else { + readfds2 = &readfds_buf; + FD_ZERO(readfds2); + } + + errno = 0; + ret = select(maxfd,readfds2,writefds,errorfds,tval); + + if (ret <= 0) { + FD_ZERO(readfds2); + if (writefds) + FD_ZERO(writefds); + if (errorfds) + FD_ZERO(errorfds); + } + + return ret; +} + +/******************************************************************* + Similar to sys_select() but catch EINTR and continue. + This is what sys_select() used to do in Samba. +********************************************************************/ + +int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval) +{ + int ret; + fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf; + struct timeval tval2, *ptval, end_time, now_time; + extern void GetTimeOfDay(struct timeval *tval); + + readfds2 = (readfds ? &readfds_buf : NULL); + writefds2 = (writefds ? &writefds_buf : NULL); + errorfds2 = (errorfds ? &errorfds_buf : NULL); + if (tval) { + GetTimeOfDay(&end_time); + end_time.tv_sec += tval->tv_sec; + end_time.tv_usec += tval->tv_usec; + end_time.tv_sec += end_time.tv_usec / 1000000; + end_time.tv_usec %= 1000000; + ptval = &tval2; + } else { + ptval = NULL; + } + + do { + if (readfds) + readfds_buf = *readfds; + if (writefds) + writefds_buf = *writefds; + if (errorfds) + errorfds_buf = *errorfds; + if (tval) { + GetTimeOfDay(&now_time); + tval2.tv_sec = end_time.tv_sec - now_time.tv_sec; + tval2.tv_usec = end_time.tv_usec - now_time.tv_usec; + if ((signed long) tval2.tv_usec < 0) { + tval2.tv_usec += 1000000; + tval2.tv_sec--; + } + if ((signed long) tval2.tv_sec < 0) { + ret = 0; + break; /* time has already elapsed */ + } + } + + ret = sys_select(maxfd, readfds2, writefds2, errorfds2, ptval); + } while (ret == -1 && errno == EINTR); + + if (readfds) + *readfds = readfds_buf; + if (writefds) + *writefds = writefds_buf; + if (errorfds) + *errorfds = errorfds_buf; + + return ret; +} -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- examples/libsmbclient/smbwrapper/select.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/libsmbclient/smbwrapper/select.c') diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c index aa90169ee7..c379ebd3da 100644 --- a/examples/libsmbclient/smbwrapper/select.c +++ b/examples/libsmbclient/smbwrapper/select.c @@ -7,7 +7,7 @@ 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 2 of the License, or + 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, -- cgit From 58e9534300430fa4f2bcb50fb2d1d2990bdbe636 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:57:11 +0000 Subject: r23785: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit d0e89d246d8e5e64196d6c1d16d39a70579ca42f) --- examples/libsmbclient/smbwrapper/select.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'examples/libsmbclient/smbwrapper/select.c') diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c index c379ebd3da..4e87a2e2e8 100644 --- a/examples/libsmbclient/smbwrapper/select.c +++ b/examples/libsmbclient/smbwrapper/select.c @@ -16,8 +16,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* -- cgit From 735e98759c0f860727c24c4cdb14235abdeb8879 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Wed, 16 Jan 2008 14:37:40 +0000 Subject: Replace GetTimeOfDay() with gettimeofday() in example program. GetTimeOfDay() seems to no longer be exported. For the smbsh example, just use the native gettimeofday() for now. (This used to be commit 296a6783fbc03460e87ac4136a0a9e6d2743b2ff) --- examples/libsmbclient/smbwrapper/select.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'examples/libsmbclient/smbwrapper/select.c') diff --git a/examples/libsmbclient/smbwrapper/select.c b/examples/libsmbclient/smbwrapper/select.c index 4e87a2e2e8..bb7a25f13e 100644 --- a/examples/libsmbclient/smbwrapper/select.c +++ b/examples/libsmbclient/smbwrapper/select.c @@ -72,13 +72,12 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf int ret; fd_set *readfds2, readfds_buf, *writefds2, writefds_buf, *errorfds2, errorfds_buf; struct timeval tval2, *ptval, end_time, now_time; - extern void GetTimeOfDay(struct timeval *tval); readfds2 = (readfds ? &readfds_buf : NULL); writefds2 = (writefds ? &writefds_buf : NULL); errorfds2 = (errorfds ? &errorfds_buf : NULL); if (tval) { - GetTimeOfDay(&end_time); + gettimeofday(&end_time, NULL); end_time.tv_sec += tval->tv_sec; end_time.tv_usec += tval->tv_usec; end_time.tv_sec += end_time.tv_usec / 1000000; @@ -96,7 +95,7 @@ int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorf if (errorfds) errorfds_buf = *errorfds; if (tval) { - GetTimeOfDay(&now_time); + gettimeofday(&now_time, NULL); tval2.tv_sec = end_time.tv_sec - now_time.tv_sec; tval2.tv_usec = end_time.tv_usec - now_time.tv_usec; if ((signed long) tval2.tv_usec < 0) { -- cgit