From b007b542df5cf6388340a81ad812473dcf8c616d Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Tue, 11 Jul 2017 21:29:59 +0200 Subject: pass filename as parameter to nxagentProcessOptionsFile() Do not use global variables where it is not necessary. --- nx-X11/programs/Xserver/hw/nxagent/Args.c | 28 +++++++++++++------------- nx-X11/programs/Xserver/hw/nxagent/Args.h | 2 +- nx-X11/programs/Xserver/hw/nxagent/Reconnect.c | 4 +++- 3 files changed, 18 insertions(+), 16 deletions(-) (limited to 'nx-X11/programs/Xserver') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index 5c908e80b..cc9ec8523 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -1569,7 +1569,7 @@ static void nxagentParseOptionString(char *string) } } -void nxagentProcessOptionsFile() +void nxagentProcessOptionsFile(char * filename) { FILE *file; char *data; @@ -1581,8 +1581,8 @@ void nxagentProcessOptionsFile() int maxFileSize = 1024; #ifdef DEBUG - fprintf(stderr, "nxagentProcessOptionsFile: Going to process option the file [%s].\n", - validateString(nxagentOptionFile)); + fprintf(stderr, "nxagentProcessOptionsFile: Going to process option file [%s].\n", + validateString(filename); #endif /* @@ -1590,15 +1590,15 @@ void nxagentProcessOptionsFile() */ setStatePath(""); - if (nxagentOptionFile == NULL) + if (filename == NULL) { return; } - if ((file = fopen(nxagentOptionFile, "r")) == NULL) + if ((file = fopen(filename, "r")) == NULL) { fprintf(stderr, "Warning: Couldn't open option file '%s'. Error is '%s'.\n", - validateString(nxagentOptionFile), strerror(errno)); + validateString(filename), strerror(errno)); goto nxagentProcessOptionsFileExit; } @@ -1606,7 +1606,7 @@ void nxagentProcessOptionsFile() if (fseek(file, 0, SEEK_END) != 0) { fprintf(stderr, "Warning: Couldn't position inside option file '%s'. Error is '%s'.\n", - validateString(nxagentOptionFile), strerror(errno)); + validateString(filename), strerror(errno)); goto nxagentProcessOptionsFileClose; } @@ -1614,14 +1614,14 @@ void nxagentProcessOptionsFile() if ((sizeOfFile = ftell(file)) == -1) { fprintf(stderr, "Warning: Couldn't get the size of option file '%s'. Error is '%s'.\n", - validateString(nxagentOptionFile), strerror(errno)); + validateString(filename), strerror(errno)); goto nxagentProcessOptionsFileClose; } #ifdef DEBUG fprintf(stderr, "nxagentProcessOptionsFile: Processing option file [%s].\n", - validateString(nxagentOptionFile)); + validateString(filename)); #endif rewind(file); @@ -1629,7 +1629,7 @@ void nxagentProcessOptionsFile() if (sizeOfFile > maxFileSize) { fprintf(stderr, "Warning: Maximum file size exceeded for options '%s'.\n", - validateString(nxagentOptionFile)); + validateString(filename)); goto nxagentProcessOptionsFileClose; } @@ -1637,7 +1637,7 @@ void nxagentProcessOptionsFile() if ((data = malloc(sizeOfFile + 1)) == NULL) { fprintf(stderr, "Warning: Memory allocation failed processing file '%s'.\n", - validateString(nxagentOptionFile)); + validateString(filename)); goto nxagentProcessOptionsFileClose; } @@ -1652,7 +1652,7 @@ void nxagentProcessOptionsFile() if (ferror(file) != 0) { fprintf(stderr, "Warning: Error reading the option file '%s'.\n", - validateString(nxagentOptionFile)); + validateString(filename)); goto nxagentProcessOptionsFileFree; } @@ -1669,7 +1669,7 @@ void nxagentProcessOptionsFile() if (size != sizeOfFile) { fprintf(stderr, "Warning: Premature end of option file '%s' while reading.\n", - validateString(nxagentOptionFile)); + validateString(filename)); goto nxagentProcessOptionsFileFree; } @@ -1696,7 +1696,7 @@ nxagentProcessOptionsFileClose: if (fclose(file) != 0) { fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n", - validateString(nxagentOptionFile), strerror(errno)); + validateString(filename), strerror(errno)); } nxagentProcessOptionsFileExit: diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.h b/nx-X11/programs/Xserver/hw/nxagent/Args.h index 09d045514..4c736ea9f 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.h +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.h @@ -81,7 +81,7 @@ extern Bool nxagentIpaq; extern int nxagentLockDeferLevel; Bool nxagentPostProcessArgs(char *name, Display *dpy, Screen *scr); -void nxagentProcessOptionsFile(void); +void nxagentProcessOptionsFile(char * filename); void nxagentSetPackMethod(void); void nxagentSetDeferLevel(void); diff --git a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c index fb2303549..937bd1eff 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c @@ -103,6 +103,8 @@ extern Bool nxagentRenderEnable; extern char *nxagentKeyboard; +extern char *nxagentOptionFile; + enum SESSION_STATE nxagentSessionState = SESSION_STARTING; struct nxagentExceptionStruct nxagentException = {0, 0}; @@ -454,7 +456,7 @@ Bool nxagentReconnectSession(void) nxagentResetOptions(); - nxagentProcessOptionsFile(); + nxagentProcessOptionsFile(nxagentOptionFile); if (nxagentReconnectDisplay(reconnectLossyLevel[DISPLAY_STEP]) == 0) { -- cgit v1.2.3 From 36e583cf52a0a19183bdee69431c306d8e7df5b7 Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 24 Jul 2017 23:45:24 +0200 Subject: rename nxagentOptionFile to nxagentOptionsFilename --- nx-X11/programs/Xserver/hw/nxagent/Args.c | 26 +++++++++++++------------- nx-X11/programs/Xserver/hw/nxagent/Reconnect.c | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'nx-X11/programs/Xserver') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index cc9ec8523..d5cbfbce3 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -135,7 +135,7 @@ char nxagentShadowDisplayName[1024] = {0}; char nxagentWindowName[256]; char nxagentDialogName[256]; char nxagentSessionId[256] = {0}; -char *nxagentOptionFile; +char *nxagentOptionsFilename; Bool nxagentFullGeneration = False; int nxagentDefaultClass = TrueColor; @@ -259,18 +259,18 @@ int ddxProcessArgument(int argc, char *argv[], int i) { if ((!strcmp(argv[j], "-options") || !strcmp(argv[j], "-option")) && j + 1 < argc) { - if (nxagentOptionFile) + if (nxagentOptionsFilename) { - nxagentOptionFile = (char *) realloc(nxagentOptionFile, strlen(argv[j + 1]) + 1); + nxagentOptionsFilename = (char *) realloc(nxagentOptionsFilename, strlen(argv[j + 1]) + 1); } else { - nxagentOptionFile = (char *) malloc(strlen(argv[j + 1]) +1); + nxagentOptionsFilename = (char *) malloc(strlen(argv[j + 1]) +1); } - if (nxagentOptionFile != NULL) + if (nxagentOptionsFilename != NULL) { - nxagentOptionFile = strcpy(nxagentOptionFile, argv[j + 1]); + nxagentOptionsFilename = strcpy(nxagentOptionsFilename, argv[j + 1]); } #ifdef WARNING else @@ -283,7 +283,7 @@ int ddxProcessArgument(int argc, char *argv[], int i) } } - if (nxagentOptionFile) + if (nxagentOptionsFilename) { nxagentProcessOptionsFile(); } @@ -365,23 +365,23 @@ int ddxProcessArgument(int argc, char *argv[], int i) { int size; - if (nxagentOptionFile != NULL) + if (nxagentOptionsFilename != NULL) { - free(nxagentOptionFile); + free(nxagentOptionsFilename); - nxagentOptionFile = NULL; + nxagentOptionsFilename = NULL; } if ((size = strlen(argv[i])) < 1024) { - if ((nxagentOptionFile = malloc(size + 1)) == NULL) + if ((nxagentOptionsFilename = malloc(size + 1)) == NULL) { FatalError("malloc failed"); } - strncpy(nxagentOptionFile, argv[i], size); + strncpy(nxagentOptionsFilename, argv[i], size); - nxagentOptionFile[size] = '\0'; + nxagentOptionsFilename[size] = '\0'; } else { diff --git a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c index 937bd1eff..902fe36be 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Reconnect.c @@ -103,7 +103,7 @@ extern Bool nxagentRenderEnable; extern char *nxagentKeyboard; -extern char *nxagentOptionFile; +extern char *nxagentOptionsFilename; enum SESSION_STATE nxagentSessionState = SESSION_STARTING; @@ -456,7 +456,7 @@ Bool nxagentReconnectSession(void) nxagentResetOptions(); - nxagentProcessOptionsFile(nxagentOptionFile); + nxagentProcessOptionsFile(nxagentOptionsFilename); if (nxagentReconnectDisplay(reconnectLossyLevel[DISPLAY_STEP]) == 0) { -- cgit v1.2.3 From 3f7b3001988bf921e6cd860f03a6256b1451ee3d Mon Sep 17 00:00:00 2001 From: Ulrich Sibiller Date: Mon, 24 Jul 2017 23:45:48 +0200 Subject: treat options parameter as option string if it starts with nx/nx This way one can easily pass options to nxagent run as Xnest replacement without having to create a temporary options file. Please note that it is not of much use for normal sessions. Options passed like this cannot be changed after startup so a reconnect may not work as expected. Fixes ArcticaProject/nx-libs#476 --- nx-X11/programs/Xserver/hw/nxagent/Args.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'nx-X11/programs/Xserver') diff --git a/nx-X11/programs/Xserver/hw/nxagent/Args.c b/nx-X11/programs/Xserver/hw/nxagent/Args.c index d5cbfbce3..e4fa350bc 100644 --- a/nx-X11/programs/Xserver/hw/nxagent/Args.c +++ b/nx-X11/programs/Xserver/hw/nxagent/Args.c @@ -285,7 +285,22 @@ int ddxProcessArgument(int argc, char *argv[], int i) if (nxagentOptionsFilename) { - nxagentProcessOptionsFile(); + /* if the "filename" starts with an nx marker treat it + as an option _string_ instead of a filename */ + if (strncasecmp(nxagentOptionsFilename, "nx/nx,", 6) == 0 || + strncasecmp(nxagentOptionsFilename, "nx/nx:", 6) == 0) + { + nxagentParseOptionString(nxagentOptionsFilename + 6); + } + else if (strncasecmp(nxagentOptionsFilename, "nx,", 3) == 0 || + strncasecmp(nxagentOptionsFilename, "nx:", 3) == 0) + { + nxagentParseOptionString(nxagentOptionsFilename + 3); + } + else + { + nxagentProcessOptionsFile(nxagentOptionsFilename); + } } } -- cgit v1.2.3