wayland/tests
Benjamin Herr 391820b0d6 connection: Leave fd open in wl_connection_destroy
Calling close() on the same file descriptor that a previous call to
close() already closed is wrong, and racy if another thread received
that same file descriptor as a eg. new socket or actual file.

There are two situations where wl_connection_destroy() would close its
file descriptor and then another function up in the call chain would
close the same file descriptor:

  * When wl_client_create() fails after calling wl_connection_create(),
    it will call wl_connection_destroy() before returning. However, its
    caller will always close the file descriptor if wl_client_create()
    fails.

  * wl_display_disconnect() unconditionally closes the display file
    descriptor and also calls wl_connection_destroy().

So these two seem to expect wl_connection_destroy() to leave the file
descriptor open. The other caller of wl_connection_destroy(),
wl_client_destroy(), does however expect wl_connection_destroy() to
close its file descriptor, alas.

This patch changes wl_connection_destroy() to indulge this majority of
two callers by simply not closing the file descriptor. For the benefit
of wl_client_destroy(), wl_connection_destroy() then returns the
unclosed file descriptor so that wl_client_destroy() can close it
itself.

Since wl_connection_destroy() is a private function called from few
places, changing its semantics seemed like the more expedient way to
address the double-close() problem than shuffling around the logic in
wl_client_create() to somehow enable it to always avoid calling
wl_connection_destroy().

Signed-off-by: Benjamin Herr <ben@0x539.de>
Reviewed-by: Marek Chalupa <mchqwerty@gmail.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2014-11-04 11:26:22 +02:00
..
array-test.c array-test: assert wl_array_add result is not NULL 2014-01-15 10:46:08 -08:00
client-test.c server: Make wl_object and wl_resource opaque structs 2013-07-02 15:52:47 -04:00
connection-test.c connection: Leave fd open in wl_connection_destroy 2014-11-04 11:26:22 +02:00
display-test.c display-test: test if threads are woken up on EAGAIN 2014-09-11 10:21:08 +03:00
event-loop-test.c tests: fix event_loop_timer_updates 2014-08-19 14:34:50 +03:00
exec-fd-leak-checker.c tests: support testing fd inheritance over exec 2012-04-20 15:06:27 +03:00
fixed-benchmark.c tests: fix make check for out-of-tree builds 2012-06-30 19:58:37 +00:00
fixed-test.c tests: fix make check for out-of-tree builds 2012-06-30 19:58:37 +00:00
list-test.c tests: fix make check for out-of-tree builds 2012-06-30 19:58:37 +00:00
map-test.c Update tests for wl_map changes and add a map_flags test 2013-06-05 17:55:14 -04:00
message-test.c tests: Add message version sanity test 2014-05-09 14:32:04 -07:00
os-wrappers-test.c os-wrappers-test: assert closure is not NULL before invoking it 2014-01-15 10:46:08 -08:00
queue-test.c tests: use test compositor in queue-test 2014-08-22 12:39:52 +03:00
resources-test.c resources-test: Don't send invalid event 2014-01-20 15:07:55 -08:00
sanity-test.c tests: ensure sanity leak check tests pass when leak checks are disabled. 2012-08-29 14:10:24 -04:00
signal-test.c tests: add unit tests for wl_signal 2013-09-21 11:37:38 -07:00
socket-test.c tests: add tests for bug in adding socket 2014-08-07 16:04:17 +03:00
test-compositor.c tests: add test-compositor 2014-08-22 12:34:33 +03:00
test-compositor.h tests: add test-compositor 2014-08-22 12:34:33 +03:00
test-helpers.c tests: support testing fd inheritance over exec 2012-04-20 15:06:27 +03:00
test-runner.c tests: extended message when leak in test is detected 2013-09-21 11:36:33 -07:00
test-runner.h tests: support testing fd inheritance over exec 2012-04-20 15:06:27 +03:00