forked from neutrinolabs/xrdp
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add xrdp-waitforx to wait for X to start with RandR outputs
For some window managers (fvwm2 and fvwm3) if the X server isn't running and has output it's possible for the window manager to fail or reconfigure randr incorrectly. With xrdp-waitfox: - Install xrdp-waitfox to the BIN dir. - sesman will run xrdp-waitfox as the logged in user. - Set an alarm to exit after 30 seconds. - Try to open env DISPLAY value's display (10 seconds). - Test for RandR extension. - Wait for outputs to appear (10 seconds).
- Loading branch information
1 parent
9150d69
commit 5875f39
Showing
8 changed files
with
186 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ SUBDIRS = \ | |
xrdp \ | ||
fontutils \ | ||
keygen \ | ||
waitforx \ | ||
docs \ | ||
instfiles \ | ||
genkeymap \ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#if defined(HAVE_CONFIG_H) | ||
#include "config_ac.h" | ||
#endif | ||
|
||
#include "log.h" | ||
#include "os_calls.h" | ||
#include "string_calls.h" | ||
#include "xwait.h" | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
/******************************************************************************/ | ||
int | ||
wait_for_xserver(int display) | ||
{ | ||
FILE *dp = NULL; | ||
int ret = 0; | ||
char buffer[100]; | ||
char exe_cmd[262]; | ||
|
||
LOG(LOG_LEVEL_DEBUG, "Waiting for X server to start on display %d", display); | ||
|
||
g_snprintf(exe_cmd, sizeof(exe_cmd), "%s/xrdp-waitforx", XRDP_BIN_PATH); | ||
dp = popen(exe_cmd, "r"); | ||
if (dp == NULL) | ||
{ | ||
LOG(LOG_LEVEL_ERROR, "Unable to launch xrdp-waitforx"); | ||
return 1; | ||
} | ||
|
||
while (fgets(buffer, 100, dp)) | ||
{ | ||
g_strtrim(buffer, 2); | ||
LOG(LOG_LEVEL_DEBUG, "%s", buffer); | ||
} | ||
|
||
ret = pclose(dp); | ||
if (ret != 0) | ||
{ | ||
LOG(LOG_LEVEL_ERROR, "An error occurred while running xrdp-waitforx"); | ||
return 0; | ||
} | ||
|
||
|
||
return 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef XWAIT_H | ||
#define XWAIT_H | ||
/** | ||
* | ||
* @brief waits for X to start | ||
* @param display number | ||
* @return 0 on error, 1 if X has outputs | ||
* | ||
*/ | ||
int | ||
wait_for_xserver(int display); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
bin_PROGRAMS = \ | ||
xrdp-waitforx | ||
|
||
AM_LDFLAGS = -lX11 -lXrandr | ||
AM_CFLAGS = -I$(top_srcdir)/common | ||
|
||
xrdp_waitforx_SOURCES = waitforx.c | ||
|
||
xrdp_waitforx_LDADD = \ | ||
$(top_builddir)/common/libcommon.la |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#include <X11/extensions/Xrandr.h> | ||
#include <signal.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <sys/signal.h> | ||
#include <unistd.h> | ||
|
||
#define ATTEMPTS 10 | ||
#define ALARM_WAIT 30 | ||
|
||
void | ||
alarm_handler(int signal_num) | ||
{ | ||
printf("Unable to find RandR outputs after %d seconds\n", ALARM_WAIT); | ||
exit(1); | ||
} | ||
|
||
int | ||
main(int argc, char **argv) | ||
{ | ||
char *display = NULL; | ||
int error_base = 0; | ||
int event_base = 0; | ||
int n = 0; | ||
int outputs = 0; | ||
int wait = ATTEMPTS; | ||
|
||
Display *dpy = NULL; | ||
XRRScreenResources *res = NULL; | ||
|
||
display = getenv("DISPLAY"); | ||
|
||
signal(SIGALRM, alarm_handler); | ||
alarm(ALARM_WAIT); | ||
|
||
if (!display) | ||
{ | ||
printf("DISPLAY is null"); | ||
exit(1); | ||
} | ||
|
||
for (n = 1; n <= wait; ++n) | ||
{ | ||
dpy = XOpenDisplay(display); | ||
printf("Opening display %s. Attempt %d of %d\n", display, n, wait); | ||
if (dpy != NULL) | ||
{ | ||
printf("Opened display %s\n", display); | ||
break; | ||
} | ||
sleep(1); | ||
} | ||
|
||
if (!dpy) | ||
{ | ||
printf("Unable to open display %s\n", display); | ||
exit(1); | ||
} | ||
|
||
if (!XRRQueryExtension(dpy, &event_base, &error_base)) | ||
{ | ||
printf("RandR not supported on display %s", display); | ||
} | ||
else | ||
{ | ||
for (n = 1; n <= wait; ++n) | ||
{ | ||
res = XRRGetScreenResources(dpy, DefaultRootWindow(dpy)); | ||
printf("Waiting for outputs. Attempt %d of %d\n", n, wait); | ||
if (res != NULL) | ||
{ | ||
if (res->noutput > 0) | ||
{ | ||
outputs = res->noutput; | ||
XRRFreeScreenResources(res); | ||
printf("Found %d output[s]\n", outputs); | ||
break; | ||
} | ||
XRRFreeScreenResources(res); | ||
} | ||
sleep(1); | ||
} | ||
|
||
if (outputs > 0) | ||
{ | ||
printf("display %s ready with %d outputs\n", display, res->noutput); | ||
} | ||
else | ||
{ | ||
printf("Unable to find any outputs\n"); | ||
exit(1); | ||
} | ||
} | ||
|
||
exit(0); | ||
} |