The branch, master has been updated
via e7054efb97d s3:selftest: run smb2.{bench,connect,credits,ioctl,rw}
over bsd-tstream
via c10f9ee940a selftest: don't skip smb2.bench
via 14ee5fadcf7 s3:libsmb: add 'client smb transport:force_bsd_tstream
= yes' option
via 7b68bb03eac libcli/smb: add smbXcli_transport_bsd_tstream()
via 10808a3ce92 libcli/smb: add smbXcli_transport_tstream()
via 5c8e88e869a libcli/smb: make read_smb_more non-static
via 4150cb2bc4f libcli/smb: abstract transport function calls
via 634f974893e s3:client: make use of smbXcli_conn_monitor_once()
via 8e58f090709 libcli/smb: add smbXcli_conn_monitor_{send,recv,once}()
via 0ac1cf07e4c libcli/smb: let smbXcli_transport_bsd() take an fd by
reference
via 0a6011f72b9 s3:libsmb: let smbsock_connect_recv() return
smbXcli_transport
via e66db40555d s3:libsmb: let smbsock_connect() return
smbXcli_transport
via 2392b89ffd1 s3:libsmb: let smbsock_any_connect_recv return
smbXcli_transport
via 7376dabd155 s4:libcli: let struct smbcli_socket hold struct
smbXcli_transport instead of sockfd
via 6288ff2d460 s3:libsmb: let smbsock_any_connect() return
smbXcli_transport
via ca87a50563c s3:winbindd: let find_dc() call smbXcli_transport_bsd()
via a3773c942cc s3:winbindd: let cm_open_connection() call
smbXcli_transport_bsd()
via f8b9c08cfff s3:libsmb: let cli_connect_sock_recv() return
smbXcli_transport
via 49acd7b3842 s3:libsmb: pass smbXcli_transport to cli_state_create()
via efd4089ef52 libcli/smb: pass smbXcli_transport to
smbXcli_conn_create()
via ac3742af8bc libcli/smb: let smbXcli_conn_create() call
smbXcli_transport_bsd()
via f3ef6e3bc09 libcli/smb: introduce smbXcli_transport_bsd
via 4262b8a809f libcli/smb: merge smb_transport library into
cli_smb_common
via b408e9f4a0c async_sock: add wait_for_error_send/recv
via 69eb53d4cbf async_sock: move
samba_socket_{poll,sock,poll_or_sock}_error() from util_net.c to async_sock.c
via b9273b3dc60 libcli/named_pipe_auth: add
tstream_npa_monitor_send/recv
via 225d1c34062 lib/tsocket: implement tstream_bsd_monitor_send/recv
via 18e304487c9 lib/tsocket: add tstream_monitor_send/recv
infrastructure
via e1de81f297c lib/tsocket: allow only one tstream_disconnect_send/recv
via c1fe1338155 lib/tsocket: make use of tevent_req_set_cleanup_fn()
instead of talloc_set_destructor()
via b27fc1cfd5f s4:torture/smb2: add explicit timeout handling to
async_credits tests
via efe95625de8 s4:torture/smb2: force a disconnect on all connections
as async_credits tests
via fff20f4ea64 s4:torture/smb2: let max_async_credits tests start the
loop only when everything is ready
via 2401f844c8b tevent: version 0.17.0
via 708ee7834d1 tevent: add tevent_reset_immediate()
via d23142643bf tevent: Add tevent_context_set_wait_timeout()
from 58c64ba25ad lib:util: Disable logging to syslog for startup messages
https://git.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit e7054efb97d574cd03ce409082f6c324922e16f4
Author: Stefan Metzmacher <[email protected]>
Date: Thu May 22 10:59:46 2025 +0200
s3:selftest: run smb2.{bench,connect,credits,ioctl,rw} over bsd-tstream
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
Autobuild-User(master): Stefan Metzmacher <[email protected]>
Autobuild-Date(master): Wed Jun 18 19:02:29 UTC 2025 on atb-devel-224
commit c10f9ee940a926eb9e52d2b753c55cdd92883f61
Author: Stefan Metzmacher <[email protected]>
Date: Wed Apr 30 13:56:17 2025 +0200
selftest: don't skip smb2.bench
This runs each test for 10 seconds and is a good
stress test for the transport layer.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 14ee5fadcf7f2c075bb008337838d96dff156541
Author: Stefan Metzmacher <[email protected]>
Date: Fri May 16 11:46:36 2025 +0200
s3:libsmb: add 'client smb transport:force_bsd_tstream = yes' option
This can be used to force the tstream based code path in smbXcli_conn.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 7b68bb03eac5449d404c0cc930afe2446b437cd7
Author: Stefan Metzmacher <[email protected]>
Date: Fri May 16 11:34:37 2025 +0200
libcli/smb: add smbXcli_transport_bsd_tstream()
This can be used to force the usage of the tstream code path even
for bsd sockets.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 10808a3ce925f3a9a4ca6149c01ce01dbc1918ef
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 20:29:55 2025 +0200
libcli/smb: add smbXcli_transport_tstream()
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 5c8e88e869aab5ea3b2c993f07bb89f08a6023ea
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 21:37:16 2025 +0200
libcli/smb: make read_smb_more non-static
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 4150cb2bc4f6c356183a2c2ec344a2f58fe6ec3b
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 21:15:20 2025 +0200
libcli/smb: abstract transport function calls
In future we'll have transports without a bsd
socket fd.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 634f974893ef8d07a01cfa343a7cd39dd4ec60c8
Author: Stefan Metzmacher <[email protected]>
Date: Thu May 15 13:59:00 2025 +0200
s3:client: make use of smbXcli_conn_monitor_once()
This makes it possible to run checks based on
a tevent_context in future.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 8e58f090709b7f88760c618ebc53d50c552a426f
Author: Stefan Metzmacher <[email protected]>
Date: Thu May 15 13:48:20 2025 +0200
libcli/smb: add smbXcli_conn_monitor_{send,recv,once}()
smbXcli_conn_monitor_{send,recv} can be used to monitor
a connection over a long time. It will only come back
if there's a connection error.
smbXcli_conn_monitor_once() will be used by sync callers
without a long term tevent context and needs to be called
multiple times per second in order to work correctly.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 0ac1cf07e4c9f858e159b9b8c856de8dbd65c93b
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 21 15:25:26 2025 +0200
libcli/smb: let smbXcli_transport_bsd() take an fd by reference
This allows it to set the callers value to -1 when it was moved.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 0a6011f72b9321e5d1fae297ccd188ba5e2e98b8
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 17:41:14 2025 +0200
s3:libsmb: let smbsock_connect_recv() return smbXcli_transport
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit e66db40555d76152c774f0d7fe66fb76ddeb63d2
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 17:11:49 2025 +0200
s3:libsmb: let smbsock_connect() return smbXcli_transport
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 2392b89ffd1a0a22cedf29036ffad549942d2af9
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 15:38:34 2025 +0200
s3:libsmb: let smbsock_any_connect_recv return smbXcli_transport
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 7376dabd1558b9d40770e68ef51bba417f91ba3f
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 16:46:55 2025 +0200
s4:libcli: let struct smbcli_socket hold struct smbXcli_transport instead
of sockfd
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 6288ff2d460653c7459381f8cf2eac4a91cc4ade
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 15:44:28 2025 +0200
s3:libsmb: let smbsock_any_connect() return smbXcli_transport
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit ca87a50563c3541132efcac3f4e366791b6743bd
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 16:11:15 2025 +0200
s3:winbindd: let find_dc() call smbXcli_transport_bsd()
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit a3773c942cc5272eacd1cef005f0212ac5ea602c
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 15:57:05 2025 +0200
s3:winbindd: let cm_open_connection() call smbXcli_transport_bsd()
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit f8b9c08cfff501a6d41f9dc0317858eb7b37cd28
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 15:22:48 2025 +0200
s3:libsmb: let cli_connect_sock_recv() return smbXcli_transport
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 49acd7b3842220a3c6b99f5741134812317eaa98
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 15:01:20 2025 +0200
s3:libsmb: pass smbXcli_transport to cli_state_create()
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit efd4089ef52efc16baed82e5b63581a177146402
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 14:30:08 2025 +0200
libcli/smb: pass smbXcli_transport to smbXcli_conn_create()
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit ac3742af8bc6cd02bb1ba01581f5489e85d36be8
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 22:15:40 2025 +0200
libcli/smb: let smbXcli_conn_create() call smbXcli_transport_bsd()
The next step will pass struct smbXcli_transport from the caller.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit f3ef6e3bc093155809560a66a5b2a57d3c1235b1
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 14:21:31 2025 +0200
libcli/smb: introduce smbXcli_transport_bsd
The next commits will pass an smbXcli_transport to
smbXcli_conn_create() instead of a plain 'int fd'.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 4262b8a809f3e7918abefd7af6d17aa8dc90133d
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 7 21:35:24 2025 +0200
libcli/smb: merge smb_transport library into cli_smb_common
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit b408e9f4a0c7b3295ca67f0a4a2844436dc15705
Author: Stefan Metzmacher <[email protected]>
Date: Tue May 20 20:20:30 2025 +0200
async_sock: add wait_for_error_send/recv
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 69eb53d4cbffc76b9c089ef11840c1008dc96ff3
Author: Stefan Metzmacher <[email protected]>
Date: Thu May 22 10:06:53 2025 +0200
async_sock: move samba_socket_{poll,sock,poll_or_sock}_error() from
util_net.c to async_sock.c
The change to LGPL is also intended.
It will be used in the the next commit that adds
wait_for_error_send/recv.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit b9273b3dc60b87aaf9ec1145918a9328bef670bf
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 21 15:08:42 2025 +0200
libcli/named_pipe_auth: add tstream_npa_monitor_send/recv
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 225d1c34062404b4bca59f3a03e102942d56a373
Author: Stefan Metzmacher <[email protected]>
Date: Wed May 21 14:57:15 2025 +0200
lib/tsocket: implement tstream_bsd_monitor_send/recv
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 18e304487c9d247f093c890cde9d73c2a95daae1
Author: Stefan Metzmacher <[email protected]>
Date: Thu May 15 12:01:12 2025 +0200
lib/tsocket: add tstream_monitor_send/recv infrastructure
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit e1de81f297ce96ca07f7df0c3a34811f8f782fc9
Author: Stefan Metzmacher <[email protected]>
Date: Fri May 16 10:04:25 2025 +0200
lib/tsocket: allow only one tstream_disconnect_send/recv
And don't allow readv and writev anymore.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit c1fe1338155a3fcaf8082edba0dbb7768a071703
Author: Stefan Metzmacher <[email protected]>
Date: Thu May 15 14:32:01 2025 +0200
lib/tsocket: make use of tevent_req_set_cleanup_fn() instead of
talloc_set_destructor()
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit b27fc1cfd5f06433381ef802adee25a58b83175c
Author: Stefan Metzmacher <[email protected]>
Date: Mon May 26 13:14:53 2025 +0200
s4:torture/smb2: add explicit timeout handling to async_credits tests
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit efe95625de849544288c8ef42c9504ef615f913d
Author: Stefan Metzmacher <[email protected]>
Date: Mon May 26 13:01:48 2025 +0200
s4:torture/smb2: force a disconnect on all connections as async_credits
tests
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit fff20f4ea6417a763a2e3a2bf4e1c71d0fd6b614
Author: Stefan Metzmacher <[email protected]>
Date: Mon May 26 12:21:08 2025 +0200
s4:torture/smb2: let max_async_credits tests start the loop only when
everything is ready
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 2401f844c8beb7e856b79fb57f8e4c079b3fb0f0
Author: Stefan Metzmacher <[email protected]>
Date: Fri May 23 14:46:15 2025 +0200
tevent: version 0.17.0
- add tevent_context_set_wait_timeout()
- add tevent_reset_immediate()
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit 708ee7834d1f2fbadd7a21ea1e503238e4b30d70
Author: Stefan Metzmacher <[email protected]>
Date: Fri May 23 14:26:38 2025 +0200
tevent: add tevent_reset_immediate()
This is a much better api than using
tevent_schedule_immediate() with a NULL handler,
while the tevent_context is still required as argument.
Note the tevent-0.16.2.sigs changes will be reverted in
the 'tevent 0.17.0' commit.
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
commit d23142643bf7f1d13b1f2996a68b131675eeac16
Author: Volker Lendecke <[email protected]>
Date: Mon Mar 10 21:12:28 2025 +0100
tevent: Add tevent_context_set_wait_timeout()
Mainly to make tevent_loop_once() return immediately with
-1/errno=EAGAIN for polling behaviour.
Note the tevent-0.16.2.sigs changes will be reverted in
the 'tevent 0.17.0' commit.
Pair-Programmed-With: Stefan Metzmacher <[email protected]>
Signed-off-by: Volker Lendecke <[email protected]>
Signed-off-by: Stefan Metzmacher <[email protected]>
Reviewed-by: Volker Lendecke <[email protected]>
-----------------------------------------------------------------------
Summary of changes:
lib/async_req/async_sock.c | 179 +++++++
lib/async_req/async_sock.h | 19 +
lib/async_req/wscript_build | 2 +-
.../ABI/{tevent-0.16.1.sigs => tevent-0.17.0.sigs} | 3 +
lib/tevent/tevent.c | 40 ++
lib/tevent/tevent.h | 36 ++
lib/tevent/tevent_epoll.c | 15 +-
lib/tevent/tevent_immediate.c | 2 +-
lib/tevent/tevent_internal.h | 30 ++
lib/tevent/tevent_poll.c | 15 +-
lib/tevent/tevent_timed.c | 8 +-
lib/tevent/wscript | 2 +-
lib/tsocket/tsocket.c | 249 ++++++++-
lib/tsocket/tsocket.h | 34 ++
lib/tsocket/tsocket_bsd.c | 274 ++++++++--
lib/tsocket/tsocket_internal.h | 8 +
lib/tsocket/wscript | 2 +-
lib/util/util_net.c | 99 ----
lib/util/util_net.h | 14 -
libcli/named_pipe_auth/npa_tstream.c | 85 +++
libcli/smb/read_smb.c | 3 +-
libcli/smb/read_smb.h | 2 +
libcli/smb/smbXcli_base.c | 585 +++++++++++++++++++--
libcli/smb/smbXcli_base.h | 32 +-
libcli/smb/wscript | 18 +-
selftest/skip | 19 +-
source3/client/client.c | 9 +-
source3/libsmb/cliconnect.c | 22 +-
source3/libsmb/clientgen.c | 6 +-
source3/libsmb/proto.h | 3 +-
source3/libsmb/smbsock_connect.c | 109 ++--
source3/libsmb/smbsock_connect.h | 28 +-
source3/selftest/tests.py | 14 +
source3/smbd/smb2_server.c | 1 +
source3/torture/test_smbsock_any_connect.c | 11 +-
source3/torture/torture.c | 39 +-
source3/winbindd/winbindd_cm.c | 57 +-
source4/libcli/raw/clisocket.c | 21 +-
source4/libcli/raw/clitransport.c | 6 +-
source4/libcli/raw/libcliraw.h | 2 +-
source4/libcli/smb2/transport.c | 7 +-
source4/libcli/smb_composite/connect_nego.c | 5 +-
source4/torture/smb2/credits.c | 85 ++-
source4/torture/smb2/multichannel.c | 14 +-
44 files changed, 1815 insertions(+), 399 deletions(-)
copy lib/tevent/ABI/{tevent-0.16.1.sigs => tevent-0.17.0.sigs} (98%)
Changeset truncated at 500 lines:
diff --git a/lib/async_req/async_sock.c b/lib/async_req/async_sock.c
index 06ffb942967..e90619056ed 100644
--- a/lib/async_req/async_sock.c
+++ b/lib/async_req/async_sock.c
@@ -24,6 +24,7 @@
#include "replace.h"
#include "system/network.h"
#include "system/filesys.h"
+#include "system/select.h"
#include <talloc.h>
#include <tevent.h>
#include "lib/async_req/async_sock.h"
@@ -33,6 +34,104 @@
/* Note: lib/util/ is currently GPL */
#include "lib/util/tevent_unix.h"
#include "lib/util/samba_util.h"
+#include "lib/util/select.h"
+
+int samba_socket_poll_error(int fd)
+{
+ struct pollfd pfd = {
+ .fd = fd,
+#ifdef POLLRDHUP
+ .events = POLLRDHUP, /* POLLERR and POLLHUP are not needed */
+#endif
+ };
+ int ret;
+
+ errno = 0;
+ ret = sys_poll_intr(&pfd, 1, 0);
+ if (ret == 0) {
+ return 0;
+ }
+ if (ret != 1) {
+ return POLLNVAL;
+ }
+
+ if (pfd.revents & POLLERR) {
+ return POLLERR;
+ }
+ if (pfd.revents & POLLHUP) {
+ return POLLHUP;
+ }
+#ifdef POLLRDHUP
+ if (pfd.revents & POLLRDHUP) {
+ return POLLRDHUP;
+ }
+#endif
+
+ /* should never be reached! */
+ return POLLNVAL;
+}
+
+int samba_socket_sock_error(int fd)
+{
+ int ret, error = 0;
+ socklen_t len = sizeof(error);
+
+ /*
+ * if no data is available check if the socket is in error state. For
+ * dgram sockets it's the way to return ICMP error messages of
+ * connected sockets to the caller.
+ */
+ ret = getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len);
+ if (ret == -1) {
+ return ret;
+ }
+ if (error != 0) {
+ errno = error;
+ return -1;
+ }
+ return 0;
+}
+
+int samba_socket_poll_or_sock_error(int fd)
+{
+ int ret;
+ int poll_error = 0;
+
+ poll_error = samba_socket_poll_error(fd);
+ if (poll_error == 0) {
+ return 0;
+ }
+
+#ifdef POLLRDHUP
+ if (poll_error == POLLRDHUP) {
+ errno = ECONNRESET;
+ return -1;
+ }
+#endif
+
+ if (poll_error == POLLHUP) {
+ errno = EPIPE;
+ return -1;
+ }
+
+ /*
+ * POLLERR and POLLNVAL fallback to
+ * getsockopt(fd, SOL_SOCKET, SO_ERROR)
+ * and force EPIPE as fallback.
+ */
+
+ errno = 0;
+ ret = samba_socket_sock_error(fd);
+ if (ret == 0) {
+ errno = EPIPE;
+ }
+
+ if (errno == 0) {
+ errno = EPIPE;
+ }
+
+ return -1;
+}
struct async_connect_state {
int fd;
@@ -762,6 +861,86 @@ bool wait_for_read_recv(struct tevent_req *req, int *perr)
return true;
}
+struct wait_for_error_state {
+ struct tevent_fd *fde;
+ int fd;
+};
+
+static void wait_for_error_cleanup(struct tevent_req *req,
+ enum tevent_req_state req_state);
+static void wait_for_error_done(struct tevent_context *ev,
+ struct tevent_fd *fde,
+ uint16_t flags,
+ void *private_data);
+
+struct tevent_req *wait_for_error_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ int fd)
+{
+ struct tevent_req *req = NULL;
+ struct wait_for_error_state *state = NULL;
+
+ req = tevent_req_create(mem_ctx, &state, struct wait_for_error_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->fd = fd;
+
+ tevent_req_set_cleanup_fn(req, wait_for_error_cleanup);
+
+ state->fde = tevent_add_fd(ev,
+ state,
+ state->fd,
+ TEVENT_FD_ERROR,
+ wait_for_error_done,
+ req);
+ if (tevent_req_nomem(state->fde, req)) {
+ return tevent_req_post(req, ev);
+ }
+
+ return req;
+}
+
+static void wait_for_error_cleanup(struct tevent_req *req,
+ enum tevent_req_state req_state)
+{
+ struct wait_for_error_state *state =
+ tevent_req_data(req, struct wait_for_error_state);
+
+ TALLOC_FREE(state->fde);
+ state->fd = -1;
+}
+
+static void wait_for_error_done(struct tevent_context *ev,
+ struct tevent_fd *fde,
+ uint16_t flags,
+ void *private_data)
+{
+ struct tevent_req *req =
+ talloc_get_type_abort(private_data,
+ struct tevent_req);
+ struct wait_for_error_state *state =
+ tevent_req_data(req,
+ struct wait_for_error_state);
+ int ret;
+
+ errno = 0;
+ ret = samba_socket_poll_or_sock_error(state->fd);
+ if (ret == 0) {
+ errno = EPIPE;
+ }
+ if (errno == 0) {
+ errno = EPIPE;
+ }
+
+ tevent_req_error(req, errno);
+}
+
+int wait_for_error_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_unix(req);
+}
+
struct accept_state {
struct tevent_fd *fde;
int listen_sock;
diff --git a/lib/async_req/async_sock.h b/lib/async_req/async_sock.h
index 780195e3725..743f7260787 100644
--- a/lib/async_req/async_sock.h
+++ b/lib/async_req/async_sock.h
@@ -28,6 +28,20 @@
#include <tevent.h>
#include "system/network.h"
+/*
+ * check for POLLERR or POLL*HUP
+ */
+int samba_socket_poll_error(int fd);
+/*
+ * getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len)
+ */
+int samba_socket_sock_error(int fd);
+/*
+ * check for POLL*HUP and fallback to
+ * getsockopt(fd, SOL_SOCKET, SO_ERROR, &error, &len)
+ */
+int samba_socket_poll_or_sock_error(int fd);
+
struct tevent_req *async_connect_send(
TALLOC_CTX *mem_ctx, struct tevent_context *ev, int fd,
const struct sockaddr *address, socklen_t address_len,
@@ -57,6 +71,11 @@ struct tevent_req *wait_for_read_send(TALLOC_CTX *mem_ctx,
bool check_errors);
bool wait_for_read_recv(struct tevent_req *req, int *perr);
+struct tevent_req *wait_for_error_send(TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ int fd);
+int wait_for_error_recv(struct tevent_req *req);
+
struct samba_sockaddr;
struct tevent_req *accept_send(TALLOC_CTX *mem_ctx, struct tevent_context *ev,
int listen_sock);
diff --git a/lib/async_req/wscript_build b/lib/async_req/wscript_build
index 4486a5b2f06..fbf712d57f2 100644
--- a/lib/async_req/wscript_build
+++ b/lib/async_req/wscript_build
@@ -4,7 +4,7 @@
bld.SAMBA_SUBSYSTEM('LIBASYNC_REQ',
source='async_sock.c',
public_deps='talloc tevent iov_buf',
- deps='tevent-util socket-blocking'
+ deps='tevent-util samba-util socket-blocking'
)
bld.SAMBA_BINARY('async_connect_send_test',
diff --git a/lib/tevent/ABI/tevent-0.16.1.sigs
b/lib/tevent/ABI/tevent-0.17.0.sigs
similarity index 98%
copy from lib/tevent/ABI/tevent-0.16.1.sigs
copy to lib/tevent/ABI/tevent-0.17.0.sigs
index f7eba5775df..4cd4226ab80 100644
--- a/lib/tevent/ABI/tevent-0.16.1.sigs
+++ b/lib/tevent/ABI/tevent-0.17.0.sigs
@@ -44,6 +44,7 @@ tevent_common_fd_get_flags: uint16_t (struct tevent_fd *)
tevent_common_fd_set_close_fn: void (struct tevent_fd *, tevent_fd_close_fn_t)
tevent_common_fd_set_flags: void (struct tevent_fd *, uint16_t)
tevent_common_have_events: bool (struct tevent_context *)
+tevent_common_immediate_cancel: void (struct tevent_immediate *)
tevent_common_invoke_fd_handler: int (struct tevent_fd *, uint16_t, bool *)
tevent_common_invoke_immediate_handler: int (struct tevent_immediate *, bool *)
tevent_common_invoke_signal_handler: int (struct tevent_signal *, int, int,
void *, bool *)
@@ -61,6 +62,7 @@ tevent_context_init_byname: struct tevent_context
*(TALLOC_CTX *, const char *)
tevent_context_init_ops: struct tevent_context *(TALLOC_CTX *, const struct
tevent_ops *, void *)
tevent_context_is_wrapper: bool (struct tevent_context *)
tevent_context_same_loop: bool (struct tevent_context *, struct tevent_context
*)
+tevent_context_set_wait_timeout: uint32_t (struct tevent_context *, uint32_t)
tevent_debug: void (struct tevent_context *, enum tevent_debug_level, const
char *, ...)
tevent_fd_get_flags: uint16_t (struct tevent_fd *)
tevent_fd_get_tag: uint64_t (const struct tevent_fd *)
@@ -123,6 +125,7 @@ tevent_req_set_cleanup_fn: void (struct tevent_req *,
tevent_req_cleanup_fn)
tevent_req_set_endtime: bool (struct tevent_req *, struct tevent_context *,
struct timeval)
tevent_req_set_print_fn: void (struct tevent_req *, tevent_req_print_fn)
tevent_req_set_profile: bool (struct tevent_req *)
+tevent_reset_immediate: void (struct tevent_immediate *)
tevent_sa_info_queue_count: size_t (void)
tevent_set_abort_fn: void (void (*)(const char *))
tevent_set_debug: int (struct tevent_context *, void (*)(void *, enum
tevent_debug_level, const char *, va_list), void *)
diff --git a/lib/tevent/tevent.c b/lib/tevent/tevent.c
index 9f4a91953ae..c9f57fece94 100644
--- a/lib/tevent/tevent.c
+++ b/lib/tevent/tevent.c
@@ -544,6 +544,13 @@ struct tevent_context *tevent_context_init_ops(TALLOC_CTX
*mem_ctx,
ev->ops = ops;
ev->additional_data = additional_data;
+ /*
+ * have a default tick time of 30 seconds. This guarantees
+ * that code that uses its own timeout checking will be
+ * able to proceed eventually
+ */
+ tevent_context_set_wait_timeout(ev, 30);
+
ret = ev->ops->context_init(ev);
if (ret != 0) {
talloc_free(ev);
@@ -582,6 +589,31 @@ struct tevent_context *tevent_context_init(TALLOC_CTX
*mem_ctx)
return tevent_context_init_byname(mem_ctx, NULL);
}
+uint32_t tevent_context_set_wait_timeout(struct tevent_context *ev,
+ uint32_t secs)
+{
+ time_t ret = ev->wait_timeout.tv_sec;
+
+ /*
+ * Cut to signed 32-bit time_t. This is the maximum that we
+ * can reasonably expect to fit into time_t. Use that as magic
+ * value for "wait forever". Nobody wants to wait 68 years....
+ */
+ secs = MIN(secs, INT32_MAX);
+
+ /*
+ * "secs == 0" and thus wait_timeout==tevent_timeval_zero()
+ * might have a special meaning for custom tevent loop_once
+ * backend functions. Make this an invalid value, our
+ * internal poll and epoll backends deal with this properly,
+ * see tevent_common_no_timeout()
+ */
+ ev->wait_timeout = tevent_timeval_set((time_t)secs,
+ (secs == 0) ? INT32_MAX: 0);
+
+ return ret;
+}
+
/*
add a fd based event
return NULL on failure (memory allocation error)
@@ -719,6 +751,14 @@ void _tevent_schedule_immediate(struct tevent_immediate
*im,
handler_name, location);
}
+/*
+ reset an immediate event
+*/
+void tevent_reset_immediate(struct tevent_immediate *im)
+{
+ tevent_common_immediate_cancel(im);
+}
+
/*
add a signal event
diff --git a/lib/tevent/tevent.h b/lib/tevent/tevent.h
index 0f40b2bed30..30825315c82 100644
--- a/lib/tevent/tevent.h
+++ b/lib/tevent/tevent.h
@@ -174,6 +174,25 @@ const char **tevent_backend_list(TALLOC_CTX *mem_ctx);
*/
void tevent_set_default_backend(const char *backend);
+/**
+ * @brief Set the default time to wait without tevent_timers pending
+ *
+ * Setting the wait timeout to 0 means polling behaviour, e.g.
+ * tevent_loop_once will return -1/errno=EAGAIN, when all
+ * currently available events were processes.
+ *
+ * Setting it to UINT32_MAX makes tevent_loop_once wait forever.
+ * The default is 30 seconds.
+ *
+ * @param[in] ev The tevent context to set this on
+ *
+ * @param[in] secs The number of seconds to wait without timers
+ *
+ * @return secs The previous wait_timeout value
+ */
+uint32_t tevent_context_set_wait_timeout(struct tevent_context *ev,
+ uint32_t secs);
+
#ifdef DOXYGEN
/**
* @brief Add a file descriptor based event.
@@ -343,6 +362,12 @@ struct tevent_immediate
*_tevent_create_immediate(TALLOC_CTX *mem_ctx,
* @param[in] ctx The tevent_context to run this event
* @param[in] handler The event handler to run when this event fires
* @param[in] private_data Data to pass to the event handler
+ *
+ * @note To cancel an immediate handler, call talloc_free() on the event
returned
+ * from tevent_create_immediate() or call tevent_reset_immediate() to
+ * keep the structure alive for later usage.
+ *
+ * @see tevent_create_immediate, tevent_reset_immediate
*/
void tevent_schedule_immediate(struct tevent_immediate *im,
struct tevent_context *ctx,
@@ -360,6 +385,17 @@ void _tevent_schedule_immediate(struct tevent_immediate
*im,
#handler, __location__);
#endif
+/**
+ * Reset an event for immediate execution.
+ *
+ * Undo the effect of tevent_schedule_immediate().
+ *
+ * @param[in] im The tevent_immediate object to clear the handler
+ *
+ * @see tevent_schedule_immediate.
+ */
+void tevent_reset_immediate(struct tevent_immediate *im);
+
/**
* @brief Associate a custom tag with the event.
*
diff --git a/lib/tevent/tevent_epoll.c b/lib/tevent/tevent_epoll.c
index 233533e4d31..d13641ec347 100644
--- a/lib/tevent/tevent_epoll.c
+++ b/lib/tevent/tevent_epoll.c
@@ -590,14 +590,9 @@ static int epoll_event_loop(struct epoll_event_context
*epoll_ev, struct timeval
int ret, i;
#define MAXEVENTS 1
struct epoll_event events[MAXEVENTS];
- int timeout = -1;
+ int timeout = tevent_common_timeout_msec(tvalp);
int wait_errno;
- if (tvalp) {
- /* it's better to trigger timed events a bit later than too
early */
- timeout = ((tvalp->tv_usec+999) / 1000) + (tvalp->tv_sec*1000);
- }
-
if (epoll_ev->ev->signal_events &&
tevent_common_check_signal(epoll_ev->ev)) {
return 0;
@@ -620,6 +615,14 @@ static int epoll_event_loop(struct epoll_event_context
*epoll_ev, struct timeval
}
if (ret == 0 && tvalp) {
+ /*
+ * tevent_context_set_wait_timeout(0) was used.
+ */
+ if (tevent_common_no_timeout(tvalp)) {
+ errno = EAGAIN;
+ return -1;
+ }
+
/* we don't care about a possible delay here */
tevent_common_loop_timer_delay(epoll_ev->ev);
return 0;
diff --git a/lib/tevent/tevent_immediate.c b/lib/tevent/tevent_immediate.c
index 82f92f1bd78..bf44c45a14b 100644
--- a/lib/tevent/tevent_immediate.c
+++ b/lib/tevent/tevent_immediate.c
@@ -29,7 +29,7 @@
#include "tevent_internal.h"
#include "tevent_util.h"
-static void tevent_common_immediate_cancel(struct tevent_immediate *im)
+void tevent_common_immediate_cancel(struct tevent_immediate *im)
{
const char *create_location = im->create_location;
bool busy = im->busy;
diff --git a/lib/tevent/tevent_internal.h b/lib/tevent/tevent_internal.h
index 75ae114e35f..049a3a6c2e2 100644
--- a/lib/tevent/tevent_internal.h
+++ b/lib/tevent/tevent_internal.h
@@ -417,6 +417,7 @@ struct tevent_context {
* tevent_common_add_timer_v2()
*/
struct tevent_timer *last_zero_timer;
+ struct timeval wait_timeout;
#ifdef HAVE_PTHREAD
struct tevent_context *prev, *next;
@@ -466,10 +467,39 @@ struct tevent_timer *tevent_common_add_timer_v2(struct
tevent_context *ev,
const char *handler_name,
const char *location);
struct timeval tevent_common_loop_timer_delay(struct tevent_context *);
+
+/* timeout values for poll(2) / epoll_wait(2) */
+static inline bool tevent_common_no_timeout(const struct timeval *tv)
+{
+ if ((tv->tv_sec == 0) && (tv->tv_usec == INT32_MAX)) {
+ /*
+ * This is special from
+ * tevent_context_set_wait_timeout(0)
+ */
+ return true;
+ }
+ return false;
+}
+static inline int tevent_common_timeout_msec(const struct timeval *tv)
+{
+ if (tv->tv_sec == INT32_MAX) {
+ return -1;
+ }
+ if (tevent_common_no_timeout(tv)) {
+ /*
+ * This is special from
+ * tevent_context_set_wait_timeout(0)
+ */
+ return 0;
+ }
--
Samba Shared Repository