aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernard Cafarelli <voyageur@gentoo.org>2017-02-05 23:29:41 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2017-04-07 13:49:51 +0200
commit4c2fe0d97f03e8f325bc63bbacda257f804fae7d (patch)
tree98b15bc61600407f2d1c4e60a0e1cfc7c70ec1b2
parent1441b02f05a9671b9ad8bcba551ebc004af821a2 (diff)
downloadnx-libs-4c2fe0d97f03e8f325bc63bbacda257f804fae7d.tar.gz
nx-libs-4c2fe0d97f03e8f325bc63bbacda257f804fae7d.tar.bz2
nx-libs-4c2fe0d97f03e8f325bc63bbacda257f804fae7d.zip
nxproxy: Support communication over stdin. Allow nxcl to use standard ssh instead of nxssh.
Fixes ArcticaProject/nx-libs#98.
-rw-r--r--nxproxy/Main.c77
1 files changed, 64 insertions, 13 deletions
diff --git a/nxproxy/Main.c b/nxproxy/Main.c
index ae90990d4..d9fb1ef4f 100644
--- a/nxproxy/Main.c
+++ b/nxproxy/Main.c
@@ -19,6 +19,8 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <errno.h>
+#include <limits.h>
#include "NX.h"
@@ -27,6 +29,8 @@
#undef TEST
#undef DEBUG
+extern const char *__progname;
+
/*
* Entry point when running nxproxy stand-alone.
*/
@@ -37,27 +41,74 @@ int main(int argc, const char **argv)
char *options = NULL;
+ char *nx_commfd_str = NULL;
+
options = getenv("NX_DISPLAY");
- if (NXTransParseCommandLine(argc, argv) < 0)
+ if ((nx_commfd_str = getenv("NX_COMMFD")) != NULL)
{
- NXTransCleanup();
- }
+ errno = 0;
+ unsigned long int nx_commfd = strtoul(nx_commfd_str, NULL, 10);
- if (NXTransParseEnvironment(options, 0) < 0)
- {
- NXTransCleanup();
+ if ((errno) && (0 == nx_commfd))
+ {
+ fprintf(stderr, "%s: NX_COMMFD environment variable's value [%s] is not a file descriptor number. "
+ "Aborting...\n",
+ __progname, nx_commfd_str
+ );
+ NXTransCleanup();
+ }
+ else if ((unsigned long int) INT_MAX < nx_commfd)
+ {
+ fprintf(stderr, "%s: NX_COMMFD environment variable's value [%lu] is out of range for a file descriptor number. "
+ "Aborting...\n",
+ __progname, nx_commfd);
+ NXTransCleanup();
+ }
+ else {
+ result = NXTransCreate(nx_commfd, NX_MODE_SERVER, options);
+
+ if (result != 1)
+ {
+ fprintf(stderr, "%s: NXTransCreate failed for FD#%lu\n"
+ "Aborting...",
+ __progname, nx_commfd);
+ NXTransCleanup();
+ }
+
+ }
+
+ // go into endless loop
+
+ if (result == 1)
+ {
+ while (NXTransRunning(NX_FD_ANY))
+ result = NXTransContinue(NULL);
+ }
}
+ else
+ {
- /*
- * This should not return...
- */
+ if (NXTransParseCommandLine(argc, argv) < 0)
+ {
+ NXTransCleanup();
+ }
- #ifdef TEST
- fprintf(stderr, "Main: Yielding control to NX entry point.\n");
- #endif
+ if (NXTransParseEnvironment(options, 0) < 0)
+ {
+ NXTransCleanup();
+ }
- result = NXTransProxy(NX_FD_ANY, NX_MODE_ANY, NX_DISPLAY_ANY);
+ /*
+ * This should not return...
+ */
+
+ #ifdef TEST
+ fprintf(stderr, "%s: Yielding control to NX entry point.\n", __progname);
+ #endif
+
+ result = NXTransProxy(NX_FD_ANY, NX_MODE_ANY, NX_DISPLAY_ANY);
+ }
/*
* ...So these should not be called.