[PATCH] Remove source3/lib/events.c dependency in nmbd

Jeremy Allison jra at samba.org
Sat Sep 24 03:13:59 UTC 2016


On Fri, Sep 23, 2016 at 08:02:06PM -0700, Jeremy Allison wrote:
> On Fri, Sep 23, 2016 at 06:49:21PM -0700, Jeremy Allison wrote:
> > On Fri, Sep 23, 2016 at 04:44:55PM -0700, Volker Lendecke wrote:
> > > On Fri, Sep 23, 2016 at 12:46:28PM -0700, Jeremy Allison wrote:
> > > > On Fri, Sep 23, 2016 at 11:55:11AM -0700, Jeremy Allison wrote:
> > > > > Is attached. Dirty, but seems to work. Now to try
> > > > > and figure out how to split it up.. :-).
> > > > 
> > > > OK, here's the split-up micro-commit version.
> > > > 
> > > > Passes make test here ! Please review and push
> > > > if you're happy.
> > > 
> > > I've taken a look at the first one and found the attached cosmetic
> > > ones. Ok if I squash them in?
> > 
> > Perfecty fine - thanks ! I should have known better for #1 and #2 :-)
> > #3 I couldn't remember what our coding standards were (and was
> > too lazy to look them up when I was working on it :-).
> > 
> > Please squash and push.
> > 
> > I can take a look at the other users of source4/lib/events.c
> > if you like ?
> 
> I means source3/lib/events.c of course :-).
> 
> I have a patch that removes it now. Testing....

Attached. Applies on top of the nmbd one.

Let's see how it does on make test !
-------------- next part --------------
>From e9917eeaf58ce94d0882fd906390c4b8ad84b659 Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 23 Sep 2016 19:07:39 -0700
Subject: [PATCH 1/3] s3: winbind: Remove dump_event_list() calls.

If needed we can add this into actual tevent.

