samba: share select wrappers.
authorGünther Deschner <gd@samba.org>
Fri, 1 Oct 2010 08:08:15 +0000 (10:08 +0200)
committerGünther Deschner <gd@samba.org>
Fri, 1 Oct 2010 20:30:22 +0000 (22:30 +0200)
Guenther

19 files changed:
lib/util/config.mk
lib/util/select.c [moved from source3/lib/select.c with 97% similarity]
lib/util/select.h [new file with mode: 0644]
lib/util/wscript_build
source3/Makefile.in
source3/client/client.c
source3/include/proto.h
source3/lib/events.c
source3/lib/g_lock.c
source3/lib/packet.c
source3/lib/readline.c
source3/lib/util_sock.c
source3/libsmb/nmblib.c
source3/nmbd/nmbd_packets.c
source3/smbd/process.c
source3/utils/smbfilter.c
source3/winbindd/winbindd_dual.c
source3/wscript_build
source4/lib/smbreadline/smbreadline.c

index 0a5d62ff86f0dbf5751da5f8dcb118ef9d69cc78..719f5f2493d3115b3ff9b4fea7d987a078e2e239 100644 (file)
@@ -35,7 +35,8 @@ LIBSAMBA-UTIL_OBJ_FILES = $(addprefix $(libutilsrcdir)/, \
                smb_threads.o \
                params.o \
                parmlist.o \
-               util_id.o)
+               util_id.o
+               select.o)
 
 PUBLIC_HEADERS += $(addprefix $(libutilsrcdir)/, util.h \
                                 dlinklist.h \
similarity index 97%
rename from source3/lib/select.c
rename to lib/util/select.c
index 846e6af1de69d0ee1b8e66fb9274e311257d9f38..61df6495261c22b31497b7354eb4bd5f2ba55fa7 100644 (file)
@@ -1,29 +1,32 @@
-/* 
+/*
    Unix SMB/Netbios implementation.
    Version 3.0
    Samba select/poll implementation
    Copyright (C) Andrew Tridgell 1992-1998
-   
+
    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 "includes.h"
+#include "system/filesys.h"
+#include "system/select.h"
+#include "lib/util/select.h"
 
-/* This is here because it allows us to avoid a nasty race in signal handling. 
+/* This is here because it allows us to avoid a nasty race in signal handling.
    We need to guarantee that when we get a signal we get out of a select immediately
-   but doing that involves a race condition. We can avoid the race by getting the 
-   signal handler to write to a pipe that is in the select/poll list 
+   but doing that involves a race condition. We can avoid the race by getting the
+   signal handler to write to a pipe that is in the select/poll list
 
    This means all Samba signal handlers should call sys_select_signal().
 */
@@ -33,7 +36,7 @@ static int select_pipe[2];
 static volatile unsigned pipe_written, pipe_read;
 
 /*******************************************************************
- Call this from all Samba signal handlers if you want to avoid a 
+ Call this from all Samba signal handlers if you want to avoid a
  nasty signal race condition.
 ********************************************************************/
 
diff --git a/lib/util/select.h b/lib/util/select.h
new file mode 100644 (file)
index 0000000..13c85ce
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+   Unix SMB/Netbios implementation.
+   Samba select/poll implementation
+   Copyright (C) Andrew Tridgell 1992-1998
+
+   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 _select_h_
+#define _select_h_
+
+/* The following definitions come from lib/util/select.c  */
+
+void sys_select_signal(char c);
+int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval);
+int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval);
+
+#endif
index 0da6ec5b265fc9cd9e4a9d26e761bb8d148feab5..457dee2e19c1b12fb92088a2ab58c04d23526622 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python
 
 bld.SAMBA_LIBRARY('LIBSAMBA-UTIL',
-       source='xfile.c debug.c fault.c signal.c system.c time.c genrand.c dprintf.c util_str.c rfc1738.c substitute.c util_strlist.c util_file.c data_blob.c util.c blocking.c util_net.c fsusage.c ms_fnmatch.c mutex.c idtree.c become_daemon.c rbtree.c talloc_stack.c smb_threads.c params.c parmlist.c util_id.c',
+       source='xfile.c debug.c fault.c signal.c system.c time.c genrand.c dprintf.c util_str.c rfc1738.c substitute.c util_strlist.c util_file.c data_blob.c util.c blocking.c util_net.c fsusage.c ms_fnmatch.c mutex.c idtree.c become_daemon.c rbtree.c talloc_stack.c smb_threads.c params.c parmlist.c util_id.c select.c',
        public_deps='talloc LIBCRYPTO CHARSET execinfo UID_WRAPPER tevent',
        public_headers='attr.h byteorder.h data_blob.h debug.h memory.h mutex.h safe_string.h time.h talloc_stack.h xfile.h dlinklist.h util.h tevent_ntstatus.h tevent_unix.h',
         header_path= [ ('dlinklist.h util.h', '.'), ('*', 'util') ],
index 8a0364d17484b8423a1b2cdc8ea750fc6960ef4d..139ea70909dcd1e9be5bb2ff861d36de3c352ca7 100644 (file)
@@ -430,7 +430,8 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \
                   ../lib/util/become_daemon.o ../lib/util/system.o \
                   ../lib/util/tevent_unix.o ../lib/util/tevent_ntstatus.o \
                   ../lib/util/smb_threads.o ../lib/util/util_id.o \
-                  ../lib/util/blocking.o ../lib/util/rfc1738.o 
+                  ../lib/util/blocking.o ../lib/util/rfc1738.o \
+                  ../lib/util/select.o
 
 CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \
                         ../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \
@@ -460,7 +461,7 @@ LIB_OBJ = $(LIBSAMBAUTIL_OBJ) $(UTIL_OBJ) $(CRYPTO_OBJ) \
          lib/util.o lib/util_names.o \
          lib/util_sock.o lib/sock_exec.o lib/util_sec.o \
          lib/substitute.o lib/dbwrap_util.o \
-         lib/ms_fnmatch.o lib/select.o lib/errmap_unix.o \
+         lib/ms_fnmatch.o lib/errmap_unix.o \
          lib/tallocmsg.o lib/dmallocmsg.o \
          libsmb/clisigning.o libsmb/smb_signing.o \
          lib/iconv.o lib/pam_errors.o intl/lang_tdb.o \
index 86d64f6afa539b9d54fe2d85e3b03a001ba39abc..1432d95c229ab0b98c4a65a1d2f80b839e96e6ba 100644 (file)
@@ -25,6 +25,7 @@
 #include "popt_common.h"
 #include "client/client_proto.h"
 #include "../librpc/gen_ndr/cli_srvsvc.h"
+#include "../lib/util/select.h"
 
 #ifndef REGISTER
 #define REGISTER 0
index 866836f99fdca6dbf589942ef815150fa47e3733..d19ce81a44e5972aa56b35845f5ea110c59ab350 100644 (file)
@@ -716,12 +716,6 @@ NTSTATUS se_create_child_secdesc_buf(TALLOC_CTX *ctx,
                                        const struct security_descriptor *parent_ctr,
                                        bool container);
 
-/* The following definitions come from lib/select.c  */
-
-void sys_select_signal(char c);
-int sys_select(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval);
-int sys_select_intr(int maxfd, fd_set *readfds, fd_set *writefds, fd_set *errorfds, struct timeval *tval);
-
 /* The following definitions come from lib/sendfile.c  */
 
 ssize_t sys_sendfile(int tofd, int fromfd, const DATA_BLOB *header, SMB_OFF_T offset, size_t count);
index 21a13b63fb74cc83d31baaa20632e0aac29da5a9..70a0d7c302c9b53c9c8ebe523b1e7cd8925ec023 100644 (file)
@@ -20,6 +20,7 @@
 
 #include "includes.h"
 #include <tevent_internal.h>
+#include "../lib/util/select.h"
 
 /*
  * Return if there's something in the queue
index 2c065029e7af3463693c7294457bfe76026ef5e4..378e464b5ce3732143def20524c4170d9e6ff793 100644 (file)
@@ -21,6 +21,7 @@
 #include "g_lock.h"
 #include "librpc/gen_ndr/messaging.h"
 #include "ctdbd_conn.h"
+#include "../lib/util/select.h"
 
 static NTSTATUS g_lock_force_unlock(struct g_lock_ctx *ctx, const char *name,
                                    struct server_id pid);
index c131b973bc3f525e5dbfda71277360b59bbc48b6..fefb74a0c57c8f37b6222e763061360297b9f919 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include "../lib/util/select.h"
 
 struct packet_context {
        int fd;
index 4b82291eca444fe49a31bf89800624f46fb0e330..1be0e05f7de90d30ce763eb8cef5af28842cf55e 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "../lib/util/select.h"
 
 #ifdef HAVE_LIBREADLINE
 #  ifdef HAVE_READLINE_READLINE_H
index 2b338162934227e8d2b69f38a80a1d7c08a72750..188e11702efe34d5af77627a8a168a7a21bfbef2 100644 (file)
@@ -22,6 +22,7 @@
 #include "includes.h"
 #include "memcache.h"
 #include "../lib/async_req/async_sock.h"
+#include "../lib/util/select.h"
 
 /****************************************************************************
  Get a port number in host byte order from a sockaddr_storage.
index 1c95d0e99f6d5097f99830f48beacae0fdc4f412..943cbcbe6db463e232a7325a52c7af4986faa63c 100644 (file)
@@ -20,6 +20,7 @@
 */
 
 #include "includes.h"
+#include "../lib/util/select.h"
 
 static const struct opcode_names {
        const char *nmb_opcode_name;
index 2dd218aece0b9b721796036cafd6ca8d043aeadd..5d5a67bf62be2dcfddba4d1a2ff9e1adb04bea83 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "includes.h"
 #include "nmbd/nmbd.h"
+#include "../lib/util/select.h"
 
 extern int ClientNMB;
 extern int ClientDGRAM;
index 4db54f39c0c961d03f9c103b7f888460ff56a387..a484dfd3f25909159f4ac04b4b8ba12e4c38fdb3 100644 (file)
@@ -24,6 +24,7 @@
 #include "librpc/gen_ndr/messaging.h"
 #include "../lib/async_req/async_sock.h"
 #include "ctdbd_conn.h"
+#include "../lib/util/select.h"
 
 extern bool global_machine_password_needs_changing;
 
index 65d846124b3f1858dc5b843fbe78943732b955aa..9d3e46825ffa22f890df5c18b66fb3c849ffb52d 100644 (file)
@@ -18,6 +18,7 @@
 */
 
 #include "includes.h"
+#include "../lib/util/select.h"
 
 #define SECURITY_MASK 0
 #define SECURITY_SET  0
index a6cc64a7b5ed4626b14c5656b4ab22a446321f2e..a4d8b8ac412f8c5df7e7ada37f74636d83c37e96 100644 (file)
@@ -32,6 +32,7 @@
 #include "../../nsswitch/libwbclient/wbc_async.h"
 #include "librpc/gen_ndr/messaging.h"
 #include "secrets.h"
+#include "../lib/util/select.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_WINBIND
index ff091b5e8a96d999158b0a0b083a0d10467de859..0d70a936ecc4e24a93051e9a96a85eff63ce965b 100644 (file)
@@ -162,7 +162,8 @@ UTIL_SRC = '''../lib/util/rbtree.c ../lib/util/signal.c ../lib/util/time.c
                    ../lib/util/become_daemon.c ../lib/util/system.c
                    ../lib/util/tevent_unix.c ../lib/util/tevent_ntstatus.c
                    ../lib/util/smb_threads.c ../lib/util/util_id.c
-                   ../lib/util/blocking.c ../lib/util/rfc1738.c '''
+                   ../lib/util/blocking.c ../lib/util/rfc1738.c
+                   ../lib/util/select.c'''
 
 LIBTEVENT_SRC0 = ''
 
@@ -194,7 +195,7 @@ LIB_SRC = '''${LIBSAMBAUTIL_SRC} ${UTIL_SRC}
           lib/util.c lib/util_names.c
           lib/util_sock.c lib/sock_exec.c lib/util_sec.c
           lib/substitute.c lib/dbwrap_util.c
-          lib/ms_fnmatch.c lib/select.c lib/errmap_unix.c
+          lib/ms_fnmatch.c lib/errmap_unix.c
           lib/tallocmsg.c lib/dmallocmsg.c
           libsmb/clisigning.c libsmb/smb_signing.c
           lib/iconv.c lib/pam_errors.c intl/lang_tdb.c
index b07417357f63bdb6e937a18334b82059a8a79ccc..fa59e5d7d53ae8fb86bc3523817bb252a1db9849 100644 (file)
 #include "system/readline.h"
 #include "lib/smbreadline/smbreadline.h"
 
-/*******************************************************************
- Similar to sys_select() but catch EINTR and continue.
- This is what sys_select() used to do in Samba.
-********************************************************************/
-
-static 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;
-
-       readfds2 = (readfds ? &readfds_buf : NULL);
-       writefds2 = (writefds ? &writefds_buf : NULL);
-       errorfds2 = (errorfds ? &errorfds_buf : NULL);
-       ptval = (tval ? &tval2 : NULL);
-
-       do {
-               if (readfds)
-                       readfds_buf = *readfds;
-               if (writefds)
-                       writefds_buf = *writefds;
-               if (errorfds)
-                       errorfds_buf = *errorfds;
-               if (tval)
-                       tval2 = *tval;
-
-               /* We must use select and not sys_select here. If we use
-                  sys_select we'd lose the fact a signal occurred when sys_select
-                  read a byte from the pipe. Fix from Mark Weaver
-                  <mark-clist@npsl.co.uk>
-               */
-
-               ret = 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;
-}
-
 /****************************************************************************
  Display the prompt and wait for input. Call callback() regularly
 ****************************************************************************/