[SCM] Samba Shared Repository - branch master updated

Jeremy Allison jra at samba.org
Fri Mar 1 18:16:02 MST 2013


The branch, master has been updated
       via  f9eb055 tevent: change version to 0.9.18
       via  35385a3 tevent: optimize adding new zero timer events
       via  afd4198 tevent: optimize adding new timer events
       via  e5ae803 tevent: add a debug message in tevent_common_loop_timer_delay()
       via  3ed0f7d tevent: add test_event_fd2()
       via  cf3ee4e tevent: add test_event_fd1()
       via  2c9d84b tevent: use better names for the subtests
       via  04b1fa4 tevent: Regression test to ensure that a tevent backend can cope with separate read/write events on a single fd.
       via  2364047 tevent: use DEBUG_ERROR for the fallback message in epoll_panic()
       via  4fcc94d tevent: If epoll_ctl(..EPOLL_CTL_ADD,..) failes with EEXIST, merge the two fde's into one epoll event.
       via  16a072e tevent: preferr the write handler if there're two possible handlers registered with epoll
       via  fa4f171 tevent: In epoll_event_loop() ensure we trigger the right handler for a multiplexed fde event.
       via  4057ef2 tevent: Add utility function epoll_handle_hup_or_err()
       via  8b1a43e tevent: handle EPOLL_ADDITIONAL_FD_FLAG_HAS_MPX in epoll_update_event()
       via  a347d55 tevent: handle multiplexed fde's in epoll_event_fd_destructor()
       via  6703c5b tevent: Fix epoll_mod_event() to cope with modifying a multiplexed fde event.
       via  15ca40f tevent: Fix up epoll_del_event to cope with deleting a multiplexed fde event.
       via  809593e tevent: handle multiplexed fde's in epoll_add_event()
       via  e4b496c tevent: Start to fix the epoll backend to support 2 fd events on the same fd correctly.
       via  7ef688c tevent: ignore EBADF from epoll_ctl() and disable the event
       via  2721f0d tevent: unify handling of HAS_EVENT and REPORT_ERROR in epoll_{add,mod,del}_event()
       via  ec9615c tevent: always go through epoll_update_event()
       via  07e0427 tevent: s/epoll_change_event/epoll_update_event
       via  056dcc7 tevent: the content of event is ignored by EPOLL_CTL_DEL
       via  2b3b06b tevent: call epoll_panic() if EPOLL_CTL_DEL failed
       via  31db8a0 tevent: use helper variables to hold the epoll_ctl() result
       via  b2114eb tevent: remove unused if (epoll_ev->epoll_fd == -1) return; checks
       via  5b9218a tevent: add std_event_loop_wait()
       via  3fc9316 tevent: don't call TALLOC_FREE(ev->additional_data) in std_fallback_to_poll()
       via  73dabdd tevent: avoid any operation on epoll_ev after a epoll_panic()
       via  2b05c96 tevent: add epoll_{create,ctl}_panic_fallback() for testing
       via  8764ec8 tevent: use DLIST_DEMOTE() before calling on fde handler after select() and poll()
       via  b31767b tevent: debug a FATAL message on EBADF from the select backend
       via  5ca6914 tevent: Fix multiple handler on the same fd bug in the tevent select backend.
       via  b53c704 tevent: revalidate fde->flags after poll()
       via  6952d76 tevent: ignore POLLNVAL from poll() and disable the event
       via  de0204c tevent: traverse the ev->fd_event list instead of the poll_ev->fds array
       via  f45abea tevent: maintain a list of disabled events in the poll backend
       via  ef8130f tevent: merge poll_fresh_fde_destructor() into poll_event_fd_destructor()
       via  f75fd90 tevent: use tevent_poll_event_add_fd_internal() in poll_event_add_fd()
       via  8e3ef65 tevent: make sure we cleanup the array passed to poll() after deleting an event
       via  d5b341d tevent: don't skip a fd event if the previous one was deleted during poll()
       via  f86df3e tevent: remember the errno from select(), poll() and epoll_wait()
       via  883d20a tevent: add trace points BEFORE_LOOP_ONCE and AFTER_LOOP_ONCE
       via  5f284be tevent: fix compiler warning in tevent_context_init_byname()
       via  dea5115 tevent: fix some compiler warnings in testsuite.c
       via  5c31b15 tevent: fix a comment typo in tevent_epoll.c
       via  4a7142e tevent: fix --disable-python cause configure fails (bug #8718)
       via  d5f9257 tevent: define TEVENT_NUM_SIGNALS based on configure checks
       via  602cd7f lib/replace: add AC_CHECK_VALUEOF() macro
       via  87f2558 wafsamba: add CHECK_VALUEOF() helper
       via  d9a69e6 s3:lib/events: make use of tevent_common_loop_timer_delay()
      from  8ac431a Fix bug # 9666 - Broken filtering of link-local addresses.

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit f9eb05509bdab08a350440eba47de38522f17036
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Nov 30 09:43:23 2012 +0100

    tevent: change version to 0.9.18
    
    This release contains a lot of fixes:
    
    - Adding new timer events is now faster, if there's
      a large number of timer events.
    
    - sigprocmask does not work on FreeBSD to stop further signals in a signal
      handler.
    
    - TEVENT_NUM_SIGNALS is calculated by configure in order
      to support realtime signals on freebsd.
    
    - ./configure --disable-python was fixed for the standalone build.
    
    - Several crash bugs in the poll backend are fixed.
    
    - The poll backend removes deleted events from the
      cached pollfd array now.
    
    - The poll doesn't pass pollfd.events == 0 to poll()
      and maintains a list of disabled events,
      instead of consuming 100% cpu and/or triggering
      the callers handler.
    
    - The poll backend detects POLLNVAL and reports EBADF
      instead of consuming 100% cpu.
    
    - The select backend supports separate handlers
      for TEVENT_FD_READ and TEVENT_FD_WRITE.
    
    - The poll and select backends are now doing fair
      queuing of fd events.
    
    - The epoll has better error checking
      and supports separate handlers
      for TEVENT_FD_READ and TEVENT_FD_WRITE.
    
    - The standard backend was rewritten to be a tiny
      wrapper on top of epoll with a fallback to poll,
      which means that it doesn't use select directly anymore.
    
    - TEVENT_TRACE_BEFORE_LOOP_ONCE and TEVENT_TRACE_AFTER_LOOP_ONCE
      are added in order to allow the application to hook in
      before and after the loop_once() backend function is called.
      The TEVENT_HAS_LOOP_ONCE_TRACE_POINTS define can be used to
      detect the new feature.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>
    
    Autobuild-User(master): Jeremy Allison <jra at samba.org>
    Autobuild-Date(master): Sat Mar  2 02:15:44 CET 2013 on sn-devel-104

commit 35385a3e28850d0915e8cf2883871ae2101526f1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 12:45:39 2013 +0100

    tevent: optimize adding new zero timer events
    
    Such events were used before we had immediate events.
    It's likely that there're a lot of this events
    and we need to add new ones in fifo order.
    
    The tricky part is that tevent_common_add_timer()
    should not use the optimization as it's used
    by broken Samba versions, which don't use
    tevent_common_loop_timer_delay() in source3/lib/events.c.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit afd4198bf1ee5877a660d42e615e06d895690161
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 12:45:39 2013 +0100

    tevent: optimize adding new timer events
    
    As new timestamps typically get higher:-)
    it's better to traverse the existing list from
    the tail.
    
    This is not completely optimal, but it should be better
    than before.
    
    A second optimization could be done for zero timestamps,
    we would just remember the last_zero_timer,
    but that would change the internal ABI.
    Normally thatshould not be a poblem, but the Samba's
    source3/lib/events.c abuses tevent_internal.h
    from the current source tree, even if an external tevent.h
    is used. The other problem is that it makes use of
    tevent_common_add_timer() without using
    tevent_common_loop_timer_delay().
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e5ae80378af00c5c0158413bd1f1a8aca27fab04
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 1 09:25:32 2013 +0100

    tevent: add a debug message in tevent_common_loop_timer_delay()
    
    We should debug a message before and after running the handler.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3ed0f7d9924b6f70c56b98adb7c98032a255fc55
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 27 16:43:44 2013 +0100

    tevent: add test_event_fd2()
    
    This test fills the socket kernel buffers
    and verifies that we don't report TEVENT_FD_WRITE
    if the buffer is full.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit cf3ee4eb53829b7825c56d1d6581b46158d258d1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 21:48:44 2013 +0100

    tevent: add test_event_fd1()
    
    This test verifies that TEVENT_FD_* flags are handled correctly.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2c9d84b226e1a2f04bb03f5b00bceb77099bdeab
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 28 10:12:42 2013 +0100

    tevent: use better names for the subtests
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 04b1fa4112a3c76e84d640ab6c4808c7e971eec9
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 14 14:16:31 2013 -0800

    tevent: Regression test to ensure that a tevent backend can cope with separate read/write events on a single fd.
    
    This tests the multiplex fd changes to the epoll backend to
    ensure they work correctly.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 23640472bc6592a8bf03cccc7134b1c71b64a55a
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 1 14:30:54 2013 +0100

    tevent: use DEBUG_ERROR for the fallback message in epoll_panic()
    
    A Samba autobuild passed without a fallback, so this is
    really an error.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 4fcc94d852fcc19c304be50edc07914ea2f8d0c8
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 14 13:52:41 2013 -0800

    tevent: If epoll_ctl(..EPOLL_CTL_ADD,..) failes with EEXIST, merge the two fde's into one epoll event.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 16a072ec1cddd75f6df656f69935ad55f71f4a28
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 11:50:56 2013 +0100

    tevent: preferr the write handler if there're two possible handlers registered with epoll
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit fa4f1713f9802ff06007b43afd90357da0f98f73
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 14:49:17 2013 +0100

    tevent: In epoll_event_loop() ensure we trigger the right handler for a multiplexed fde event.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 4057ef2e11df6f7065f9691d0f388aea56faae45
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 14 15:53:38 2013 -0800

    tevent: Add utility function epoll_handle_hup_or_err()
    
    We'll use this to handle the EPOLL_ADDITIONAL_FD_FLAG_GOT_ERROR
    and EPOLL_ADDITIONAL_FD_FLAG_REPORT_ERROR flags with multiplexed
    events in the event loop.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 8b1a43ece8f056d7063a3d7accc5894f380bd018
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 17:17:31 2013 +0100

    tevent: handle EPOLL_ADDITIONAL_FD_FLAG_HAS_MPX in epoll_update_event()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit a347d55f506541e18b95cf3e7c1e83f2c665ee91
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 18:01:57 2013 +0100

    tevent: handle multiplexed fde's in epoll_event_fd_destructor()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6703c5b49ff8f1957a16b1bab5a0e0d18bf1af75
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 1 13:57:05 2013 +0100

    tevent: Fix epoll_mod_event() to cope with modifying a multiplexed fde event.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 15ca40fb7ad1668013eb5ebef4479058d33df992
