Commit Graph

666 Commits

Author SHA1 Message Date
Michael Stapelberg 4f25ee1644 Drop AI_ADDRCONFIG when resolving TCP addresses
When a system is completely offline (no interface has an IP address but 'lo'),
xcb could not connect to localhost via TCP, e.g. connections with
DISPLAY=127.0.0.1:0 fail.

AI_ADDRCONFIG will only return IPv4 addresses if the system has an IPv4
address configured (likewise for IPv6). This also takes place when
resolving localhost (or 127.0.0.0/8 or ::1). Also, as per RFC 3493,
loopback addresses are not considered as valid addresses when
determining whether to return IPv4 or IPv6 addresses.

As per mailing-list discussion on the xcb list started with message
20110813215405.5818a0c1@x200, the AI_ADDRCONFIG flag is there for historical
reasons:

    In the old days, the "default on-link" assumption in IPv6 made the flag vey
    much indispensable for dual-stack hosts on IPv4-only networks. Without it,
    there would be long timeouts trying non-existent IPv6 connectivity. Nowadays,
    this assumption has been flagged as historic bad practice by IETF, and hosts
    should have been updated to not make it anymore.

    Then AI_ADDRCONFIG became mostly cosmetic: it avoids phony "Protocol family
    not supported" or "Host unreachable" errors while trying to connect to a dual-
    stack mode from a host with no support for source address selection.

    Nowadays, on up-to-date systems, this flag is completely useless. Then again,
    I understood only the very latest MacOS release is "up-to-date" with this
    definition.
2011-08-18 13:39:56 -07:00
James Jones 662ad589c5 Insert, not append explicit xcbgen dir python path
If a the path to the xcb python generate libs is
explicitly specified to c_client.py, insert it in
the python path list just after the local dir entry,
rather than appending it to the existing paths.
This keeps a global/distro install of xcb from
overriding a local build of the xcb proto files.

Signed-off-by: James Jones <jajones@nvidia.com>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-05-11 23:49:39 -07:00
David Coles 294c9f455c Add support for building with Python 3
Python 3 introduces some language changes that cause issues when running
c_client.py. This also breaks compatibility with Python 2.5 since it does not
support the "as" statement in try/except blocks and does not have reduce() in
the functools package.

The main changes are:
* try/except blocks require `except ... as ...:` to resolve syntactical ambiguity
* map() and filter() return iterators rather than lists in Python 3
* reduce() is now in functools package (and not built-in in Python 3)
* Dictionaries don't have a has_key() method in Python 3
* None and int types can't be directly compared in Python 3
* print() is a statement in Python 3

See http://diveintopython3.org/porting-code-to-python-3-with-2to3.html and
PEP-3110 for details.

Verified on Python 2.6.5 and 3.1.3.

Signed-off-by: David Coles <dcoles@gaikai.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
2011-05-04 15:00:21 +02:00
Jamey Sharp e300ee4920 Revert "Introduce xcb_wait_for_event_until, for consuming responses in wire-order."
This function was intended to allow libX11 to fix a multi-threaded hang,
but the corresponding libX11 patch caused single-threaded apps to spin
sometimes. Since I've retracted that patch, this patch has no users and
shouldn't go into a release unless/until that changes.

This reverts commit 2415c11dec.

Conflicts:

	src/xcb.h
	src/xcb_in.c

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-04-12 13:11:48 -07:00
Rami Ylimäki 527df3c84b Introduce a variant of xcb_poll_for_event for examining event queue.
In some circumstances using xcb_poll_for_event is suboptimal because
it checks the connection for new events. This may lead to a lot of
failed nonblocking read system calls.

