diff options
author | Mihai Moldovan <ionic@ionic.de> | 2017-12-15 12:55:17 +0100 |
---|---|---|
committer | Mihai Moldovan <ionic@ionic.de> | 2017-12-15 12:55:17 +0100 |
commit | 1dad092caf01d733990648e6df64cbf964df5143 (patch) | |
tree | 39de0e643e76754a3e23ca9dd0350b8ba4f76250 /nxproxy/src/Main.c | |
parent | 6d70b9e3c47f27a166f4aacb522c5c1e49092dd9 (diff) | |
parent | 2b9025f797ee322e21077e100c2ee27c2e7fa0e0 (diff) | |
download | nx-libs-1dad092caf01d733990648e6df64cbf964df5143.tar.gz nx-libs-1dad092caf01d733990648e6df64cbf964df5143.tar.bz2 nx-libs-1dad092caf01d733990648e6df64cbf964df5143.zip |
Merge branch '3.6.x'
Diffstat (limited to 'nxproxy/src/Main.c')
-rw-r--r-- | nxproxy/src/Main.c | 121 |
1 files changed, 121 insertions, 0 deletions
diff --git a/nxproxy/src/Main.c b/nxproxy/src/Main.c new file mode 100644 index 000000000..dc4e0fd68 --- /dev/null +++ b/nxproxy/src/Main.c @@ -0,0 +1,121 @@ +/**************************************************************************/ +/* */ +/* Copyright (c) 2001, 2011 NoMachine, http://www.nomachine.com/. */ +/* */ +/* NXPROXY, NX protocol compression and NX extensions to this software */ +/* are copyright of NoMachine. Redistribution and use of the present */ +/* software is allowed according to terms specified in the file LICENSE */ +/* which comes in the source distribution. */ +/* */ +/* Check http://www.nomachine.com/licensing.html for applicability. */ +/* */ +/* NX and NoMachine are trademarks of Medialogic S.p.A. */ +/* */ +/* All rigths reserved. */ +/* */ +/**************************************************************************/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <limits.h> + +#include "NX.h" + +#define PANIC +#define WARNING +#undef TEST +#undef DEBUG + +extern const char *__progname; + +/* + * Entry point when running nxproxy stand-alone. + */ + +int main(int argc, const char **argv) +{ + int result = -1; + + char *options = NULL; + + unsigned long int nx_commfd; + char *nx_commfd_str = NULL; + + options = getenv("NX_DISPLAY"); + + if ((nx_commfd_str = getenv("NX_COMMFD")) != NULL) + { + errno = 0; + nx_commfd = strtoul(nx_commfd_str, NULL, 10); + + 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 + { + + if (NXTransParseCommandLine(argc, argv) < 0) + { + NXTransCleanup(); + } + + if (NXTransParseEnvironment(options, 0) < 0) + { + NXTransCleanup(); + } + + /* + * 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. + */ + + NXTransExit(result); + + return 0; +} |