From bff0c590e5e857d3ce06d454f260d4263e10cc05 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 10 Sep 2021 10:38:30 +0100 Subject: [PATCH] Unix platform_make_x11_server: fix sense of error check. Analogous to the bug I just fixed in xtruss: in the loop that tries to find a reasonable port number for an X display, the sense of the (horrible) strcmp distinguishing EADDRINUSE from other socket errors was backwards. --- unix/x11.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/unix/x11.c b/unix/x11.c index 7a0c2218..f30dcfbf 100644 --- a/unix/x11.c +++ b/unix/x11.c @@ -88,7 +88,20 @@ int platform_make_x11_server(Plug *plug, const char *progname, int mindisp, sk_close(sockets[nsockets]); } - if (!strcmp(err, strerror(EADDRINUSE))) /* yuck! */ + /* + * If we weren't able to bind to this port because it's in use + * by another program, go round this loop and try again. But + * for any other reason, give up completely and return failure + * to our caller. + * + * sk_socket_error currently has no machine-readable component + * (it would need a cross-platform abstraction of the socket + * error types we care about, plus translation from each OS + * error enumeration into that). So we use the disgusting + * approach of a string compare between the error string and + * the one EADDRINUSE would have given :-( + */ + if (strcmp(err, strerror(EADDRINUSE))) goto out; }