Signed-off-by: Rami Ylimäki <rami.ylimaki@vincit.fi>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-04-12 13:05:59 -07:00
Alan Coopersmith b64cd0df88 If protocol is "unix", use a Unix domain socket, not TCP
Fixes fallback to local connections from Xlib's XOpenDisplay(), which
will try with protocol "unix" if a hostname is specified and tcp fails
(as it usually will now that most OS'es ship with -nolisten tcp enabled).

Also fixes explicitly specifying DISPLAY as "unix/foo:0", which Xlib
previously accepted for Unix domain sockets.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2011-04-12 13:01:03 -07:00
Alan Coopersmith b027922ebf Make launchd code in xcb_util.c match surrounding code indent levels
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2011-04-12 13:01:03 -07:00
Carlos Garnacho 82b1f3919a Handle XGE events with the "send event" flag
This patch is necessary so xcb reads the payload after the message
for GenericEvents with the 0x80 flag turned on.

Signed-off-by: Carlos Garnacho <carlosg@gnome.org>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-04-12 12:57:37 -07:00
Alan Coopersmith 42c4adeff4 Add #include <sys/socket.h> to xcb_conn.c
Solves compiler warning on Solaris:
"xcb_conn.c", line 304: warning: implicit function declaration: shutdown

Also provides system definition of SHUT_RDWR on Solaris 11.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
2011-04-04 22:06:16 -07:00
Alan Coopersmith 4b502dd696 Remove unused DECnet code
"unifdef -UDNETCONN src/xcb_util.c" plus re-indenting code that was
formerly in the else clause after a DECnet check.

DECnet support has been removed from most of the X.Org code base for
several years, and it appears DNETCONN was never defined in XCB.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Jamey Sharp <jamey@minilop.net>
2011-04-04 22:06:03 -07:00
Alan Coopersmith 7131d5d070 Use special path to sockets when running under Solaris Trusted Extensions
Solaris Trusted Extensions puts the endpoints for the X server's Unix
domain sockets in a special directory shared from the global zone to
each of the labeled zones, since each labeled zone has a separate /tmp.

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Peter Harris <pharris@opentext.com>
2011-04-04 19:56:16 -07:00
Rami Ylimäki 70976d87f1 Prevent theoretical double free and leak on get_peer_sock_name.
Variable new_sockname will leak and sockname will be double freed if
both of the cases shown below are true.

1. realloc succeeds and doesn't return the original pointer
2. calling socket_func fails

Signed-off-by: Rami Ylimäki <rami.ylimaki@vincit.fi>
Signed-off-by: Erkki Seppälä <erkki.seppala@vincit.fi>
Reviewed-by: Arnaud Fontaine <arnau@debian.org>
Signed-off-by: Peter Harris <pharris@opentext.com>
2011-03-24 11:30:21 -04:00
Jamey Sharp 3678159e4e Delete the old c-client.xsl.
It hasn't been used since libxcb 1.1.90.1, released in 2008.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-03-19 20:04:55 -07:00
Jamey Sharp 2415c11dec Introduce xcb_wait_for_event_until, for consuming responses in wire-order.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2011-03-18 21:59:47 -07:00
Jamey Sharp 29a974f212 Dequeue readers that can't receive any new responses.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2011-03-18 21:59:44 -07:00
Jamey Sharp 131e867fca Factor reader_list management out of wait_for_reply.
Later patches will insert reader_list entries from other entry points.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2011-03-18 21:59:38 -07:00
Jamey Sharp 1469e87965 Enable AM_SILENT_RULES on automake 1.11 or newer.
This incantation is supposed to be a no-op on earlier automake versions.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Josh Triplett <josh@freedesktop.org>
2011-03-18 21:58:45 -07:00
Rami Ylimäki 6310475e23 Prevent reply waiters from being blocked.
It's possible to call xcb_wait_for_reply more than once for a single
request. In this case we are nice and let reply waiters continue so
that they can notice that the reply is not available
anymore. Otherwise an event waiter could just signal the reply waiter
that got its reply to continue but leave a waiter for an earlier reply
blocked.

Below is an example sequence for reproducing this problem.

thread #1 (XNextEvent)
  - waits for events
thread #2 (XSync)
  - executes request #2
  - waits for reply #2
thread #1
  - reads reply #2
  - signals waiter of reply #2 to continue
  - waits for events
thread #2
  - handles reply #2
thread #3 (XCloseDisplay)
  - executes request #3
  - waits for reply #2
thread #1
  - reads reply #3
  - nobody is waiting for reply #3 so don't signal
  - wait for events

Of course it may be questionable to wait for a reply twice, but XCB
should be smart enough to let clients continue if they choose to do
so.

Signed-off-by: Rami Ylimäki <rami.ylimaki@vincit.fi>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-03-14 17:19:14 -07:00
Jamey Sharp 29ab5aeb9b Include XKB in ./configure's summary output.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2011-03-13 09:41:10 -07:00
Jamey Sharp 2edfd5c375 Merge branch 'master' of git+ssh://git.freedesktop.org/git/xcb/libxcb
Apparently I forgot to push these months ago.
2011-03-13 09:33:44 -07:00
Jeremy Huddleston 8c3325f8bb darwin: Don't use poll() when expected to run on darwin10 and prior
Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
2011-03-04 12:41:55 -08:00
Peter Harris c2e0236462 Don't try to sizeof(void)
sizeof(void) is a gcc extension, and not portable.

Xorg Bugzilla 31959
http://bugs.freedesktop.org/show_bug.cgi?id=31959
http://lists.freedesktop.org/archives/xcb/2010-May/006039.html

Signed-off-by: Peter Harris <pharris@opentext.com>
Tested-by: Cyril Brulebois <kibi@debian.org>
2011-01-27 15:38:36 -05:00
Vincent Torri 9efced72a3 fix Windows build and installation 2011-01-20 20:46:04 -05:00
Peter Harris 3c58136971 Merge branch 'master' of git://anongit.freedesktop.org/~peterh/libxcb 2010-12-23 13:04:40 -05:00
Jeetu Golani 69b78ced1a Don't validate FD_SETSIZE on Win32
Windows' file handles have never been small or consecutive, so Windows'
select has always been implemented the same way as everyone else's poll.

On Windows, FD_SETSIZE is the size of the poll array, not the maximum
SOCKET number.

Signed-off-by: Peter Harris <git@peter.is-a-geek.org>
2010-12-12 16:48:41 -05:00
Uli Schlachter 8ecd754b16 xcb_take_socket: Document sequence wrap requirements
If lots of requests are send without one causing a reply, xcb can get confused
about the current sequence number of a reply. Document the requirements of an
external socket owner to avoid this problem.

The return_socket callback for xcb_take_socket() originally was supposed to
return the last sequence number used, but the version committed to libxcb never
actually had this signature. This fixes the function's documentation not to
mention this non-existent return value.

Signed-off-by: Uli Schlachter <psychon@znc.in>
Signed-off-by: Julien Danjou <julien@danjou.info>
2010-11-27 12:48:27 +01:00
Nick Bowler 5755582444 xcb_auth: Fix memory leak in _xcb_get_auth_info.
If the initial get_peer_sock_name(getpeername ...) succeeds, the
pointer to allocated memory is overwritten by the later call to
get_peer_sock_name(getsockname ...).  Fix that up by freeing
the allocated memory before overwriting the pointer.

Signed-off-by: Nick Bowler <nbowler@draconx.ca>
Signed-off-by: Julien Danjou <julien@danjou.info>
2010-11-23 14:58:48 +01:00
Jamey Sharp ed37b08751 xcb_in: Use 64-bit sequence numbers internally everywhere.
Widen sequence numbers on entry to those public APIs that still take
32-bit sequence numbers.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 17:13:45 -07:00
Jamey Sharp 6c8b539c2a xcb_discard_reply: Simplify by re-using poll_for_reply helper.
If you discard a sequence number that has multiple responses already
read, this will do more allocations than necessary. But nobody cares
about ListFontsWithInfo.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 13:19:05 -07:00
Jamey Sharp 3a74b5e7a1 xcb_request_check: Hold the I/O lock while deciding to sync.
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 12:37:48 -07:00
Jamey Sharp ee1bc1d28a xcb_send_request: Send all requests using a common internal send_request.
This simplifies the critical section of xcb_send_request and fixes a
couple of subtle bugs:

- It's possible for xcb_send_request to need to issue two sync requests
  before it can issue the real request. Previously, we counted sequence
  numbers as if both were issued, but only one went out on the wire.

- The test for whether to sync at 32-bit sequence number wrap has been
  incorrect since we switched to 64-bit sequence numbers internally.

This change means that if the output queue was already full and the
current request is bigger than the output queue, XCB will do one more
write syscall than it did before. But syncs are rare and small requests
are the norm, so this shouldn't be a measurable difference.

Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-10-09 12:37:23 -07:00
Peter Harris b672d1514c Fix _unserialize of reply headers
This cleans up a number of warnings, and passes the sequence number
through correctly.

Signed-off-by: Peter Harris <pharris@opentext.com>
2010-09-22 23:16:33 -04:00
Peter Harris 29cca33b90 Clean up a couple of warnings in xprint
Signed-off-by: Peter Harris <pharris@opentext.com>
2010-09-22 22:32:51 -04:00
Peter Harris 8c1d2021ca Make *_unserialize safe to use on buffers in-place
By calling memmove instead of memcpy, and walking the buffer backward
from the end, *_unserialize is safe to use in-place.

Signed-off-by: Peter Harris <pharris@opentext.com>
2010-09-22 22:20:04 -04:00
Peter Harris 28a71c6567 Fix memory leak in _sizeof implemented with _unserialize
Signed-off-by: Peter Harris <pharris@opentext.com>
2010-09-22 22:20:04 -04:00
Peter Harris a22909c0f5 Don't emit out-of-module sizeof definitions
Signed-off-by: Peter Harris <pharris@opentext.com>
2010-09-22 22:20:04 -04:00
Josh Triplett 1c4717de36 Allow disconnecting connections that are in error state.
In support of this, consolidate the two static error_connection
definitions into one so we don't try to free the static out-of-memory
error_connection.

Commit by Josh Triplett and Jamey Sharp.

Signed-off-by: Josh Triplett <josh@joshtriplett.org>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-09-19 20:38:06 +02:00
Peter Harris 03bcccb132 Add xkb.* to gitignore
Signed-off-by: Peter Harris <pharris@opentext.com>
2010-09-10 15:54:56 -04:00
Peter Harris 28d3925800 Merge branch 'gsoc2010' of git://anongit.freedesktop.org/~chr/libxcb 2010-09-08 14:41:52 -04:00
Jamey Sharp f0565e8f06 _xcb_conn_wait: Shut down the connection on unexpected poll() events.
If a client calls close(2) on the connection's file descriptor and then
flushes writes, libxcb causes a hang in the client.

Any flush eventually calls _xcb_out_send() with has the following loop:
   while(ret && *count)
       ret = _xcb_conn_wait(c, &c->out.cond, vector, count);

_xcb_conn_wait(), if built with USE_POLL, gets the POLLNVAL error. It only
checks for POLLIN and POLLOUT though, ignoring the error. Return value is 1,
count is unmodified, leaving us with an endless loop and a client hang.

XTS testcase Xlib3/XConnectionNumber triggers this bug. It creates a display
connection, closes its file descriptor, tries to send a no-op, and then expects
an error.
http://cgit.freedesktop.org/xorg/test/xts/tree/xts5/Xlib3/XConnectionNumber.m

If poll returned POLLHUP or POLLERR, we might see the same result.

If poll returns any event we didn't ask for, this patch causes
_xcb_conn_shutdown() to be invoked and an error returned. This matches the
behaviour if select(2) is used instead of poll(2): select(2) returns -1 and
EBADF for an already closed file descriptor.

I believe this fix both is safe and will handle any similar error. POSIX says
that the only bits poll is permitted to set in revents are those bits that were
set in events, plus POLLHUP, POLLERR, and POLLNVAL. So if we see any flags we
didn't ask for then something has gone wrong.

Patch inspired by earlier proposals from Peter Hutterer and Aaron
Plattner--thanks!

Reported-by: Peter Hutterer <peter.hutterer@who-t.net>
Reported-by: Aaron Plattner <aplattner@nvidia.com>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
Reviewed-by: Aaron Plattner <aplattner@nvidia.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Tested-by: Aaron Plattner <aplattner@nvidia.com>
Cc: Peter Hutterer <peter.hutterer@who-t.net>
Cc: Dan Nicholson <dbn.lists@gmail.com>
Signed-off-by: Peter Harris <pharris@opentext.com>
2010-09-04 13:39:38 -04:00
Peter Harris 20da10490f Merge branch 'master' of git://github.com/topcat/xcb-win32
Conflicts:
	src/xcb_conn.c
	src/xcb_util.c

Signed-off-by: Peter Harris <pharris@opentext.com>
2010-08-31 18:35:20 -04:00
Aaron Plattner 7f5cfcc2fd xcb_disconnect: call shutdown() to force a disconnect
Fixes the X Test Suite's XCloseDisplay-6 test, which has this (admittedly
ridiculous) behavior:

 1. Create a window w.
 2. Open two display connections, dpy1, and dpy2.
 3. Grab the server using dpy1.
 4. Fork.
 5 (child). XSetProperty on w using dpy2.
 5 (parent). Verify that no event was recieved on dpy1.
 6 (parent). XCloseDisplay(dpy1).
 6 (child). Verify that an event was received on dpy2.