Author: Jeremy Allison <jra at samba.org>
Date:   Fri Feb 15 10:16:44 2013 -0800

    tevent: Fix up epoll_del_event to cope with deleting a multiplexed fde event.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 809593e7f55c1d17c616f60d69ec5904e531ea2f
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 17:14:52 2013 +0100

    tevent: handle multiplexed fde's in epoll_add_event()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit e4b496cc096e1caabdaee646c162f0ba8cfac39c
Author: Jeremy Allison <jra at samba.org>
Date:   Thu Feb 14 13:50:56 2013 -0800

    tevent: Start to fix the epoll backend to support 2 fd events on the same fd correctly.
    
    Add a utility function epoll_add_multiplex_fd() and
    a new flag EPOLL_ADDITIONAL_FD_FLAG_HAS_MPX.
    
    This will be called by epoll_add_event() to merge two
    fde events with the same file descriptor.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 7ef688c1dd797b1d108afe02c4b803bab01988ab
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 13:33:19 2013 +0100

    tevent: ignore EBADF from epoll_ctl() and disable the event
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2721f0dc5b35aa4961d801c2377a951cd63ecee1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 17:38:10 2013 +0100

    tevent: unify handling of HAS_EVENT and REPORT_ERROR in epoll_{add,mod,del}_event()
    
    epoll_{add,mod,del}_event() are only called via epoll_update_event()
    and epoll_update_event() should not remove REPORT_ERROR itself.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ec9615c4fcbe15de1b0c16ccc6a52fa3ffb65b48
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 11:26:00 2013 +0100

    tevent: always go through epoll_update_event()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 07e0427115f030b9b573b2d8a3a91b71b9b89eb6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 12:55:11 2013 +0100

    tevent: s/epoll_change_event/epoll_update_event
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 056dcc7a8a9b0cac0b28ef6712eccf46e45c2474
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 17:15:52 2013 +0100

    tevent: the content of event is ignored by EPOLL_CTL_DEL
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2b3b06b9b428b72cf7f5f400c043abaca47850de
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 15 10:31:36 2013 +0100

    tevent: call epoll_panic() if EPOLL_CTL_DEL failed
    
    Only ENOENT is ignored as it is no error.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 31db8a08be445b252ba27b07106ca5b2e73cc325
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 13:12:27 2013 +0100

    tevent: use helper variables to hold the epoll_ctl() result
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b2114eb3b01a6259265391fbc41f0492bc26596e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Wed Feb 20 13:07:34 2013 +0100

    tevent: remove unused if (epoll_ev->epoll_fd == -1) return; checks
    
    We'll never leave epoll_check_reopen() with epoll_fd == -1.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5b9218a3c267cb51a389af14e88f5b4a0d3a77ea
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Feb 17 16:41:41 2013 +0100

    tevent: add std_event_loop_wait()
    
    We also need to fallback in tevent_loop_wait()
    otherwise we might miss events in the poll->fresh list.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 3fc93164fb83e396e2b757672d65269509fa7148
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Feb 17 16:40:20 2013 +0100

    tevent: don't call TALLOC_FREE(ev->additional_data) in std_fallback_to_poll()
    
    The epoll backend has done the cleanup already.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 73dabddbdce99c5bc19a4be814f88da581e6d372
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 15 16:33:56 2013 +0100

    tevent: avoid any operation on epoll_ev after a epoll_panic()
    
    This calls TALLOC_FREE(ev->additional_data), which is epoll_ev
    within epoll_panic() before calling the fallback handler.
    
    In order to notice that a epoll_panic() happened, a caller can
    register a pointer to a bool variable under epoll_ev->panic_state.
    
    As epoll_check_reopen() can fail due to a epoll_panic(),
    we need to force the replay flag if we have called any event handler.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 2b05c9621784da8e5aa793cd2110dde768084968
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 15 12:10:26 2013 +0100

    tevent: add epoll_{create,ctl}_panic_fallback() for testing
    
    This makes sure we only do random panics if a fallback handler
    is registered.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 8764ec80bbcba93e862c069766c00944e5187ed5
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 21 15:44:30 2013 +0100

    tevent: use DLIST_DEMOTE() before calling on fde handler after select() and poll()
    
    This makes sure we don't preferr events which are at the beginning
    of the list.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit b31767bf27bafd3ae20ba3f26dd5001051b9f2b6
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 28 14:43:55 2013 +0100

    tevent: debug a FATAL message on EBADF from the select backend
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5ca69148844e2f8940b571aef0812e85e08b7cc5
Author: Jeremy Allison <jra at samba.org>
Date:   Wed Feb 27 10:18:44 2013 -0800

    tevent: Fix multiple handler on the same fd bug in the tevent select backend.
    
    When we're deciding what handlers to call in the select backend,
    we didn't take into account the fact that the same fd may have
    been added into the read FD_SET and the write FD_SET but with
    different handlers.
    
    We must match on both the file descriptor and the flags requested
    before calling the handler.
    
    Signed-off-by: Jeremy Allison <jra at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit b53c704a34abca0ad69ae9a0dbb0db6a0a71043b
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 1 16:43:35 2013 +0100

    tevent: revalidate fde->flags after poll()
    
    This is important to avoid races between threads if the poll_mt
    backend is used.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 6952d761d2b9ebb2457916d9dfa3f070c0f62228
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 21:45:11 2013 +0100

    tevent: ignore POLLNVAL from poll() and disable the event
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit de0204ccae514b26524893b51414c6c772a35a55
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 21 15:41:17 2013 +0100

    tevent: traverse the ev->fd_event list instead of the poll_ev->fds array
    
    That has the same complexity but simplifies the code.
    
    It also seems to fix a real problem, which was found
    by the following test failure in Samba's autobuild,
    while removing the epoll support from the "standard" backend.
    
        [402/1555 in 19m8s] samba3.raw.composite(plugin_s4_dc)
        smbtorture 4.1.0pre1-DEVELOPERBUILD
        Using seed 1361531675
        Testing savefile
        Testing parallel fetchfile with 10 ops
        waiting for completion
        maximum runtime exceeded for smbtorture - terminating
        UNEXPECTED(error): samba3.raw.composite.fetchfile (subunit.RemotedTestCase)(plugin_s4_dc)
        REASON: _StringException: _StringException: was started but never finished!
        UNEXPECTED(error): samba3.raw.composite.fetchfile(plugin_s4_dc) (subunit.RemotedTestCase)
        REASON: was started but never finished!
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f45abeae40495460e29347ebc3c73b9ffece847d
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 28 17:07:28 2013 +0100

    tevent: maintain a list of disabled events in the poll backend
    
    We need to avoid passing pollfd.events == 0, to poll(),
    as it will report POLLERR and POLLHUP events, but our caller
    does not expect the event handler to be called.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit ef8130fdbf50384dca3669ab27de4863490d5cb1
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 28 17:04:00 2013 +0100

    tevent: merge poll_fresh_fde_destructor() into poll_event_fd_destructor()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f75fd905f72fff28cc2d8f5fc4e3240b039d3446
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 28 17:02:45 2013 +0100

    tevent: use tevent_poll_event_add_fd_internal() in poll_event_add_fd()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 8e3ef659f876573bd7abb7d0e707369157232125
