waitforx changes

1) Changed alarm message from "Timed out waiting for RandR outputs" to
   "Timed out waiting for X display". The former was confusing, and the
   times where this message was triggered were nothing to do with
   RandR
2) Don't try to open a display of the form ":n" directory (n >= 0).
   If the X server hasn't yet opened its local socket, the
   XOpenDisplay() call can go to the network and possibly block
   for a long time. Instead, use the (undocumented) "unix:n" display
   specification, whih never goes to the network, and doesn't block.
This commit is contained in:
matt335672 2024-11-04 16:22:01 +00:00
parent 514c62c7c1
commit d037a76471

View File

@ -2,6 +2,7 @@
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/signal.h>
#include <unistd.h>
@ -21,11 +22,32 @@ alarm_handler(int signal_num)
*
* Prefix the message with a newline in case another message
* has been partly output */
const char msg[] = "\n<E>Timed out waiting for RandR outputs\n";
const char msg[] = "\n<E>Timed out waiting for X display\n";
g_file_write(1, msg, g_strlen(msg));
exit(XW_STATUS_TIMED_OUT);
}
/*****************************************************************************/
/***
* Checks display is of the form ':n' where 'n' is an unsigned number
* @param display Display string
* @return boolean
*/
static int
is_local_display(const char *display)
{
int result = 0;
if (display != NULL && *display++ == ':')
{
while (isdigit(*display))
{
++display;
}
result = (*display == '\0');
}
return result;
}
/*****************************************************************************/
static Display *
open_display(const char *display)
@ -34,6 +56,23 @@ open_display(const char *display)
unsigned int wait = ATTEMPTS;
unsigned int n;
if (is_local_display(display))
{
// Don't use the raw display value, as this goes to the
// network if the X server port is not yet open. This can
// block if the network is configured in an unexpected way,
// which leads to use failing to detect the X server starting
// up shortly after.
//
// This code attempts to use a string such as "unix:10" to open
// the display. This is undocumented in the X11 man pages but
// is implemented in _xcb_open() from libxcb
// (which libX11 is now layered on).
char unix_display[64];
snprintf(unix_display, sizeof(unix_display), "unix%s", display);
return open_display(unix_display);
}
for (n = 1; n <= ATTEMPTS; ++n)
{
printf("<D>Opening display %s. Attempt %u of %u\n", display, n, wait);