From 367c567c5f35db202474c8d3f730484538e1fb97 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 9 Feb 2012 13:16:55 +1100 Subject: [PATCH] lib/util: Remove sys_poll as it is no longer needed sys_poll() is only needed if the signal pipe is set up and used, but as no signal handler ever writes to the pipe, this can all be removed. signal based events are now handled via tevent. Andrew Bartlett Signed-off-by: Jeremy Allison --- lib/util/{select.h => select.c} | 40 ++++++++++++++++++++++++++++++---------- lib/util/select.h | 1 - source3/lib/events.c | 11 +++-------- source3/lib/g_lock.c | 12 ++++++------ source3/lib/util_sock.c | 4 ++-- source3/nmbd/nmbd_packets.c | 2 +- source3/smbd/process.c | 2 +- source3/winbindd/winbindd_dual.c | 2 +- 8 files changed, 44 insertions(+), 30 deletions(-) copy lib/util/{select.h => select.c} (58%) diff --git a/lib/util/select.h b/lib/util/select.c similarity index 58% copy from lib/util/select.h copy to lib/util/select.c index bfc78a99d2f..5e66344c9da 100644 --- a/lib/util/select.h +++ b/lib/util/select.c @@ -1,5 +1,6 @@ /* Unix SMB/Netbios implementation. + Version 3.0 Samba select/poll implementation Copyright (C) Andrew Tridgell 1992-1998 @@ -17,14 +18,33 @@ along with this program. If not, see . */ -#ifndef _select_h_ -#define _select_h_ - +#include "includes.h" +#include "system/filesys.h" #include "system/select.h" - -/* The following definitions come from lib/util/select.c */ - -int sys_poll(struct pollfd *fds, int num_fds, int timeout); -int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout); - -#endif +#include "lib/util/select.h" + +int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout) +{ + int orig_timeout = timeout; + struct timespec start; + int ret; + + clock_gettime_mono(&start); + + while (true) { + struct timespec now; + int64_t elapsed; + + ret = poll(fds, num_fds, timeout); + if (ret != -1) { + break; + } + if (errno != EINTR) { + break; + } + clock_gettime_mono(&now); + elapsed = nsec_time_diff(&now, &start); + timeout = (orig_timeout - elapsed) / 1000000; + }; + return ret; +} diff --git a/lib/util/select.h b/lib/util/select.h index bfc78a99d2f..fa1970ec016 100644 --- a/lib/util/select.h +++ b/lib/util/select.h @@ -24,7 +24,6 @@ /* The following definitions come from lib/util/select.c */ -int sys_poll(struct pollfd *fds, int num_fds, int timeout); int sys_poll_intr(struct pollfd *fds, int num_fds, int timeout); #endif diff --git a/source3/lib/events.c b/source3/lib/events.c index 77589f8e7e2..c71876ce39d 100644 --- a/source3/lib/events.c +++ b/source3/lib/events.c @@ -101,14 +101,9 @@ bool event_add_to_poll_args(struct tevent_context *ev, TALLOC_CTX *mem_ctx, fds = *pfds; num_pollfds = *pnum_pfds; - /* - * The +1 is for the sys_poll calling convention. It expects - * an array 1 longer for the signal pipe - */ - - if (talloc_array_length(fds) < num_pollfds + num_fds + 1) { + if (talloc_array_length(fds) < num_pollfds + num_fds) { fds = talloc_realloc(mem_ctx, fds, struct pollfd, - num_pollfds + num_fds + 1); + num_pollfds + num_fds); if (fds == NULL) { DEBUG(10, ("talloc_realloc failed\n")); return false; @@ -338,7 +333,7 @@ static int s3_event_loop_once(struct tevent_context *ev, const char *location) return -1; } - ret = sys_poll(state->pfds, num_pfds, timeout); + ret = poll(state->pfds, num_pfds, timeout); if (ret == -1 && errno != EINTR) { tevent_debug(ev, TEVENT_DEBUG_FATAL, "poll() failed: %d:%s\n", diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 1fd8ae9f387..1011584a254 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -395,11 +395,11 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name, */ /* - * We allocate 2 entries here. One is needed anyway for - * sys_poll and in the clustering case we might have to add - * the ctdb fd. This avoids the realloc then. + * We allocate 1 entries here. In the clustering case + * we might have to add the ctdb fd. This avoids the + * realloc then. */ - pollfds = talloc_array(talloc_tos(), struct pollfd, 2); + pollfds = talloc_array(talloc_tos(), struct pollfd, 1); if (pollfds == NULL) { status = NT_STATUS_NO_MEMORY; break; @@ -425,8 +425,8 @@ NTSTATUS g_lock_lock(struct g_lock_ctx *ctx, const char *name, select_timeout = timeval_min(&select_timeout, &timeout_remaining); - ret = sys_poll(pollfds, num_pollfds, - timeval_to_msec(select_timeout)); + ret = poll(pollfds, num_pollfds, + timeval_to_msec(select_timeout)); /* * We're not *really interested in the actual flags. We just diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c index dcc41bb699e..69e33f77250 100644 --- a/source3/lib/util_sock.c +++ b/source3/lib/util_sock.c @@ -1604,7 +1604,7 @@ int poll_one_fd(int fd, int events, int timeout, int *revents) int ret; int saved_errno; - fds = talloc_zero_array(talloc_tos(), struct pollfd, 2); + fds = talloc_zero_array(talloc_tos(), struct pollfd, 1); if (fds == NULL) { errno = ENOMEM; return -1; @@ -1612,7 +1612,7 @@ int poll_one_fd(int fd, int events, int timeout, int *revents) fds[0].fd = fd; fds[0].events = events; - ret = sys_poll(fds, 1, timeout); + ret = poll(fds, 1, timeout); /* * Assign whatever poll did, even in the ret<=0 case. diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index edac6f6b9ff..81e2f7f6732 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1935,7 +1935,7 @@ bool listen_for_packets(struct messaging_context *msg, bool run_election) event_add_to_poll_args(nmbd_event_context(), NULL, &fds, &num_sockets, &timeout); - pollrtn = sys_poll(fds, num_sockets, timeout); + pollrtn = poll(fds, num_sockets, timeout); if (run_events_poll(nmbd_event_context(), pollrtn, fds, num_sockets)) { return False; diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 2f8f88fa2ac..f295a59f86f 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -967,7 +967,7 @@ static NTSTATUS smbd_server_connection_loop_once(struct tevent_context *ev_ctx, int sav; START_PROFILE(smbd_idle); - ret = sys_poll(conn->pfds, num_pfds, timeout); + ret = poll(conn->pfds, num_pfds, timeout); sav = errno; END_PROFILE(smbd_idle); diff --git a/source3/winbindd/winbindd_dual.c b/source3/winbindd/winbindd_dual.c index d0bcd3bd402..f11dae7e082 100644 --- a/source3/winbindd/winbindd_dual.c +++ b/source3/winbindd/winbindd_dual.c @@ -1507,7 +1507,7 @@ static bool fork_domain_child(struct winbindd_child *child) (unsigned int)tp->tv_sec, (unsigned int)tp->tv_usec )); } - ret = sys_poll(pfds, num_pfds, timeout); + ret = poll(pfds, num_pfds, timeout); if (run_events_poll(winbind_event_context(), ret, pfds, num_pfds)) { -- 2.11.4.GIT