Author: Stefan Metzmacher <metze at samba.org>
Date:   Thu Feb 21 14:41:24 2013 +0100

    tevent: make sure we cleanup the array passed to poll() after deleting an event
    
    If we don't cleanup the array passed to poll after an
    event was deleted, we may pass a bad file descriptor to poll().
    
    This was found by the following test failure in Samba's
    autobuild, while removing the epoll support from
    the "standard" backend.
    
        [48/1555 in 4m37s] samba3.smbtorture_s3.plain(s3dc).LOCK4
        UNEXPECTED(failure): samba3.smbtorture_s3.plain(s3dc).LOCK4.smbtorture(s3dc)
        REASON: _StringException: _StringException: using seed 1361530718
        host=127.0.0.2 share=tmp user=metze myname=sn-devel-104
        Running LOCK4
        starting locktest4
        Failed to create file: NT_STATUS_INVALID_HANDLE
        finished locktest4
        TEST LOCK4 FAILED!
        LOCK4 took 190.492 secs
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d5b341d873bc326843d80dd15d3cd3ef465234ae
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Feb 17 23:21:28 2013 +0100

    tevent: don't skip a fd event if the previous one was deleted during poll()
    
    In a threaded environment it can happen that an tevent_fd is talloc_free'ed
    while the main thread sleeps in the poll() syscall.
    
    In such a case poll_event_fd_destructor() would set poll_ev->fdes[i] = NULL.
    
    We then skip the removed event, but before we also skipped the one
    that was located at the end of the array. We moved it to possition
    'i', but the next loop uses 'i=i+1'.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit f86df3e364f55be5f320463e3c1b89ee3a49115e
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 15 11:24:59 2013 +0100

    tevent: remember the errno from select(), poll() and epoll_wait()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 883d20a9bf7444e6338e13d6efbcbc257e1d78b7
