summaryrefslogtreecommitdiffstats
path: root/xup
diff options
context:
space:
mode:
Diffstat (limited to 'xup')
-rw-r--r--xup/xup.c104
1 files changed, 104 insertions, 0 deletions
diff --git a/xup/xup.c b/xup/xup.c
index 91eb0563..a96c362c 100644
--- a/xup/xup.c
+++ b/xup/xup.c
@@ -32,6 +32,98 @@
#define LLOGLN(_level, _args) \
do { if (_level < LOG_LEVEL) { g_writeln _args ; } } while (0)
+#include <arpa/inet.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <netdb.h>
+
+/******************************************************************************/
+/**
++ *
++ * @brief checks if there's a server running on a host and port
++ * @param display the display to check
+ * @return 0 if the port is closed, 1 if it is open
+ *
+ */
+static int
+check_port_status(const char* host, const char* port)
+{
+ char text[256];
+ int x_running;
+ int sck;
+
+ struct sockaddr_in servaddr;
+ int soc = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
+
+ g_memset( &servaddr, 0, sizeof(servaddr));
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_port = htons(atoi(port));
+
+ struct hostent* hostaddr;
+ hostaddr = gethostbyname(host);
+ g_memcpy(&servaddr.sin_addr, hostaddr->h_addr, hostaddr->h_length);
+
+ int res = connect(soc, (struct sockaddr*)&servaddr, sizeof(servaddr));
+
+ close(soc);
+
+ if (res == -1)
+ {
+ // Port is closed, no server there!
+ return 0;
+ }
+ else {
+ // Port is open
+ return 1;
+ }
+}
+
+/******************************************************************************/
+/**
+ *
+ * @brief checks if there's a server running on a remote display
+ * @param display the display to check
+ * @return 0 if there isn't a display running, nonzero otherwise
+ *
+ */
+static int
+x_server_running_check_remote_port(const char* host, const char* port)
+{
+ int x_running;
+ int sck;
+
+ x_running = 0;
+ x_running += check_port_status(host, port);
+
+ return x_running;
+}
+
+/******************************************************************************/
+static int
+wait_for_remote_xserver(const char* host, const char* port)
+{
+ int i;
+
+ /* give X a bit to start */
+ /* wait up to 15 secs for x server to start */
+ i = 0;
+ while (!x_server_running_check_remote_port(host, port))
+ {
+ i++;
+ if (i > 60)
+ {
+ break;
+ }
+ g_sleep(250);
+ }
+ return 0;
+}
+
+
static int
lib_mod_process_message(struct mod *mod, struct stream *s);
@@ -164,6 +256,18 @@ lib_mod_connect(struct mod *mod)
return 1;
}
+ char text[256];
+ g_snprintf(text, 255, "allocating resources on %s, please wait...\n\r", mod->ip);
+ mod->server_msg(mod, text, 0);
+
+ // Prevent an immediate RDP exit
+ wait_for_remote_xserver(mod->ip, mod->port);
+
+ // FIXME CRITICAL
+ // Prevent an immediate RDP exit
+ // Why is this still needed even after waiting for the X11rdp server to start!?!?
+ g_sleep(5000);
+
if (g_strcmp(mod->ip, "") == 0)
{
mod->server_msg(mod, "error - no ip set", 0);