http8086
http8086

Reputation: 1736

recvfrom for X11-unix socket is throwing EAGAIN (Resource temporarily unavailable)

I want to capture web page by pywebkitgtk. I have installed the X org server on that machine, started the X server with some exceptions, but the X server is running. Issue is I'm not able to read any data from the X unix socket, which is PF_FILE type with path=@"/tmp/.X11-unix/X0", recvfrom is throwing EAGAIN (Resource temporarily unavailable) error, polling against that socket constantly time out without any coming data, below is the trace log, in which we can find successfully created unix socket with fd 5, connected unix socket, succeed so far, but failed to read anything from that unix socket.

developer@kernel: /data/play/null> strace python ../pywebkitgtk-1.1.8/demos/browser.py

socket(PF_FILE, SOCK_STREAM|SOCK_CLOEXEC, 0) = 5
connect(5, {sa_family=AF_FILE, path=@"/tmp/.X11-unix/X0"}, 20) = 0
getpeername(5, {sa_family=AF_FILE, path=@"/tmp/.X11-unix/X0"}, [20]) = 0


...........................


recvfrom(5, "\1\3\304\1\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096, 0, NULL, NULL) = 32
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"\220\10\7\0\0\1G\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \1", 28}, {NULL, 0}, {"", 0}], 3) = 28
poll([{fd=5, events=POLLIN}], 1, -1)    = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\1\3\305\1X\4\0\0\0\0\10\377G\0\0\31\31\0104\1\370\0\0\0\0\0\0\0\0\0\0\10"..., 4096, 0, NULL, NULL) = 4096
recvfrom(5, "\216\377\10\20\0\0\0\0\1\1\1\0\33\377\10\20\0\0\0\0\1\1\1\0_\377\10\20\0\0\0\0"..., 384, 0, NULL, NULL) = 384
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"\220\21\3\0\3\0G\0\0\30\0\0", 12}, {NULL, 0}, {"", 0}], 3) = 12
poll([{fd=5, events=POLLIN}], 1, -1)    = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\1\3\306\1\16\0\0\0\0\30\0\0\10\377\31\1\377\37\10\370\0\0\0\0\0\0\0\0\0\0\0\0"..., 4096, 0, NULL, NULL) = 88
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"\20\0\3\0\4\0G\0Meta", 12}, {NULL, 0}, {"", 0}], 3) = 12
poll([{fd=5, events=POLLIN}], 1, -1)    = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\1\0\307\1\0\0\0\0\206\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096, 0, NULL, NULL) = 32
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"\20\0\4\0\5\0G\0Super\0\0\0", 16}, {NULL, 0}, {"", 0}], 3) = 16
poll([{fd=5, events=POLLIN}], 1, -1)    = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\1\0\310\1\0\0\0\0\207\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096, 0, NULL, NULL) = 32
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"\20\0\4\0\5\0G\0Hyper\0\0\0", 16}, {NULL, 0}, {"", 0}], 3) = 16
poll([{fd=5, events=POLLIN}], 1, -1)    = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\1\0\311\1\0\0\0\0\210\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096, 0, NULL, NULL) = 32
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{";\3\5\0\16\0 \1\0\0\0\0\3\0\3\0\316\2\22\0008\0\5\0\16\0 \1\0000\0\0"..., 16384}, {NULL, 0}, {"", 0}], 3) = 16384
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"6\3\2\0f\0 \1", 8}, {NULL, 0}, {"", 0}], 3) = 8
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=6, events=POLLIN}, {fd=5, events=POLLIN}], 2, 0) = 0 (Timeout)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=6, events=POLLIN}, {fd=5, events=POLLIN}], 2, 0) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"5\30\4\0\200\0 \1\3\0 \1\316\2\22\0\223\4\5\0\201\0 \1\200\0 \1)\0\0\0"..., 296}, {NULL, 0}, {"", 0}], 3) = 296
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=6, events=POLLIN}, {fd=5, events=POLLIN}], 2, 497) = 0 (Timeout)
poll([{fd=5, events=POLLIN|POLLOUT}], 1, -1) = 1 ([{fd=5, revents=POLLOUT}])
writev(5, [{"(\30\4\0\3\0 \1\1\1\0\0\0\0\0\0", 16}, {NULL, 0}, {"", 0}], 3) = 16
poll([{fd=5, events=POLLIN}], 1, -1)    = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "\1\1#\2\0\0\0\0\250\3\300\0o\0N\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 4096, 0, NULL, NULL) = 32
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)
poll([{fd=6, events=POLLIN}, {fd=5, events=POLLIN}], 2, 4498) = 0 (Timeout)
futex(0x7f2d8af5ea9c, FUTEX_WAKE_OP_PRIVATE, 1, 1, 0x7f2d8af5ea98, {FUTEX_OP_SET, 0, FUTEX_OP_CMP_GT, 1}) = 1
recvfrom(5, 0x25ff6c4, 4096, 0, 0, 0)   = -1 EAGAIN (Resource temporarily unavailable)

Upvotes: 0

Views: 3587

Answers (2)

alanc
alanc

Reputation: 4180

Have you sent X11 protocol requests on the Unix socket that you’re expecting replies from? After the initial X11 protocol handshake, you won’t get anything from the X server until you request it - either via a request that returns an immediate response or one that registers you for later events.

The X11 protocol is complex enough that trying to write your own code to connect to it is a far larger task than anyone should do - you should use the libxcb or libX11 libraries to handle the protocol for you, and a higher level toolkit such as GTK or Qt to handle most of the widgets and user interface.

Upvotes: 0

Nikolai Fetissov
Nikolai Fetissov

Reputation: 84239

Somewhere in the .... part the socket was marked as non-blocking, so getting EAGAIN (which is the same errno(3) value as EWOULDBLOCK, btw) is totally normal - it means there's no data to consume at that particular moment.

Then your trace does show that you do get data from the socket every time after poll(2) with revents=POLLIN, so I don't see anything wrong here. Maybe just the fact that the unsuccessful read is always repeated twice, but that's not a real issue, just inefficiency (or maybe the other way around - some very clever trick).

Upvotes: 2

Related Questions