-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add xrdp-waitforx to wait for X to start with RandR outputs #2492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,101 @@ | ||
| #include <X11/extensions/Xrandr.h> | ||
| #include <signal.h> | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <sys/signal.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include "config_ac.h" | ||
| #include "os_calls.h" | ||
| #include "string_calls.h" | ||
|
|
||
| #define ATTEMPTS 10 | ||
| #define ALARM_WAIT 30 | ||
|
|
||
| void | ||
| alarm_handler(int signal_num) | ||
| { | ||
| /* Avoid printf() in signal handler (see signal-safety(7)) */ | ||
| const char msg[] = "Timed out waiting for RandR outputs\n"; | ||
| g_file_write(1, msg, g_strlen(msg)); | ||
| 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"); | ||
|
|
||
| g_set_alarm(alarm_handler, 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; | ||
| } | ||
| g_sleep(1000); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
| g_sleep(1000); | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
printfhere raises an interesting question about some of the wrapper functions incommon/os_calls.h.Other bits of xrdp using
printf()rather thang_printf()Personally I can't see that we gain anything by using
g_printf()overprintf(). I think we should (over time) be removing the wrappers for standard C functions and simply use the<stdio.h>(etc) includes.@metalefty - what's your take on this? Should we start a discussion?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding
printf(), I personally think I would like to quit using wrapper function and useprintf()directly.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll start a discussion about this.