It was failing because at step 6 (child), the server had not actually ungrabbed
yet because the file descriptor for dpy1 was still open in the child process.

Shutting down the socket during XCloseDisplay matches the behavior of non-XCB
Xlib, which calls shutdown() from _X11TransSocketDisconnect.

Thanks to Julien Cristau for noticing this.

Signed-off-by: Aaron Plattner <aplattner at nvidia.com>
Reviewed-by: Julien Cristau <jcristau@debian.org>
Signed-off-by: Peter Harris <pharris@opentext.com>
2010-08-25 21:40:52 -04:00
Jamey Sharp 2040f10a4e xcb_request_check: Sync even if an event was read for this sequence.
This fixes the test case I have so far for Havoc's report that
xcb_request_check hangs.

Rationale: Since we have a void cookie, request_expected can't have been
set equal to this sequence number when the request was sent; it can only
have become equal due to the arrival of an event or error. If it became
equal due to an event then we still need to sync. If it became equal due
to an error, then request_completed will have been updated, which means
we correctly won't sync.

Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=29599

However, Havoc reports that he can still reproduce the problem, so we
may be revisiting this later.

Reported-by: Havoc Pennington <hp@pobox.com>
Signed-off-by: Jamey Sharp <jamey@minilop.net>
2010-08-24 09:29:59 -07:00
Christoph Reimann 5e8a7ade2d small fix to get rid of some compiler warnings
also added very basic documentation for xkb
2010-08-16 20:24:40 +02:00
Christoph Reimann b89f634ff9 small fix in the xkb pkg file 2010-08-16 18:22:42 +02:00
Christoph Reimann 22e1013131 added accessors for special cases
major bugfixes include: rewrite of prefix related functions, merge of serialize/unserialize/... generators, extended field name resolution
2010-08-16 18:19:16 +02:00
Julien Danjou 35f901a0f2 Release libxcb 1.7
Signed-off-by: Julien Danjou <julien@danjou.info>
2010-08-13 13:46:37 +02:00
Christoph Reimann fe0e32b5fa special case 'intermixed variable and fixed size fields': fixed reply side, needs testing 2010-08-08 21:25:13 +02:00
Christoph Reimann 77b594f958 renamed most _unserialize() functions to _sizeof() and fixed _unserialize() for the special case of intermixed variable and fixed size fields 2010-08-05 15:55:28 +02:00
Eamon Walsh dd1a4dbe20 Tutorial uses wrong function.
https://bugs.freedesktop.org/show_bug.cgi?id=29392

Signed-off-by: Eamon Walsh <efw@eamonwalsh.com>
2010-08-05 00:50:22 -04:00