The branch, master has been updated via 613acd3ddd7 s3-mdssvc: add a comment to mds_init() via 003b5d3ee4c s3-mdssvc: make mds_ctx_destructor_cb static via 91c9c03435e s3-mdssvc: add missing call to g_cancellable_new() via 984c890cd05 s3-mdssvc: use default g_main context via 55b2cca14a1 s3-mdssvc: use tevent_glib_glue in mdssvc RPC service via bc053abdd1d s3-mdssvc: call [un]become_authenticated_pipe_user() via 675902f8006 s3-mdssvc: add tevent context arg to mds_init_ctx via 6592daf56fa s3/lib: tevent-glib-glue test utiltity with Tracker via 1f836d4c7fa s3/lib: add a tevent_glib_glue subsystem test via fa39a7b2e6e s3/lib: new tevent_glib_glue subsystem via 2f87661c568 s3:wscript: fix flex and bison detection via f52e4020653 s3:wscript: fix flex and bison detection message when not installed via f79acc51a5f s3: build: seperate out check for Gnome Tracker from Spotlight via adbb6e91adf waf: fix array access out of bounds exception in the check for flex via d5166089d69 bootstrap: move flex to common packages from 92f30f91e44 waf: build: Respect --disable-python for third_party modules
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 613acd3ddd789290f4a018f6920fc51ed9bac6b2 Author: Ralph Boehme <s...@samba.org> Date: Tue Mar 12 15:43:57 2019 +0100 s3-mdssvc: add a comment to mds_init() Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> Autobuild-User(master): Ralph Böhme <s...@samba.org> Autobuild-Date(master): Wed Apr 24 19:32:12 UTC 2019 on sn-devel-184 commit 003b5d3ee4c8a44ad9062fbee4cec45738b5a9bd Author: Ralph Boehme <s...@samba.org> Date: Tue Mar 12 15:29:48 2019 +0100 s3-mdssvc: make mds_ctx_destructor_cb static This is only used in this compilation unit. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 91c9c03435e6d0d42d7be69c1effac2a36f296ec Author: Ralph Boehme <s...@samba.org> Date: Tue Mar 12 15:27:25 2019 +0100 s3-mdssvc: add missing call to g_cancellable_new() Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 984c890cd0561bc016fd327ba7030df4e6b20b45 Author: Ralph Boehme <s...@samba.org> Date: Mon Mar 25 16:11:30 2019 +0100 s3-mdssvc: use default g_main context Way back when the module was developed it seemed to be necessary the use a private context with push/pop as thread default. Maybe there was a bug in libtracker-sparql dispatching callback in the wrong (global) context. It's not necessary anymore with a recent libtracker-sparql version. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 55b2cca14a115a9c13004ec9f59b6b95a2776e78 Author: Ralph Boehme <s...@samba.org> Date: Wed Jan 27 13:23:51 2016 +0100 s3-mdssvc: use tevent_glib_glue in mdssvc RPC service Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit bc053abdd1df343eb4bf0eeff52bebc2dcbd7a30 Author: Ralph Boehme <s...@samba.org> Date: Mon Mar 11 18:11:04 2019 +0100 s3-mdssvc: call [un]become_authenticated_pipe_user() This ensures we're running as the authenticated user int the tevent callback which might be running in an arbitrary impersonation context. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 675902f80068c159af51b004ccded7fb777d1c40 Author: Ralph Boehme <s...@samba.org> Date: Wed Jan 27 13:17:04 2016 +0100 s3-mdssvc: add tevent context arg to mds_init_ctx This is needed later when adding tevent_glib_glue support, not used for now. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 6592daf56fa1dc6d7e489add54a07d407cbb00c6 Author: Ralph Boehme <s...@samba.org> Date: Fri Jan 22 15:38:39 2016 +0100 s3/lib: tevent-glib-glue test utiltity with Tracker A small utilitly useful for tesing the tevent_glib_glue code. It runs a tracker-sparql search query against your local tracker store that must be setup and running. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 1f836d4c7fa5376eb4b45116cb59755e1c363b7f Author: Ralph Boehme <s...@samba.org> Date: Thu Jan 28 08:29:28 2016 +0100 s3/lib: add a tevent_glib_glue subsystem test Tests adapted from glib2 glib/tests/mainloop.c. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit fa39a7b2e6e3fd22d234b2c6c53772b08243db9d Author: Ralph Boehme <s...@samba.org> Date: Wed Jan 20 15:08:31 2016 +0100 s3/lib: new tevent_glib_glue subsystem tevent_glib_glue_create() takes glib GMainContext and adds its event sources to a tevent context. tevent will poll the sources and run handlers for pending events as detailed in the glib documentation: https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit 2f87661c568e33ab4f74e3434ffbb7ec49f03203 Author: Ralph Boehme <s...@samba.org> Date: Fri Mar 29 18:40:51 2019 +0100 s3:wscript: fix flex and bison detection conf.env['BISON'] and conf.env['FLEX'] return lists. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit f52e4020653a3848efef47424e21481ed18d3935 Author: Ralph Boehme <s...@samba.org> Date: Fri Mar 29 18:20:52 2019 +0100 s3:wscript: fix flex and bison detection message when not installed If flex or bison are not installed, conf.env['BISON'] and conf.env['FLEX'] respectively return an empty string, so conf.CHECK_COMMAND() runs $ /bin/sh -c " --version | head -n1" and $ /bin/sh -c " --version" which results in the following message /bin/sh: []: command not found Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit f79acc51a5f45da3936886eaec7b635e70ad4540 Author: Ralph Boehme <s...@samba.org> Date: Mon Feb 15 10:42:52 2016 +0100 s3: build: seperate out check for Gnome Tracker from Spotlight Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit adbb6e91adfaa03c5519f3c7eeaa29fdde991efb Author: Ralph Boehme <s...@samba.org> Date: Fri Mar 29 18:18:27 2019 +0100 waf: fix array access out of bounds exception in the check for flex If flex is not installed the following expection is triggered: Checking for flex Checking for program 'flex' : not found Traceback (most recent call last): File "/home/slow/git/samba/scratch/third_party/waf/waflib/Scripting.py", line 158, in waf_entry_point run_commands() File "/home/slow/git/samba/scratch/third_party/waf/waflib/Scripting.py", line 251, in run_commands ctx = run_command(cmd_name) File "/home/slow/git/samba/scratch/third_party/waf/waflib/Scripting.py", line 235, in run_command ctx.execute() File "/home/slow/git/samba/scratch/third_party/waf/waflib/Configure.py", line 159, in execute super(ConfigurationContext, self).execute() File "/home/slow/git/samba/scratch/third_party/waf/waflib/Context.py", line 204, in execute self.recurse([os.path.dirname(g_module.root_path)]) File "/home/slow/git/samba/scratch/third_party/waf/waflib/Context.py", line 286, in recurse user_function(self) File "/home/slow/git/samba/scratch/wscript", line 307, in configure conf.RECURSE('source3') File "./buildtools/wafsamba/samba_utils.py", line 66, in fun return f(*k, **kw) File "./buildtools/wafsamba/samba_utils.py", line 481, in RECURSE return ctx.recurse(relpath) File "/home/slow/git/samba/scratch/third_party/waf/waflib/Context.py", line 286, in recurse user_function(self) File "/home/slow/git/samba/scratch/source3/wscript", line 1660, in configure flex.configure(conf) File "/home/slow/git/samba/scratch/third_party/waf/waflib/Tools/flex.py", line 59, in configure if re.search (r"\\msys\\[0-9.]+\\bin\\flex.exe$", conf.env.FLEX[0]): IndexError: list index out of range This happens because when the detection of flex fails, an excpetion is thrown in Configure.py:find_program by calling self.fatal(), but as Configure.py:find_program() is called from samba_waf18.py:find_program_samba() which sets the keyword argument mandatory=False, Configure.py:conf:fun() catches the expection. As a result in flex.py the call to conf.find_program('flex', var='FLEX') does not abort and if re.search (r"\\msys\\[0-9.]+\\bin\\flex.exe$", conf.env.FLEX[0]) is executed even though conf.env.FLEX is None. As this is a not a problem of upstream Samba, but triggered by our samba_waf18.py:find_program_samba(), I don't pursue an upstream fix. Instead, just use conf.find_program() directly instead of the wrapper in flex.py. Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Noel Power <npo...@samba.org> commit d5166089d6960379872d864e74eb4e1cf177cdd1 Author: Ralph Boehme <s...@samba.org> Date: Fri Apr 19 11:04:58 2019 +0200 bootstrap: move flex to common packages Signed-off-by: Ralph Boehme <s...@samba.org> Reviewed-by: Andrew Bartlett <abart...@samba.org> ----------------------------------------------------------------------- Summary of changes: .gitlab-ci.yml | 2 +- bootstrap/config.py | 2 +- bootstrap/generated-dists/centos6/bootstrap.sh | 1 + bootstrap/generated-dists/centos6/packages.yml | 1 + bootstrap/generated-dists/centos7/bootstrap.sh | 1 + bootstrap/generated-dists/centos7/packages.yml | 1 + bootstrap/generated-dists/fedora28/bootstrap.sh | 1 + bootstrap/generated-dists/fedora28/packages.yml | 1 + bootstrap/generated-dists/fedora29/bootstrap.sh | 1 + bootstrap/generated-dists/fedora29/packages.yml | 1 + bootstrap/generated-dists/opensuse150/bootstrap.sh | 1 + bootstrap/generated-dists/opensuse150/packages.yml | 1 + bootstrap/sha1sum.txt | 2 +- source3/lib/tevent_glib_glue.c | 883 +++++++++++++++++++++ source3/lib/tevent_glib_glue.h | 68 ++ source3/lib/tevent_glib_glue_tests.c | 397 +++++++++ source3/rpc_server/mdssvc/mdssvc.c | 279 +++---- source3/rpc_server/mdssvc/mdssvc.h | 16 +- source3/rpc_server/mdssvc/srv_mdssvc_nt.c | 6 +- source3/rpc_server/wscript_build | 4 +- source3/script/tests/test_tevent_glib_glue.sh | 21 + source3/selftest/tests.py | 3 + source3/utils/async-tracker.c | 288 +++++++ source3/wscript | 71 +- source3/wscript_build | 26 + 25 files changed, 1879 insertions(+), 199 deletions(-) create mode 100644 source3/lib/tevent_glib_glue.c create mode 100644 source3/lib/tevent_glib_glue.h create mode 100644 source3/lib/tevent_glib_glue_tests.c create mode 100755 source3/script/tests/test_tevent_glib_glue.sh create mode 100644 source3/utils/async-tracker.c Changeset truncated at 500 lines: diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9d596372df8..e43000548ca 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,7 +19,7 @@ variables: # Set this to the contents of bootstrap/sha1sum.txt # which is generated by bootstrap/template.py --render # - SAMBA_CI_CONTAINER_TAG: 8606e89b0ce6a916fa881549a6cebf6eed528157 + SAMBA_CI_CONTAINER_TAG: 5c2b831fb6aef8abd25dbdc6ade53ba2ebad1a1c # # The following images are available # Please see the samba-o3 sections at the end of this file! diff --git a/bootstrap/config.py b/bootstrap/config.py index 8d85dce1e83..d8bb7cf9654 100644 --- a/bootstrap/config.py +++ b/bootstrap/config.py @@ -37,6 +37,7 @@ COMMON = [ 'binutils', 'bison', 'curl', + 'flex', 'gcc', 'gdb', 'git', @@ -163,7 +164,6 @@ PKGS = [ # rpm has no pkg for docbook-xml ('docbook-xml', 'docbook-dtds'), ('docbook-xsl', 'docbook-style-xsl'), - ('flex', ''), ('', 'keyutils-libs-devel'), ('', 'which'), ] diff --git a/bootstrap/generated-dists/centos6/bootstrap.sh b/bootstrap/generated-dists/centos6/bootstrap.sh index 2ac905ddda7..be21d8bec69 100755 --- a/bootstrap/generated-dists/centos6/bootstrap.sh +++ b/bootstrap/generated-dists/centos6/bootstrap.sh @@ -25,6 +25,7 @@ yum -y -q --verbose install \ dbus-devel \ docbook-dtds \ docbook-style-xsl \ + flex \ gawk \ gcc \ gdb \ diff --git a/bootstrap/generated-dists/centos6/packages.yml b/bootstrap/generated-dists/centos6/packages.yml index 344d88a5d2a..c7953bd60f9 100644 --- a/bootstrap/generated-dists/centos6/packages.yml +++ b/bootstrap/generated-dists/centos6/packages.yml @@ -13,6 +13,7 @@ packages: - dbus-devel - docbook-dtds - docbook-style-xsl + - flex - gawk - gcc - gdb diff --git a/bootstrap/generated-dists/centos7/bootstrap.sh b/bootstrap/generated-dists/centos7/bootstrap.sh index 90dcbd19566..08a11b7ee93 100755 --- a/bootstrap/generated-dists/centos7/bootstrap.sh +++ b/bootstrap/generated-dists/centos7/bootstrap.sh @@ -25,6 +25,7 @@ yum -y -q --verbose install \ dbus-devel \ docbook-dtds \ docbook-style-xsl \ + flex \ gawk \ gcc \ gdb \ diff --git a/bootstrap/generated-dists/centos7/packages.yml b/bootstrap/generated-dists/centos7/packages.yml index d5048a71d77..c3bbe7ba4a6 100644 --- a/bootstrap/generated-dists/centos7/packages.yml +++ b/bootstrap/generated-dists/centos7/packages.yml @@ -13,6 +13,7 @@ packages: - dbus-devel - docbook-dtds - docbook-style-xsl + - flex - gawk - gcc - gdb diff --git a/bootstrap/generated-dists/fedora28/bootstrap.sh b/bootstrap/generated-dists/fedora28/bootstrap.sh index ec1fdff902a..6793a37b8c9 100755 --- a/bootstrap/generated-dists/fedora28/bootstrap.sh +++ b/bootstrap/generated-dists/fedora28/bootstrap.sh @@ -23,6 +23,7 @@ dnf -y -q --verbose install \ dbus-devel \ docbook-dtds \ docbook-style-xsl \ + flex \ gawk \ gcc \ gdb \ diff --git a/bootstrap/generated-dists/fedora28/packages.yml b/bootstrap/generated-dists/fedora28/packages.yml index 40cc9e74abb..a37f78b33d2 100644 --- a/bootstrap/generated-dists/fedora28/packages.yml +++ b/bootstrap/generated-dists/fedora28/packages.yml @@ -13,6 +13,7 @@ packages: - dbus-devel - docbook-dtds - docbook-style-xsl + - flex - gawk - gcc - gdb diff --git a/bootstrap/generated-dists/fedora29/bootstrap.sh b/bootstrap/generated-dists/fedora29/bootstrap.sh index ec1fdff902a..6793a37b8c9 100755 --- a/bootstrap/generated-dists/fedora29/bootstrap.sh +++ b/bootstrap/generated-dists/fedora29/bootstrap.sh @@ -23,6 +23,7 @@ dnf -y -q --verbose install \ dbus-devel \ docbook-dtds \ docbook-style-xsl \ + flex \ gawk \ gcc \ gdb \ diff --git a/bootstrap/generated-dists/fedora29/packages.yml b/bootstrap/generated-dists/fedora29/packages.yml index 40cc9e74abb..a37f78b33d2 100644 --- a/bootstrap/generated-dists/fedora29/packages.yml +++ b/bootstrap/generated-dists/fedora29/packages.yml @@ -13,6 +13,7 @@ packages: - dbus-devel - docbook-dtds - docbook-style-xsl + - flex - gawk - gcc - gdb diff --git a/bootstrap/generated-dists/opensuse150/bootstrap.sh b/bootstrap/generated-dists/opensuse150/bootstrap.sh index 06f3ca67fed..dbf7dabf55a 100755 --- a/bootstrap/generated-dists/opensuse150/bootstrap.sh +++ b/bootstrap/generated-dists/opensuse150/bootstrap.sh @@ -22,6 +22,7 @@ zypper --non-interactive install \ dbus-1-devel \ docbook-dtds \ docbook-xsl-stylesheets \ + flex \ gawk \ gcc \ gdb \ diff --git a/bootstrap/generated-dists/opensuse150/packages.yml b/bootstrap/generated-dists/opensuse150/packages.yml index 415384721c3..a6c989ffebd 100644 --- a/bootstrap/generated-dists/opensuse150/packages.yml +++ b/bootstrap/generated-dists/opensuse150/packages.yml @@ -12,6 +12,7 @@ packages: - dbus-1-devel - docbook-dtds - docbook-xsl-stylesheets + - flex - gawk - gcc - gdb diff --git a/bootstrap/sha1sum.txt b/bootstrap/sha1sum.txt index dad5a55516e..d7dbdaee084 100644 --- a/bootstrap/sha1sum.txt +++ b/bootstrap/sha1sum.txt @@ -1 +1 @@ -8606e89b0ce6a916fa881549a6cebf6eed528157 +5c2b831fb6aef8abd25dbdc6ade53ba2ebad1a1c diff --git a/source3/lib/tevent_glib_glue.c b/source3/lib/tevent_glib_glue.c new file mode 100644 index 00000000000..b83f2036d9a --- /dev/null +++ b/source3/lib/tevent_glib_glue.c @@ -0,0 +1,883 @@ +/* + Unix SMB/CIFS implementation. + Integration of a glib g_main_context into a tevent_context + Copyright (C) Stefan Metzmacher 2016 + Copyright (C) Ralph Boehme 2016 + + ** NOTE! The following LGPL license applies to the tevent + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 3 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, see <http://www.gnu.org/licenses/>. +*/ + +#include "replace.h" +#include "system/filesys.h" +#include "lib/util/debug.h" +#include "lib/util/select.h" +#include <tevent.h> + +#undef DBGC_CLASS +#define DBGC_CLASS DBGC_TEVENT + +#ifdef HAVE_GLIB +#include <glib.h> +#include "tevent_glib_glue.h" + +struct fd_map { + struct tevent_glib_glue *glue; + int fd; + struct tevent_fd *fd_event; +}; + +struct tevent_glib_glue { + /* + * The tevent context we're feeding. + */ + struct tevent_context *ev; + + /* + * The glib gmain context we're polling and whether we're currently + * owning it by virtue of g_main_context_acquire(). + */ + GMainContext *gmain_ctx; + bool gmain_owner; + + /* + * Set by samba_tevent_glib_glue_quit(). + */ + bool quit; + + /* + * tevent trace callback and data we got from tevent_get_trace_callback() + * before installing our own trace callback. + */ + tevent_trace_callback_t prev_tevent_trace_cb; + void *prev_tevent_trace_data; + + /* + * Don't call tevent_glib_prepare() in the tevent tracepoint handler if + * explicity told so. This is an optimisation for the case that glib + * event sources are created from glib event callbacks. + */ + bool skip_glib_refresh; + + /* + * Used when acquiring the glib gmain context failed. + */ + struct tevent_timer *acquire_retry_timer; + + /* + * glib gmain context timeout and priority for the current event look + * iteration. gtimeout is translated to a tevent timer event, unless it + * is 0 which signals some event source is pending. In that case we + * dispatch an immediate event. gpriority is ignored by us, just passed + * to the glib relevant functions. + */ + gint gtimeout; + gint gpriority; + struct tevent_timer *timer; + struct tevent_immediate *im; + bool scheduled_im; + + /* + * glib gmain context fds returned from g_main_context_query(). These + * get translated to tevent fd events. + */ + GPollFD *gpollfds; + gint num_gpollfds; + + /* + * A copy of gpollfds and num_gpollfds from the previous event loop + * iteration, used to detect changes in the set of fds. + */ + GPollFD *prev_gpollfds; + gint num_prev_gpollfds; + + /* + * An array of pointers to fd_map's. The fd_map'd contain the tevent + * event fd as well as a pointer to the corresponding glib GPollFD. + */ + struct fd_map **fd_map; + size_t num_maps; +}; + +static bool tevent_glib_prepare(struct tevent_glib_glue *glue); +static bool tevent_glib_process(struct tevent_glib_glue *glue); +static bool tevent_glib_glue_reinit(struct tevent_glib_glue *glue); +static void tevent_glib_fd_handler(struct tevent_context *ev, + struct tevent_fd *fde, + uint16_t flags, + void *private_data); + +typedef int (*gfds_cmp_cb)(const void *fd1, const void *fd2); +typedef bool (*gfds_found_cb)(struct tevent_glib_glue *glue, + const GPollFD *new, + const GPollFD *old); +typedef bool (*gfds_new_cb)(struct tevent_glib_glue *glue, + const GPollFD *fd); +typedef bool (*gfds_removed_cb)(struct tevent_glib_glue *glue, + const GPollFD *fd); + +/** + * Compare two sorted GPollFD arrays + * + * For every element that exists in gfds and prev_gfds found_fn() is called. + * For every element in gfds but not in prev_gfds, new_fn() is called. + * For every element in prev_gfds but not in gfds removed_fn() is called. + **/ +static bool cmp_gfds(struct tevent_glib_glue *glue, + GPollFD *gfds, + GPollFD *prev_gfds, + size_t num_gfds, + size_t num_prev_gfds, + gfds_cmp_cb cmp_cb, + gfds_found_cb found_cb, + gfds_new_cb new_cb, + gfds_removed_cb removed_cb) +{ + bool ok; + size_t i = 0, j = 0; + int cmp; + + while (i < num_gfds && j < num_prev_gfds) { + cmp = cmp_cb(&gfds[i], &prev_gfds[j]); + if (cmp == 0) { + ok = found_cb(glue, &gfds[i], &prev_gfds[j]); + if (!ok) { + return false; + } + i++; + j++; + } else if (cmp < 0) { + ok = new_cb(glue, &gfds[i]); + if (!ok) { + return false; + } + i++; + } else { + ok = removed_cb(glue, &prev_gfds[j]); + if (!ok) { + return false; + } + j++; + } + } + + while (i < num_gfds) { + ok = new_cb(glue, &gfds[i++]); + if (!ok) { + return false; + } + } + + while (j < num_prev_gfds) { + ok = removed_cb(glue, &prev_gfds[j++]); + if (!ok) { + return false; + } + } + + return true; +} + +static int glib_fd_cmp_func(const void *p1, const void *p2) +{ + const GPollFD *lhs = p1; + const GPollFD *rhs = p2; + + if (lhs->fd < rhs->fd) { + return -1; + } else if (lhs->fd > rhs->fd) { + return 1; + } + + return 0; +} + +/* + * We already have a tevent fd event for the glib GPollFD, but we may have to + * update flags. + */ +static bool match_gfd_cb(struct tevent_glib_glue *glue, + const GPollFD *new_gfd, + const GPollFD *old_gfd) +{ + size_t i; + struct fd_map *fd_map = NULL; + struct tevent_fd *fd_event = NULL; + + if (new_gfd->events == old_gfd->events) { + return true; + } + + for (i = 0; i < glue->num_maps; i++) { + if (glue->fd_map[i]->fd == new_gfd->fd) { + break; + } + } + + if (i == glue->num_maps) { + DBG_ERR("match_gfd_cb: glib fd %d not in map\n", new_gfd->fd); + return false; + } + + fd_map = glue->fd_map[i]; + if (fd_map == NULL) { + DBG_ERR("fd_map for fd %d is NULL\n", new_gfd->fd); + return false; + } + + fd_event = fd_map->fd_event; + if (fd_event == NULL) { + DBG_ERR("fd_event for fd %d is NULL\n", new_gfd->fd); + return false; + } + + tevent_fd_set_flags(fd_event, 0); + + if (new_gfd->events & (G_IO_IN | G_IO_HUP | G_IO_ERR)) { + TEVENT_FD_READABLE(fd_event); + } + if (new_gfd->events & G_IO_OUT) { + TEVENT_FD_WRITEABLE(fd_event); + } + + return true; +} + +static bool new_gfd_cb(struct tevent_glib_glue *glue, const GPollFD *gfd) +{ + struct tevent_fd *fd_event = NULL; + struct fd_map *fd_map = NULL; + uint16_t events = 0; + bool revent; + bool wevent; + + revent = (gfd->events & (G_IO_IN | G_IO_HUP | G_IO_ERR)); + wevent = (gfd->events & G_IO_OUT); + if (revent) { + events |= TEVENT_FD_READ; + } + if (wevent) { + events |= TEVENT_FD_WRITE; + } + + glue->fd_map = talloc_realloc(glue, + glue->fd_map, + struct fd_map *, + glue->num_maps + 1); + if (glue->fd_map == NULL) { + DBG_ERR("talloc_realloc failed\n"); + return false; + } + fd_map = talloc_zero(glue->fd_map, struct fd_map); + if (fd_map == NULL) { + DBG_ERR("talloc_realloc failed\n"); + return false; + } + glue->fd_map[glue->num_maps] = fd_map; + glue->num_maps++; + + fd_event = tevent_add_fd(glue->ev, + glue->fd_map, + gfd->fd, + events, + tevent_glib_fd_handler, + fd_map); + if (fd_event == NULL) { + DBG_ERR("tevent_add_fd failed\n"); + return false; + } + + *fd_map = (struct fd_map) { + .glue = glue, + .fd = gfd->fd, + .fd_event = fd_event, + }; + + DBG_DEBUG("added tevent_fd for glib fd %d\n", gfd->fd); + + return true; +} + +static bool remove_gfd_cb(struct tevent_glib_glue *glue, const GPollFD *gfd) +{ + size_t i; + + for (i = 0; i < glue->num_maps; i++) { + if (glue->fd_map[i]->fd == gfd->fd) { + break; + } + } + + if (i == glue->num_maps) { + DBG_ERR("remove_gfd_cb: glib fd %d not in map\n", gfd->fd); + return false; + } + + TALLOC_FREE(glue->fd_map[i]->fd_event); + TALLOC_FREE(glue->fd_map[i]); + + if (i + 1 < glue->num_maps) { + memmove(&glue->fd_map[i], -- Samba Shared Repository