Author: Michael Adam <obnox at samba.org>
Date:   Tue Feb 26 15:54:57 2013 +0100

    tevent: add trace points BEFORE_LOOP_ONCE and AFTER_LOOP_ONCE
    
    The define TEVENT_HAS_LOOP_ONCE_TRACE_POINTS can be used to
    detect the new feature, without writing configure tests.
    
    Pair-Programmed-With: Stefan Metzmacher <metze at samba.org>
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Signed-off-by: Stefan Metzmacher <metze at samba.org>

commit 5f284bec47971ea25df5461dfb3fbed731c243a8
Author: Stefan Metzmacher <metze at samba.org>
Date:   Sun Feb 17 16:36:25 2013 +0100

    tevent: fix compiler warning in tevent_context_init_byname()
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit dea5115a3d92f1ea91d354849f382a08957c8ba9
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 21:48:11 2013 +0100

    tevent: fix some compiler warnings in testsuite.c
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 5c31b152d26dc726b24cf6e8d6d09d1c7b5aa86f
Author: Michael Adam <obnox at samba.org>
Date:   Tue Feb 26 15:51:38 2013 +0100

    tevent: fix a comment typo in tevent_epoll.c
    
    Signed-off-by: Michael Adam <obnox at samba.org>
    Reviewed-by: Stefan Metzmacher <metze at samba.org>