Preparing to remove source3/lib/events.c

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/winbindd/winbindd_dual.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c
index 17a89a7..161e100 100644
--- a/source3/winbindd/winbindd_dual.c
+++ b/source3/winbindd/winbindd_dual.c
@@ -835,7 +835,7 @@ void winbind_msg_dump_event_list(struct messaging_context *msg_ctx,
 
 	DEBUG(10,("winbind_msg_dump_event_list received\n"));
 
-	dump_event_list(winbind_event_context());
+	DEBUG(0,("dump event list no longer implemented\n"));
 
 	for (child = winbindd_children; child != NULL; child = child->next) {
 
@@ -1240,8 +1240,7 @@ static void child_msg_dump_event_list(struct messaging_context *msg,
 				      DATA_BLOB *data)
 {
 	DEBUG(5,("child_msg_dump_event_list received\n"));
-
-	dump_event_list(winbind_event_context());
+	DEBUG(0,("dump_event_list no longer implemented\n"));
 }
 
 NTSTATUS winbindd_reinit_after_fork(const struct winbindd_child *myself,
-- 
2.7.4


>From 34f92d74dba94bd28631fcc57fdd36f8b73f2f1e Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 23 Sep 2016 19:11:17 -0700
Subject: [PATCH 2/3] s3: server: s3_tevent_context_init() ->
 tevent_context_init().

We can now remove source3/lib/events.c

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/lib/server_contexts.c     | 2 +-
 source3/rpc_server/rpc_ncacn_np.c | 8 ++++----
 source3/smbd/process.c            | 2 +-
 source3/smbd/server.c             | 1 -
 4 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/source3/lib/server_contexts.c b/source3/lib/server_contexts.c
index d49e334..9192fa3 100644
--- a/source3/lib/server_contexts.c
+++ b/source3/lib/server_contexts.c
@@ -31,7 +31,7 @@ struct tevent_context *server_event_context(void)
 		 * autofree context, to avoid side effects in forked
 		 * children exiting.
 		 */
-		server_event_ctx = s3_tevent_context_init(NULL);
+		server_event_ctx = tevent_context_init(NULL);
 	}
 	if (!server_event_ctx) {
 		smb_panic("Could not init server's event context");
diff --git a/source3/rpc_server/rpc_ncacn_np.c b/source3/rpc_server/rpc_ncacn_np.c
index f9c73de..0a69e89 100644
--- a/source3/rpc_server/rpc_ncacn_np.c
+++ b/source3/rpc_server/rpc_ncacn_np.c
@@ -708,9 +708,9 @@ NTSTATUS make_external_rpc_pipe(TALLOC_CTX *mem_ctx,
 		goto out;
 	}
 
-	ev_ctx = s3_tevent_context_init(tmp_ctx);
+	ev_ctx = tevent_context_init(tmp_ctx);
 	if (ev_ctx == NULL) {
-		DEBUG(0, ("s3_tevent_context_init failed\n"));
+		DEBUG(0, ("tevent_context_init failed\n"));
 		status = NT_STATUS_NO_MEMORY;
 		goto out;
 	}
@@ -816,9 +816,9 @@ struct np_proxy_state *make_external_rpc_pipe_p(TALLOC_CTX *mem_ctx,
 		goto fail;
 	}
 
-	ev = s3_tevent_context_init(talloc_tos());
+	ev = tevent_context_init(talloc_tos());
 	if (ev == NULL) {
-		DEBUG(0, ("s3_tevent_context_init failed\n"));
+		DEBUG(0, ("tevent_context_init failed\n"));
 		goto fail;
 	}
 
diff --git a/source3/smbd/process.c b/source3/smbd/process.c
index e3c32f9..bfd837c 100644
--- a/source3/smbd/process.c
+++ b/source3/smbd/process.c
@@ -3224,7 +3224,7 @@ static void smbd_echo_loop(struct smbXsrv_connection *xconn,
 	}
 	state->xconn = xconn;
 	state->parent_pipe = parent_pipe;
-	state->ev = s3_tevent_context_init(state);
+	state->ev = tevent_context_init(state);
 	if (state->ev == NULL) {
 		DEBUG(1, ("tevent_context_init failed\n"));
 		TALLOC_FREE(state);
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index f1e64ac..3cbd089 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -1670,7 +1670,6 @@ extern void build_options(bool screen);
 	 * Initialize the event context. The event context needs to be
 	 * initialized before the messaging context, cause the messaging
 	 * context holds an event context.
-	 * FIXME: This should be s3_tevent_context_init()
 	 */
 	ev_ctx = server_event_context();
 	if (ev_ctx == NULL) {
-- 
2.7.4


>From b5b75a19802c47dc82f12ed43a44e95292d3233c Mon Sep 17 00:00:00 2001
From: Jeremy Allison <jra at samba.org>
Date: Fri, 23 Sep 2016 20:00:33 -0700
Subject: [PATCH 3/3] s3: events. Move events.c to util_event.c

Remove all tevent internal code.

Everything is now stock tevent.

Signed-off-by: Jeremy Allison <jra at samba.org>
---
 source3/include/event.h      |  42 ----
 source3/include/includes.h   |   4 +-
 source3/include/util_event.h |  28 +++
 source3/lib/events.c         | 490 -------------------------------------------
 source3/lib/util_event.c     | 101 +++++++++
 source3/wscript_build        |   2 +-
 6 files changed, 132 insertions(+), 535 deletions(-)
 delete mode 100644 source3/include/event.h
 create mode 100644 source3/include/util_event.h
 delete mode 100644 source3/lib/events.c
 create mode 100644 source3/lib/util_event.c

diff --git a/source3/include/event.h b/source3/include/event.h
deleted file mode 100644
index 108026e..0000000
--- a/source3/include/event.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-   event handling
-   Copyright (C) Andrew Tridgell 1992-1998
-   Copyright (C) Volker Lendecke 2005-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 <tevent.h>
-
-/* The following definitions come from lib/events.c  */
-struct pollfd;
-struct timeval *get_timed_events_timeout(struct tevent_context *event_ctx,
-					 struct timeval *to_ret);
-void dump_event_list(struct tevent_context *event_ctx);
-struct tevent_context *s3_tevent_context_init(TALLOC_CTX *mem_ctx);
-
-bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
-			    struct pollfd **pfds, int *num_pfds,
-			    int *ptimeout);
-bool run_events_poll(struct tevent_context *ev, int pollrtn,
-		     struct pollfd *pfds, int num_pfds);
-
-struct idle_event *event_add_idle(struct tevent_context *event_ctx,
-				  TALLOC_CTX *mem_ctx,
-				  struct timeval interval,
-				  const char *name,
-				  bool (*handler)(const struct timeval *now,
-						  void *private_data),
-				  void *private_data);
diff --git a/source3/include/includes.h b/source3/include/includes.h
index 81bba40..234a564 100644
--- a/source3/include/includes.h
+++ b/source3/include/includes.h
@@ -310,8 +310,8 @@ typedef char fstring[FSTRING_LEN];
 #include "../lib/util/dlinklist.h"
 
 #include <talloc.h>
-
-#include "event.h"
+#include <tevent.h>
+#include "util_event.h"
 
 #include "../lib/util/data_blob.h"
 #include "../lib/util/time.h"
diff --git a/source3/include/util_event.h b/source3/include/util_event.h
new file mode 100644
index 0000000..df608a1
--- /dev/null
+++ b/source3/include/util_event.h
@@ -0,0 +1,28 @@
+/*
+   Unix SMB/CIFS implementation.
+   event handling
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Volker Lendecke 2005-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/>.
+*/
+
+/* The following definitions come from lib/util_event.c  */
+struct idle_event *event_add_idle(struct tevent_context *event_ctx,
+				  TALLOC_CTX *mem_ctx,
+				  struct timeval interval,
+				  const char *name,
+				  bool (*handler)(const struct timeval *now,
+						  void *private_data),
+				  void *private_data);
diff --git a/source3/lib/events.c b/source3/lib/events.c
deleted file mode 100644
index a866ef5..0000000
--- a/source3/lib/events.c
+++ /dev/null
@@ -1,490 +0,0 @@
-/*
-   Unix SMB/CIFS implementation.
-   Timed event library.
-   Copyright (C) Andrew Tridgell 1992-1998
-   Copyright (C) Volker Lendecke 2005-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 "includes.h"
-#include "lib/tevent/tevent_internal.h"
-#include "../lib/util/select.h"
-#include "system/select.h"
-
-struct tevent_poll_private {
-	/*
-	 * Index from file descriptor into the pollfd array
-	 */
-	int *pollfd_idx;
-
-	/*
-	 * Cache for s3_event_loop_once to avoid reallocs
-	 */
-	struct pollfd *pfds;
-};
-
-static struct tevent_poll_private *tevent_get_poll_private(
-	struct tevent_context *ev)
-{
-	struct tevent_poll_private *state;
-
-	state = (struct tevent_poll_private *)ev->additional_data;
-	if (state == NULL) {
-		state = talloc_zero(ev, struct tevent_poll_private);
-		ev->additional_data = (void *)state;
-		if (state == NULL) {
-			DEBUG(10, ("talloc failed\n"));
-		}
-	}
-	return state;
-}
-
-static void count_fds(struct tevent_context *ev,
-		      int *pnum_fds, int *pmax_fd)
-{
-	struct tevent_fd *fde;
-	int num_fds = 0;
-	int max_fd = 0;
-
-	for (fde = ev->fd_events; fde != NULL; fde = fde->next) {
-		if (fde->flags & (TEVENT_FD_READ|TEVENT_FD_WRITE)) {
-			num_fds += 1;
-			if (fde->fd > max_fd) {
-				max_fd = fde->fd;
-			}
-		}
-	}
-	*pnum_fds = num_fds;
-	*pmax_fd = max_fd;
-}
-
-bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx,
-			    struct pollfd **pfds, int *pnum_pfds,
-			    int *ptimeout)
-{
-	struct tevent_poll_private *state;
-	struct tevent_fd *fde;
-	int i, num_fds, max_fd, num_pollfds, idx_len;
-	struct pollfd *fds;
-	struct timeval now, diff;
-	int timeout;
-
-	state = tevent_get_poll_private(ev);
-	if (state == NULL) {
-		return false;
-	}
-	count_fds(ev, &num_fds, &max_fd);
-
-	idx_len = max_fd+1;
-
-	if (talloc_array_length(state->pollfd_idx) < idx_len) {
-		state->pollfd_idx = talloc_realloc(
-			state, state->pollfd_idx, int, idx_len);
-		if (state->pollfd_idx == NULL) {
-			DEBUG(10, ("talloc_realloc failed\n"));
-			return false;
-		}
-	}
-
-	fds = *pfds;
-	num_pollfds = *pnum_pfds;
-
-	if (talloc_array_length(fds) < num_pollfds + num_fds) {
-		fds = talloc_realloc(mem_ctx, fds, struct pollfd,
-					   num_pollfds + num_fds);
-		if (fds == NULL) {
-			DEBUG(10, ("talloc_realloc failed\n"));
-			return false;
-		}
-	}
-
-	memset(&fds[num_pollfds], 0, sizeof(struct pollfd) * num_fds);
-
-	/*
-	 * This needs tuning. We need to cope with multiple fde's for a file
-	 * descriptor. The problem is that we need to re-use pollfd_idx across
-	 * calls for efficiency. One way would be a direct bitmask that might
-	 * be initialized quicker, but our bitmap_init implementation is
-	 * pretty heavy-weight as well.
-	 */
-	for (i=0; i<idx_len; i++) {
-		state->pollfd_idx[i] = -1;
-	}
-
-	for (fde = ev->fd_events; fde; fde = fde->next) {
-		struct pollfd *pfd;
-
-		if ((fde->flags & (TEVENT_FD_READ|TEVENT_FD_WRITE)) == 0) {
-			continue;
-		}
-
-		if (state->pollfd_idx[fde->fd] == -1) {
-			/*
-			 * We haven't seen this fd yet. Allocate a new pollfd.
-			 */
-			state->pollfd_idx[fde->fd] = num_pollfds;
-			pfd = &fds[num_pollfds];
-			num_pollfds += 1;
-		} else {
-			/*
-			 * We have already seen this fd. OR in the flags.
-			 */
-			pfd = &fds[state->pollfd_idx[fde->fd]];
-		}
-
-		pfd->fd = fde->fd;
-
-		if (fde->flags & TEVENT_FD_READ) {
-			pfd->events |= (POLLIN|POLLHUP);
-		}
-		if (fde->flags & TEVENT_FD_WRITE) {
-			pfd->events |= POLLOUT;
-		}
-	}
-	*pfds = fds;
-	*pnum_pfds = num_pollfds;
-
-	if (ev->immediate_events != NULL) {
-		*ptimeout = 0;
-		return true;
-	}
-	if (ev->timer_events == NULL) {
-		*ptimeout = MIN(*ptimeout, INT_MAX);
-		return true;
-	}
-
-	now = timeval_current();
-	diff = timeval_until(&now, &ev->timer_events->next_event);
-	timeout = timeval_to_msec(diff);
-
-	if (timeout < *ptimeout) {
-		*ptimeout = timeout;
-	}
-
-	return true;
-}
-
-bool run_events_poll(struct tevent_context *ev, int pollrtn,
-		     struct pollfd *pfds, int num_pfds)
-{
-	struct tevent_poll_private *state;
-	int *pollfd_idx;
-	struct tevent_fd *fde;
-
-	if (ev->signal_events &&
-	    tevent_common_check_signal(ev)) {
-		return true;
-	}
-
-	if (ev->threaded_contexts != NULL) {
-		tevent_common_threaded_activate_immediate(ev);
-	}
-
-	if (ev->immediate_events &&
-	    tevent_common_loop_immediate(ev)) {
-		return true;
-	}
-
-	if (pollrtn <= 0) {
-		struct timeval tval;
-
-		tval = tevent_common_loop_timer_delay(ev);
-		if (tevent_timeval_is_zero(&tval)) {
-			return true;
-		}
-
-		/*
-		 * No fd ready
-		 */
-		return false;
-	}
-
-	state = (struct tevent_poll_private *)ev->additional_data;
-	pollfd_idx = state->pollfd_idx;
-
-	for (fde = ev->fd_events; fde; fde = fde->next) {
-		struct pollfd *pfd;
-		uint16_t flags = 0;
-
-		if ((fde->flags & (TEVENT_FD_READ|TEVENT_FD_WRITE)) == 0) {
-			continue;
-		}
-
-		if (pollfd_idx[fde->fd] >= num_pfds) {
-			DEBUG(1, ("internal error: pollfd_idx[fde->fd] (%d) "
-				  ">= num_pfds (%d)\n", pollfd_idx[fde->fd],
-				  num_pfds));
-			return false;
-		}
-		pfd = &pfds[pollfd_idx[fde->fd]];
-
-		if (pfd->fd != fde->fd) {
-			DEBUG(1, ("internal error: pfd->fd (%d) "
-				  "!= fde->fd (%d)\n", pollfd_idx[fde->fd],
-                                  num_pfds));
-			return false;
-		}
-
-		if (pfd->revents & (POLLHUP|POLLERR)) {
-			/* If we only wait for TEVENT_FD_WRITE, we
-			   should not tell the event handler about it,
-			   and remove the writable flag, as we only
-			   report errors when waiting for read events
-			   to match the select behavior. */
-			if (!(fde->flags & TEVENT_FD_READ)) {
-				TEVENT_FD_NOT_WRITEABLE(fde);
-				continue;
-			}
-			flags |= TEVENT_FD_READ;
-		}
-
-		if (pfd->revents & POLLIN) {
-			flags |= TEVENT_FD_READ;
-		}
-		if (pfd->revents & POLLOUT) {
-			flags |= TEVENT_FD_WRITE;
-		}
-		if (flags & fde->flags) {
-			DLIST_DEMOTE(ev->fd_events, fde);
-			fde->handler(ev, fde, flags, fde->private_data);
-			return true;
-		}
-	}
-
-	return false;
-}
-
-struct timeval *get_timed_events_timeout(struct tevent_context *ev,
-					 struct timeval *to_ret)
-{
-	struct timeval now;
-
-	if ((ev->timer_events == NULL) && (ev->immediate_events == NULL)) {
-		return NULL;
-	}
-	if (ev->immediate_events != NULL) {
-		*to_ret = timeval_zero();
-		return to_ret;
-	}
-
-	now = timeval_current();
-	*to_ret = timeval_until(&now, &ev->timer_events->next_event);
-
-	DEBUG(10, ("timed_events_timeout: %d/%d\n", (int)to_ret->tv_sec,
-		(int)to_ret->tv_usec));
-
-	return to_ret;
-}
-
-static int s3_event_loop_once(struct tevent_context *ev, const char *location)
-{
-	struct tevent_poll_private *state;
-	int timeout;
-	int num_pfds;
-	int ret;
-	int poll_errno;
-
-	timeout = INT_MAX;
-
-	state = tevent_get_poll_private(ev);
-	if (state == NULL) {
-		errno = ENOMEM;
-		return -1;
-	}
-
-	if (run_events_poll(ev, 0, NULL, 0)) {
-		return 0;
-	}
-
-	num_pfds = 0;
-	if (!event_add_to_poll_args(ev, state,
-				    &state->pfds, &num_pfds, &timeout)) {
-		return -1;
-	}
-
-	tevent_trace_point_callback(ev, TEVENT_TRACE_BEFORE_WAIT);
-	ret = poll(state->pfds, num_pfds, timeout);
-	poll_errno = errno;
-	tevent_trace_point_callback(ev, TEVENT_TRACE_AFTER_WAIT);
-	errno = poll_errno;
-
-	if (ret == -1 && errno != EINTR) {
-		tevent_debug(ev, TEVENT_DEBUG_FATAL,
-			     "poll() failed: %d:%s\n",
-			     errno, strerror(errno));
-		return -1;
-	}
-
-	run_events_poll(ev, ret, state->pfds, num_pfds);
-	return 0;
-}
-
-static int s3_event_context_init(struct tevent_context *ev)
-{
-	return 0;
-}
-
-void dump_event_list(struct tevent_context *ev)
-{
-	struct tevent_timer *te;
-	struct tevent_fd *fe;
-	struct timeval evt, now;
-
-	if (!ev) {
-		return;
-	}
-
-	now = timeval_current();
-
-	DEBUG(10,("dump_event_list:\n"));
-
-	for (te = ev->timer_events; te; te = te->next) {
-
-		evt = timeval_until(&now, &te->next_event);
-
-		DEBUGADD(10,("Timed Event \"%s\" %p handled in %d seconds (at %s)\n",
-			   te->handler_name,
-			   te,
-			   (int)evt.tv_sec,
-			   http_timestring(talloc_tos(), te->next_event.tv_sec)));
-	}
-
-	for (fe = ev->fd_events; fe; fe = fe->next) {
-
-		DEBUGADD(10,("FD Event %d %p, flags: 0x%04x\n",
-			   fe->fd,
-			   fe,
-			   fe->flags));
-	}
-}
-
-static const struct tevent_ops s3_event_ops = {
-	.context_init		= s3_event_context_init,
-	.add_fd			= tevent_common_add_fd,
-	.set_fd_close_fn	= tevent_common_fd_set_close_fn,
-	.get_fd_flags		= tevent_common_fd_get_flags,
-	.set_fd_flags		= tevent_common_fd_set_flags,
-	.add_timer		= tevent_common_add_timer,
-	.schedule_immediate	= tevent_common_schedule_immediate,
-	.add_signal		= tevent_common_add_signal,
-	.loop_once		= s3_event_loop_once,
-	.loop_wait		= tevent_common_loop_wait,
-};
-
-static bool s3_tevent_init(void)
-{
-	static bool initialized;
-	if (initialized) {
-		return true;
-	}
-	initialized = tevent_register_backend("s3", &s3_event_ops);
-	tevent_set_default_backend("s3");
-	return initialized;
-}
-
-struct tevent_context *s3_tevent_context_init(TALLOC_CTX *mem_ctx)
-{
-	struct tevent_context *ev;
-
-	s3_tevent_init();
-
-	ev = tevent_context_init_byname(mem_ctx, "s3");
-	if (ev) {
-		samba_tevent_set_debug(ev, "s3_tevent");
-	}
-
-	return ev;
-}
-
-struct idle_event {
-	struct tevent_timer *te;
-	struct timeval interval;
-	char *name;
-	bool (*handler)(const struct timeval *now, void *private_data);
-	void *private_data;
-};
-
-static void smbd_idle_event_handler(struct tevent_context *ctx,
-				    struct tevent_timer *te,
-				    struct timeval now,
-				    void *private_data)
-{
-	struct idle_event *event =
-		talloc_get_type_abort(private_data, struct idle_event);
-
-	TALLOC_FREE(event->te);
-
-	DEBUG(10,("smbd_idle_event_handler: %s %p called\n",
-		  event->name, event->te));
-
-	if (!event->handler(&now, event->private_data)) {
-		DEBUG(10,("smbd_idle_event_handler: %s %p stopped\n",
-			  event->name, event->te));
-		/* Don't repeat, delete ourselves */
-		TALLOC_FREE(event);
-		return;
-	}
-
-	DEBUG(10,("smbd_idle_event_handler: %s %p rescheduled\n",
-		  event->name, event->te));
-
-	event->te = tevent_add_timer(ctx, event,
-				     timeval_sum(&now, &event->interval),
-				     smbd_idle_event_handler, event);
-
-	/* We can't do much but fail here. */
-	SMB_ASSERT(event->te != NULL);
-}
-
-struct idle_event *event_add_idle(struct tevent_context *event_ctx,
-				  TALLOC_CTX *mem_ctx,
-				  struct timeval interval,
-				  const char *name,
-				  bool (*handler)(const struct timeval *now,
-						  void *private_data),
-				  void *private_data)
-{
-	struct idle_event *result;
-	struct timeval now = timeval_current();
-
-	result = talloc(mem_ctx, struct idle_event);
-	if (result == NULL) {
-		DEBUG(0, ("talloc failed\n"));
-		return NULL;
-	}
-
-	result->interval = interval;
-	result->handler = handler;
-	result->private_data = private_data;
-
-	if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) {
-		DEBUG(0, ("talloc failed\n"));
-		TALLOC_FREE(result);
-		return NULL;
-	}
-
-	result->te = tevent_add_timer(event_ctx, result,
-				      timeval_sum(&now, &interval),
-				      smbd_idle_event_handler, result);
-	if (result->te == NULL) {
-		DEBUG(0, ("event_add_timed failed\n"));
-		TALLOC_FREE(result);
-		return NULL;
-	}
-
-	DEBUG(10,("event_add_idle: %s %p\n", result->name, result->te));
-	return result;
-}
-
diff --git a/source3/lib/util_event.c b/source3/lib/util_event.c
new file mode 100644
index 0000000..4ca2840
--- /dev/null
+++ b/source3/lib/util_event.c
@@ -0,0 +1,101 @@
+/*
+   Unix SMB/CIFS implementation.
+   Timed event library.
+   Copyright (C) Andrew Tridgell 1992-1998
+   Copyright (C) Volker Lendecke 2005-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 "includes.h"
+
+struct idle_event {
+	struct tevent_timer *te;
+	struct timeval interval;
+	char *name;
+	bool (*handler)(const struct timeval *now, void *private_data);
+	void *private_data;
+};
+
+static void smbd_idle_event_handler(struct tevent_context *ctx,
+				    struct tevent_timer *te,
+				    struct timeval now,
+				    void *private_data)
+{
+	struct idle_event *event =
+		talloc_get_type_abort(private_data, struct idle_event);
+
+	TALLOC_FREE(event->te);
+
+	DEBUG(10,("smbd_idle_event_handler: %s %p called\n",
+		  event->name, event->te));
+
+	if (!event->handler(&now, event->private_data)) {
+		DEBUG(10,("smbd_idle_event_handler: %s %p stopped\n",
+			  event->name, event->te));
+		/* Don't repeat, delete ourselves */
+		TALLOC_FREE(event);
+		return;
+	}
+
+	DEBUG(10,("smbd_idle_event_handler: %s %p rescheduled\n",
+		  event->name, event->te));
+
+	event->te = tevent_add_timer(ctx, event,
+				     timeval_sum(&now, &event->interval),
+				     smbd_idle_event_handler, event);
+
+	/* We can't do much but fail here. */
+	SMB_ASSERT(event->te != NULL);
+}
+
+struct idle_event *event_add_idle(struct tevent_context *event_ctx,
+				  TALLOC_CTX *mem_ctx,
+				  struct timeval interval,
+				  const char *name,
+				  bool (*handler)(const struct timeval *now,
+						  void *private_data),
+				  void *private_data)
+{
+	struct idle_event *result;
+	struct timeval now = timeval_current();
+
+	result = talloc(mem_ctx, struct idle_event);
+	if (result == NULL) {
+		DEBUG(0, ("talloc failed\n"));
+		return NULL;
+	}
+
+	result->interval = interval;
+	result->handler = handler;
+	result->private_data = private_data;
+
+	if (!(result->name = talloc_asprintf(result, "idle_evt(%s)", name))) {
+		DEBUG(0, ("talloc failed\n"));
+		TALLOC_FREE(result);
+		return NULL;
+	}
+
+	result->te = tevent_add_timer(event_ctx, result,
+				      timeval_sum(&now, &interval),
+				      smbd_idle_event_handler, result);
+	if (result->te == NULL) {
+		DEBUG(0, ("event_add_timed failed\n"));
+		TALLOC_FREE(result);
+		return NULL;
+	}
+
+	DEBUG(10,("event_add_idle: %s %p\n", result->name, result->te));
+	return result;
+}
diff --git a/source3/wscript_build b/source3/wscript_build
index a59927a..21a76d3 100755
--- a/source3/wscript_build
+++ b/source3/wscript_build
@@ -333,7 +333,7 @@ bld.SAMBA3_SUBSYSTEM('samba3core',
                    lib/dmallocmsg.c
                    intl/lang_tdb.c
                    lib/gencache.c
-                   lib/events.c
+                   lib/util_event.c
                    lib/server_contexts.c
                    lib/server_prefork.c
                    lib/server_prefork_util.c
-- 
2.7.4



More information about the samba-technical mailing list