commit 4a7142ec04de94ae91119a39bd9e48adeab7368b
Author: Galen.Liu <galen.gang.liu at gmail.com>
Date:   Mon Feb 4 07:43:01 2013 +0100

    tevent: fix --disable-python cause configure fails (bug #8718)
    
    When we disable python, it will cause build fail!
    so, the patch will fix it.
    
    Reviewed-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d5f92571083c82347f58a415db828b064e377522
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 14:26:16 2013 +0100

    tevent: define TEVENT_NUM_SIGNALS based on configure checks
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 602cd7f6c6744c2468fb3350eb80ac15f5b9400c
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 14:53:07 2013 +0100

    lib/replace: add AC_CHECK_VALUEOF() macro
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit 87f255821b75accb0d91ac11cdf059f91bf6ecd4
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Feb 22 14:20:07 2013 +0100

    wafsamba: add CHECK_VALUEOF() helper
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

commit d9a69e6dbf61cffd6be473a460f6671573aa8564
Author: Stefan Metzmacher <metze at samba.org>
Date:   Fri Mar 1 09:27:29 2013 +0100

    s3:lib/events: make use of tevent_common_loop_timer_delay()
    
    This is critical as we also use tevent_common_add_timer().
    And if the common code does internal changes, it may affects
    both tevent_common_add_timer() and tevent_common_loop_timer_delay()
    together!
    
    Without this we rely on a specific behavior and version of
    tevent.
    
    Signed-off-by: Stefan Metzmacher <metze at samba.org>
    Reviewed-by: Jeremy Allison <jra at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 buildtools/wafsamba/samba_autoconf.py              |   20 +-
 lib/replace/libreplace_macros.m4                   |   15 +
 .../ABI/{tevent-0.9.17.sigs => tevent-0.9.18.sigs} |    1 +
 lib/tevent/libtevent.m4                            |   29 +
 lib/tevent/testsuite.c                             |  554 +++++++++++++++++++-
 lib/tevent/tevent.c                                |    7 +-
 lib/tevent/tevent.h                                |   11 +
 lib/tevent/tevent_epoll.c                          |  545 +++++++++++++++++---
 lib/tevent/tevent_internal.h                       |   14 +
 lib/tevent/tevent_poll.c                           |  188 +++++--
 lib/tevent/tevent_select.c                         |   21 +-
 lib/tevent/tevent_signal.c                         |    2 -
 lib/tevent/tevent_standard.c                       |   18 +-
 lib/tevent/tevent_timed.c                          |  117 ++++-
 lib/tevent/wscript                                 |   21 +-
 source3/lib/events.c                               |   36 +-
 16 files changed, 1421 insertions(+), 178 deletions(-)
 copy lib/tevent/ABI/{tevent-0.9.17.sigs => tevent-0.9.18.sigs} (97%)


Changeset truncated at 500 lines:

diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
index 76316d2..65c66f3 100644
--- a/buildtools/wafsamba/samba_autoconf.py
+++ b/buildtools/wafsamba/samba_autoconf.py
@@ -323,7 +323,25 @@ def CHECK_SIZEOF(conf, vars, headers=None, define=None):
             ret = False
     return ret
 
-
+ at conf
+def CHECK_VALUEOF(conf, v, headers=None, define=None):
+    '''check the value of a variable/define'''
+    ret = True
+    v_define = define
+    if v_define is None:
+        v_define = 'VALUEOF_%s' % v.upper().replace(' ', '_')
+    if CHECK_CODE(conf,
+                  'printf("%%u", (unsigned)(%s))' % v,
+                  define=v_define,
+                  execute=True,
+                  define_ret=True,
+                  quote=False,
+                  headers=headers,
+                  local_include=False,
+                  msg="Checking value of %s" % v):
+        return int(conf.env[v_define])
+
+    return None
 
 @conf
 def CHECK_CODE(conf, code, define,
diff --git a/lib/replace/libreplace_macros.m4 b/lib/replace/libreplace_macros.m4
index 42b8847..f3753c4 100644
--- a/lib/replace/libreplace_macros.m4
+++ b/lib/replace/libreplace_macros.m4
@@ -330,3 +330,18 @@ fi
   AC_DEFINE_UNQUOTED($ac_tr_hdr, 1, [Define if you have type `$1'])
 fi
 ])
+
+# AC_CHECK_VALUEOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
+# ---------------------------------------------------------------
+AC_DEFUN([AC_CHECK_VALUEOF],
+[AS_LITERAL_IF(m4_translit([[$1]], [*], [p]), [],
+	       [m4_fatal([$0: requires literal arguments])])]dnl
+[
+_AC_CACHE_CHECK_INT([value of $1], [AS_TR_SH([ac_cv_valueof_$1])],
+  [(long int) ($1)],
+  [AC_INCLUDES_DEFAULT([$2])],
+  [])
+
+AC_DEFINE_UNQUOTED(AS_TR_CPP(valueof_$1), $AS_TR_SH([ac_cv_valueof_$1]),
+		   [The value of `$1'.])
+])# AC_CHECK_VALUEOF
diff --git a/lib/tevent/ABI/tevent-0.9.17.sigs b/lib/tevent/ABI/tevent-0.9.18.sigs
similarity index 97%
copy from lib/tevent/ABI/tevent-0.9.17.sigs
copy to lib/tevent/ABI/tevent-0.9.18.sigs
index ea7f944..70d20b6 100644
--- a/lib/tevent/ABI/tevent-0.9.17.sigs
+++ b/lib/tevent/ABI/tevent-0.9.18.sigs
@@ -21,6 +21,7 @@ tevent_cleanup_pending_signal_handlers: void (struct tevent_signal *)
 tevent_common_add_fd: struct tevent_fd *(struct tevent_context *, TALLOC_CTX *, int, uint16_t, tevent_fd_handler_t, void *, const char *, const char *)
 tevent_common_add_signal: struct tevent_signal *(struct tevent_context *, TALLOC_CTX *, int, int, tevent_signal_handler_t, void *, const char *, const char *)
 tevent_common_add_timer: struct tevent_timer *(struct tevent_context *, TALLOC_CTX *, struct timeval, tevent_timer_handler_t, void *, const char *, const char *)
+tevent_common_add_timer_v2: struct tevent_timer *(struct tevent_context *, TALLOC_CTX *, struct timeval, tevent_timer_handler_t, void *, const char *, const char *)
 tevent_common_check_signal: int (struct tevent_context *)
 tevent_common_context_destructor: int (struct tevent_context *)
 tevent_common_fd_destructor: int (struct tevent_fd *)
diff --git a/lib/tevent/libtevent.m4 b/lib/tevent/libtevent.m4
index 5c5969b..4d4fd2b 100644
--- a/lib/tevent/libtevent.m4
+++ b/lib/tevent/libtevent.m4
@@ -39,6 +39,35 @@ if test x"$ac_cv_header_sys_epoll_h" = x"yes" -a x"$ac_cv_func_epoll_create" = x
    AC_DEFINE(HAVE_EPOLL, 1, [Whether epoll available])
 fi
 
+tevent_num_signals_includes="$ac_includes_default
+#include <signal.h>
+"
+tevent_num_signals=64
+AC_CHECK_VALUEOF(NSIG, [$tevent_num_signals_includes])
+v=$ac_cv_valueof_NSIG
+test -n "$v" && test "$v" -gt "$tevent_num_signals" && {
+	tevent_num_signals=$v
+}
+AC_CHECK_VALUEOF(_NSIG, [$tevent_num_signals_includes])
+v=$ac_cv_valueof__NSIG
+test -n "$v" && test "$v" -gt "$tevent_num_signals" && {
+	tevent_num_signals=$v
+}
+AC_CHECK_VALUEOF(SIGRTMAX, [$tevent_num_signals_includes])
+v=$ac_cv_valueof_SIGRTMAX
+test -n "$v" && test "$v" -gt "$tevent_num_signals" && {
+	tevent_num_signals=$v
+}
+AC_CHECK_VALUEOF(SIGRTMIN, [$tevent_num_signals_includes])
+v=$ac_cv_valueof_SIGRTMIN
+test -n "$v" && {
+	v=`expr $v + $v`
+}
+test -n "$v" && test "$v" -gt "$tevent_num_signals" && {
+	tevent_num_signals=$v
+}
+AC_DEFINE_UNQUOTED(TEVENT_NUM_SIGNALS, $tevent_num_signals, [Max signal number value])
+
 if test x"$VERSIONSCRIPT" != "x"; then
     EXPORTSFILE=tevent.exports
     AC_SUBST(EXPORTSFILE)
diff --git a/lib/tevent/testsuite.c b/lib/tevent/testsuite.c
index 3d2a79a..8e3f4af 100644
--- a/lib/tevent/testsuite.c
+++ b/lib/tevent/testsuite.c
@@ -4,6 +4,7 @@
    testing of the events subsystem
 
    Copyright (C) Stefan Metzmacher 2006-2009
+   Copyright (C) Jeremy Allison    2013
 
      ** NOTE! The following LGPL license applies to the tevent
      ** library. This does NOT imply that all of Samba is released
@@ -27,6 +28,7 @@
 #include "lib/tevent/tevent.h"
 #include "system/filesys.h"
 #include "system/select.h"
+#include "system/network.h"
 #include "torture/torture.h"
 #ifdef HAVE_PTHREAD
 #include <pthread.h>
@@ -35,7 +37,7 @@
 
 static int fde_count;
 
-static void fde_handler(struct tevent_context *ev_ctx, struct tevent_fd *f, 
+static void fde_handler_read(struct tevent_context *ev_ctx, struct tevent_fd *f,
 			uint16_t flags, void *private_data)
 {
 	int *fd = (int *)private_data;
@@ -44,11 +46,38 @@ static void fde_handler(struct tevent_context *ev_ctx, struct tevent_fd *f,
 	kill(getpid(), SIGUSR1);
 #endif
 	kill(getpid(), SIGALRM);
+
 	read(fd[0], &c, 1);
-	write(fd[1], &c, 1);
 	fde_count++;
 }
 
+static void fde_handler_write(struct tevent_context *ev_ctx, struct tevent_fd *f,
+			uint16_t flags, void *private_data)
+{
+	int *fd = (int *)private_data;
+	char c = 0;
+	write(fd[1], &c, 1);
+}
+
+
+/* These should never fire... */
+static void fde_handler_read_1(struct tevent_context *ev_ctx, struct tevent_fd *f,
+			uint16_t flags, void *private_data)
+{
+	struct torture_context *test = (struct torture_context *)private_data;
+	torture_comment(test, "fde_handler_read_1 should never fire !\n");
+	abort();
+}
+
+/* These should never fire... */
+static void fde_handler_write_1(struct tevent_context *ev_ctx, struct tevent_fd *f,
+			uint16_t flags, void *private_data)
+{
+	struct torture_context *test = (struct torture_context *)private_data;
+	torture_comment(test, "fde_handler_write_1 should never fire !\n");
+	abort();
+}
+
 static void finished_handler(struct tevent_context *ev_ctx, struct tevent_timer *te,
 			     struct timeval tval, void *private_data)
 {
@@ -70,17 +99,21 @@ static bool test_event_context(struct torture_context *test,
 	int fd[2] = { -1, -1 };
 	const char *backend = (const char *)test_data;
 	int alarm_count=0, info_count=0;
-	struct tevent_fd *fde;
+	struct tevent_fd *fde_read;
+	struct tevent_fd *fde_read_1;
+	struct tevent_fd *fde_write;
+	struct tevent_fd *fde_write_1;
 #ifdef SA_RESTART
 	struct tevent_signal *se1 = NULL;
 #endif
+#ifdef SA_RESETHAND
 	struct tevent_signal *se2 = NULL;
+#endif
 #ifdef SA_SIGINFO
 	struct tevent_signal *se3 = NULL;
 #endif
 	int finished=0;
 	struct timeval t;
-	char c = 0;
 
 	ev_ctx = tevent_context_init_byname(test, backend);
 	if (ev_ctx == NULL) {
@@ -88,7 +121,8 @@ static bool test_event_context(struct torture_context *test,
 		return true;
 	}
 
-	torture_comment(test, "Testing event backend '%s'\n", backend);
+	torture_comment(test, "backend '%s' - %s\n",
+			backend, __FUNCTION__);
 
 	/* reset globals */
 	fde_count = 0;
@@ -96,25 +130,35 @@ static bool test_event_context(struct torture_context *test,
 	/* create a pipe */
 	pipe(fd);
 
-	fde = tevent_add_fd(ev_ctx, ev_ctx, fd[0], TEVENT_FD_READ,
-			    fde_handler, fd);
-	tevent_fd_set_auto_close(fde);
+	fde_read = tevent_add_fd(ev_ctx, ev_ctx, fd[0], TEVENT_FD_READ,
+			    fde_handler_read, fd);
+	fde_write_1 = tevent_add_fd(ev_ctx, ev_ctx, fd[0], TEVENT_FD_WRITE,
+			    fde_handler_write_1, test);
+
+	fde_write = tevent_add_fd(ev_ctx, ev_ctx, fd[1], TEVENT_FD_WRITE,
+			    fde_handler_write, fd);
+	fde_read_1 = tevent_add_fd(ev_ctx, ev_ctx, fd[1], TEVENT_FD_READ,
+			    fde_handler_read_1, test);
+
+	tevent_fd_set_auto_close(fde_read);
+	tevent_fd_set_auto_close(fde_write);
 
 	tevent_add_timer(ev_ctx, ev_ctx, timeval_current_ofs(2,0),
 			 finished_handler, &finished);
 
 #ifdef SA_RESTART
 	se1 = tevent_add_signal(ev_ctx, ev_ctx, SIGALRM, SA_RESTART, count_handler, &alarm_count);
+	torture_assert(test, se1 != NULL, "failed to setup se1");
 #endif
 #ifdef SA_RESETHAND
 	se2 = tevent_add_signal(ev_ctx, ev_ctx, SIGALRM, SA_RESETHAND, count_handler, &alarm_count);
+	torture_assert(test, se2 != NULL, "failed to setup se2");
 #endif
 #ifdef SA_SIGINFO
 	se3 = tevent_add_signal(ev_ctx, ev_ctx, SIGUSR1, SA_SIGINFO, count_handler, &info_count);
+	torture_assert(test, se3 != NULL, "failed to setup se3");
 #endif
 
-	write(fd[1], &c, 1);
-
 	t = timeval_current();
 	while (!finished) {
 		errno = 0;
@@ -124,8 +168,10 @@ static bool test_event_context(struct torture_context *test,
 		}
 	}
 
-	talloc_free(fde);
-	close(fd[1]);
+	talloc_free(fde_read);
+	talloc_free(fde_write);
+	talloc_free(fde_read_1);
+	talloc_free(fde_write_1);
 
 	while (alarm_count < fde_count+1) {
 		if (tevent_loop_once(ev_ctx) == -1) {
@@ -141,6 +187,14 @@ static bool test_event_context(struct torture_context *test,
 
 	torture_assert_int_equal(test, alarm_count, 1+fde_count, "alarm count mismatch");
 
+#ifdef SA_RESETHAND
+	/*
+	 * we do not call talloc_free(se2)
+	 * because it is already gone,
+	 * after triggering the event handler.
+	 */
+#endif
+
 #ifdef SA_SIGINFO
 	talloc_free(se3);
 	torture_assert_int_equal(test, info_count, fde_count, "info count mismatch");
@@ -151,6 +205,460 @@ static bool test_event_context(struct torture_context *test,
 	return true;
 }
 
+struct test_event_fd1_state {
+	struct torture_context *tctx;
+	const char *backend;
+	struct tevent_context *ev;
+	int sock[2];
+	struct tevent_timer *te;
+	struct tevent_fd *fde0;
+	struct tevent_fd *fde1;
+	bool got_write;
+	bool got_read;
+	bool drain;
+	bool drain_done;
+	unsigned loop_count;
+	bool finished;
+	const char *error;
+};
+
+static void test_event_fd1_fde_handler(struct tevent_context *ev_ctx,
+				       struct tevent_fd *fde,
+				       uint16_t flags,
+				       void *private_data)
+{
+	struct test_event_fd1_state *state =
+		(struct test_event_fd1_state *)private_data;
+
+	if (state->drain_done) {
+		state->finished = true;
+		state->error = __location__;
+		return;
+	}
+
+	if (state->drain) {
+		ssize_t ret;
+		uint8_t c = 0;
+
+		if (!(flags & TEVENT_FD_READ)) {
+			state->finished = true;
+			state->error = __location__;
+			return;
+		}
+
+		ret = read(state->sock[0], &c, 1);
+		if (ret == 1) {
+			return;
+		}
+
+		/*
+		 * end of test...
+		 */
+		tevent_fd_set_flags(fde, 0);
+		state->drain_done = true;
+		return;
+	}
+
+	if (!state->got_write) {
+		uint8_t c = 0;
+
+		if (flags != TEVENT_FD_WRITE) {
+			state->finished = true;
+			state->error = __location__;
+			return;
+		}
+		state->got_write = true;
+
+		/*
+		 * we write to the other socket...
+		 */
+		write(state->sock[1], &c, 1);
+		TEVENT_FD_NOT_WRITEABLE(fde);
+		TEVENT_FD_READABLE(fde);
+		return;
+	}
+
+	if (!state->got_read) {
+		if (flags != TEVENT_FD_READ) {
+			state->finished = true;
+			state->error = __location__;
+			return;
+		}
+		state->got_read = true;
+
+		TEVENT_FD_NOT_READABLE(fde);
+		return;
+	}
+
+	state->finished = true;
+	state->error = __location__;
+	return;
+}
+
+static void test_event_fd1_finished(struct tevent_context *ev_ctx,
+				    struct tevent_timer *te,
+				    struct timeval tval,
+				    void *private_data)
+{
+	struct test_event_fd1_state *state =
+		(struct test_event_fd1_state *)private_data;
+
+	if (state->drain_done) {
+		state->finished = true;
+		return;
+	}
+
+	if (!state->got_write) {
+		state->finished = true;
+		state->error = __location__;
+		return;
+	}
+
+	if (!state->got_read) {
+		state->finished = true;
+		state->error = __location__;
+		return;
+	}
+
+	state->loop_count++;
+	if (state->loop_count > 3) {
+		state->finished = true;
+		state->error = __location__;
+		return;
+	}
+
+	state->got_write = false;
+	state->got_read = false;
+
+	tevent_fd_set_flags(state->fde0, TEVENT_FD_WRITE);
+
+	if (state->loop_count > 2) {
+		state->drain = true;
+		TALLOC_FREE(state->fde1);
+		TEVENT_FD_READABLE(state->fde0);
+	}
+
+	state->te = tevent_add_timer(state->ev, state->ev,
+				    timeval_current_ofs(0,2000),
+				    test_event_fd1_finished, state);
+}
+
+static bool test_event_fd1(struct torture_context *tctx,
+			   const void *test_data)
+{
+	struct test_event_fd1_state state;
+
+	ZERO_STRUCT(state);
+	state.tctx = tctx;
+	state.backend = (const char *)test_data;
+
+	state.ev = tevent_context_init_byname(tctx, state.backend);
+	if (state.ev == NULL) {
+		torture_skip(tctx, talloc_asprintf(tctx,
+			     "event backend '%s' not supported\n",
+			     state.backend));
+		return true;
+	}
+
+	tevent_set_debug_stderr(state.ev);
+	torture_comment(tctx, "backend '%s' - %s\n",
+			state.backend, __FUNCTION__);
+
+	/*
+	 * This tests the following:
+	 *
+	 * It monitors the state of state.sock[0]
+	 * with tevent_fd, but we never read/write on state.sock[0]
+	 * while state.sock[1] * is only used to write a few bytes.
+	 *
+	 * We have a loop:
+	 *   - we wait only for TEVENT_FD_WRITE on state.sock[0]
+	 *   - we write 1 byte to state.sock[1]
+	 *   - we wait only for TEVENT_FD_READ on state.sock[0]
+	 *   - we disable events on state.sock[0]
+	 *   - the timer event restarts the loop
+	 * Then we close state.sock[1]
+	 * We have a loop:
+	 *   - we wait for TEVENT_FD_READ/WRITE on state.sock[0]
+	 *   - we try to read 1 byte
+	 *   - if the read gets an error of returns 0
+	 *     we disable the event handler
+	 *   - the timer finishes the test
+	 */
+	state.sock[0] = -1;
+	state.sock[1] = -1;
+	socketpair(AF_UNIX, SOCK_STREAM, 0, state.sock);
+
+	state.te = tevent_add_timer(state.ev, state.ev,
+				    timeval_current_ofs(0,1000),
+				    test_event_fd1_finished, &state);
+	state.fde0 = tevent_add_fd(state.ev, state.ev,
+				   state.sock[0], TEVENT_FD_WRITE,
+				   test_event_fd1_fde_handler, &state);
+	/* state.fde1 is only used to auto close */
+	state.fde1 = tevent_add_fd(state.ev, state.ev,
+				   state.sock[1], 0,
+				   test_event_fd1_fde_handler, &state);
+
+	tevent_fd_set_auto_close(state.fde0);
+	tevent_fd_set_auto_close(state.fde1);
+
+	while (!state.finished) {
+		errno = 0;
+		if (tevent_loop_once(state.ev) == -1) {
+			talloc_free(state.ev);
+			torture_fail(tctx, talloc_asprintf(tctx,
+				     "Failed event loop %s\n",
+				     strerror(errno)));
+		}
+	}
+
+	talloc_free(state.ev);
+
+	torture_assert(tctx, state.error == NULL, talloc_asprintf(tctx,
+		       "%s", state.error));
+
+	return true;
+}


-- 
Samba Shared Repository


More information about the samba-cvs mailing list