Skip to content

Commit 3b640a0

Browse files
committed
Merge branch 'uli42-pr/options_on_reconnect' into 3.6.x
Attributes GH PR #554: #554
2 parents 39d45a0 + 4ef4fbf commit 3b640a0

File tree

3 files changed

+60
-57
lines changed

3 files changed

+60
-57
lines changed

nx-X11/programs/Xserver/hw/nxagent/Args.c

Lines changed: 57 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ char nxagentShadowDisplayName[1024] = {0};
135135
char nxagentWindowName[256];
136136
char nxagentDialogName[256];
137137
char nxagentSessionId[256] = {0};
138-
char *nxagentOptionsFilename;
138+
char *nxagentOptionsFilenameOrString;
139139

140140
Bool nxagentFullGeneration = False;
141141
int nxagentDefaultClass = TrueColor;
@@ -259,18 +259,18 @@ int ddxProcessArgument(int argc, char *argv[], int i)
259259
{
260260
if ((!strcmp(argv[j], "-options") || !strcmp(argv[j], "-option")) && j + 1 < argc)
261261
{
262-
if (nxagentOptionsFilename)
262+
if (nxagentOptionsFilenameOrString)
263263
{
264-
nxagentOptionsFilename = (char *) realloc(nxagentOptionsFilename, strlen(argv[j + 1]) + 1);
264+
nxagentOptionsFilenameOrString = (char *) realloc(nxagentOptionsFilenameOrString, strlen(argv[j + 1]) + 1);
265265
}
266266
else
267267
{
268-
nxagentOptionsFilename = (char *) malloc(strlen(argv[j + 1]) +1);
268+
nxagentOptionsFilenameOrString = (char *) malloc(strlen(argv[j + 1]) +1);
269269
}
270270

271-
if (nxagentOptionsFilename != NULL)
271+
if (nxagentOptionsFilenameOrString != NULL)
272272
{
273-
nxagentOptionsFilename = strcpy(nxagentOptionsFilename, argv[j + 1]);
273+
nxagentOptionsFilenameOrString = strcpy(nxagentOptionsFilenameOrString, argv[j + 1]);
274274
}
275275
#ifdef WARNING
276276
else
@@ -283,25 +283,7 @@ int ddxProcessArgument(int argc, char *argv[], int i)
283283
}
284284
}
285285

286-
if (nxagentOptionsFilename)
287-
{
288-
/* if the "filename" starts with an nx marker treat it
289-
as an option _string_ instead of a filename */
290-
if (strncasecmp(nxagentOptionsFilename, "nx/nx,", 6) == 0 ||
291-
strncasecmp(nxagentOptionsFilename, "nx/nx:", 6) == 0)
292-
{
293-
nxagentParseOptionString(nxagentOptionsFilename + 6);
294-
}
295-
else if (strncasecmp(nxagentOptionsFilename, "nx,", 3) == 0 ||
296-
strncasecmp(nxagentOptionsFilename, "nx:", 3) == 0)
297-
{
298-
nxagentParseOptionString(nxagentOptionsFilename + 3);
299-
}
300-
else
301-
{
302-
nxagentProcessOptionsFile(nxagentOptionsFilename);
303-
}
304-
}
286+
nxagentProcessOptions(nxagentOptionsFilenameOrString);
305287
}
306288

307289
if (!strcmp(argv[i], "-B"))
@@ -380,23 +362,19 @@ int ddxProcessArgument(int argc, char *argv[], int i)
380362
{
381363
int size;
382364

383-
if (nxagentOptionsFilename != NULL)
384-
{
385-
free(nxagentOptionsFilename);
386-
387-
nxagentOptionsFilename = NULL;
388-
}
365+
free(nxagentOptionsFilenameOrString);
366+
nxagentOptionsFilenameOrString = NULL;
389367

390368
if ((size = strlen(argv[i])) < 1024)
391369
{
392-
if ((nxagentOptionsFilename = malloc(size + 1)) == NULL)
370+
if ((nxagentOptionsFilenameOrString = malloc(size + 1)) == NULL)
393371
{
394372
FatalError("malloc failed");
395373
}
396374

397-
strncpy(nxagentOptionsFilename, argv[i], size);
375+
strncpy(nxagentOptionsFilenameOrString, argv[i], size);
398376

399-
nxagentOptionsFilename[size] = '\0';
377+
nxagentOptionsFilenameOrString[size] = '\0';
400378
}
401379
else
402380
{
@@ -1584,10 +1562,38 @@ static void nxagentParseOptionString(char *string)
15841562
}
15851563
}
15861564

1565+
void nxagentProcessOptions(char * string)
1566+
{
1567+
if (!string)
1568+
return;
1569+
1570+
#ifdef DEBUG
1571+
fprintf(stderr, "%s: Going to process option string/filename [%s].\n",
1572+
__func__, validateString(string));
1573+
#endif
1574+
1575+
/* if the "filename" starts with an nx marker treat it
1576+
as an option _string_ instead of a filename */
1577+
if (strncasecmp(string, "nx/nx,", 6) == 0 ||
1578+
strncasecmp(string, "nx/nx:", 6) == 0)
1579+
{
1580+
nxagentParseOptionString(string + 6);
1581+
}
1582+
else if (strncasecmp(string, "nx,", 3) == 0 ||
1583+
strncasecmp(string, "nx:", 3) == 0)
1584+
{
1585+
nxagentParseOptionString(string + 3);
1586+
}
1587+
else
1588+
{
1589+
nxagentProcessOptionsFile(string);
1590+
}
1591+
}
1592+
15871593
void nxagentProcessOptionsFile(char * filename)
15881594
{
1589-
FILE *file;
1590-
char *data;
1595+
FILE *file = NULL;
1596+
char *data = NULL;
15911597

15921598
int offset;
15931599
int size;
@@ -1597,7 +1603,7 @@ void nxagentProcessOptionsFile(char * filename)
15971603

15981604
#ifdef DEBUG
15991605
fprintf(stderr, "nxagentProcessOptionsFile: Going to process option file [%s].\n",
1600-
validateString(filename);
1606+
validateString(filename));
16011607
#endif
16021608

16031609
/*
@@ -1623,15 +1629,15 @@ void nxagentProcessOptionsFile(char * filename)
16231629
fprintf(stderr, "Warning: Couldn't position inside option file '%s'. Error is '%s'.\n",
16241630
validateString(filename), strerror(errno));
16251631

1626-
goto nxagentProcessOptionsFileClose;
1632+
goto nxagentProcessOptionsFileExit;
16271633
}
16281634

16291635
if ((sizeOfFile = ftell(file)) == -1)
16301636
{
16311637
fprintf(stderr, "Warning: Couldn't get the size of option file '%s'. Error is '%s'.\n",
16321638
validateString(filename), strerror(errno));
16331639

1634-
goto nxagentProcessOptionsFileClose;
1640+
goto nxagentProcessOptionsFileExit;
16351641
}
16361642

16371643
#ifdef DEBUG
@@ -1646,15 +1652,15 @@ void nxagentProcessOptionsFile(char * filename)
16461652
fprintf(stderr, "Warning: Maximum file size exceeded for options '%s'.\n",
16471653
validateString(filename));
16481654

1649-
goto nxagentProcessOptionsFileClose;
1655+
goto nxagentProcessOptionsFileExit;
16501656
}
16511657

16521658
if ((data = malloc(sizeOfFile + 1)) == NULL)
16531659
{
16541660
fprintf(stderr, "Warning: Memory allocation failed processing file '%s'.\n",
16551661
validateString(filename));
16561662

1657-
goto nxagentProcessOptionsFileClose;
1663+
goto nxagentProcessOptionsFileExit;
16581664
}
16591665

16601666
offset = 0;
@@ -1669,7 +1675,7 @@ void nxagentProcessOptionsFile(char * filename)
16691675
fprintf(stderr, "Warning: Error reading the option file '%s'.\n",
16701676
validateString(filename));
16711677

1672-
goto nxagentProcessOptionsFileFree;
1678+
goto nxagentProcessOptionsFileExit;
16731679
}
16741680

16751681
size += result;
@@ -1686,7 +1692,7 @@ void nxagentProcessOptionsFile(char * filename)
16861692
fprintf(stderr, "Warning: Premature end of option file '%s' while reading.\n",
16871693
validateString(filename));
16881694

1689-
goto nxagentProcessOptionsFileFree;
1695+
goto nxagentProcessOptionsFileExit;
16901696
}
16911697

16921698
/*
@@ -1699,23 +1705,19 @@ void nxagentProcessOptionsFile(char * filename)
16991705

17001706
nxagentParseOptionString(data);
17011707

1702-
nxagentProcessOptionsFileFree:
1703-
1704-
if (data != NULL)
1705-
{
1706-
free(data);
1707-
}
1708+
nxagentProcessOptionsFileExit:
17081709

1709-
nxagentProcessOptionsFileClose:
1710+
free(data);
17101711

1711-
if (fclose(file) != 0)
1712+
if (file)
17121713
{
1713-
fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n",
1714-
validateString(filename), strerror(errno));
1714+
if (fclose(file) != 0)
1715+
{
1716+
fprintf(stderr, "Warning: Couldn't close option file '%s'. Error is '%s'.\n",
1717+
validateString(filename), strerror(errno));
1718+
}
17151719
}
17161720

1717-
nxagentProcessOptionsFileExit:
1718-
17191721
return;
17201722
}
17211723

nx-X11/programs/Xserver/hw/nxagent/Args.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern Bool nxagentIpaq;
8181
extern int nxagentLockDeferLevel;
8282

8383
Bool nxagentPostProcessArgs(char *name, Display *dpy, Screen *scr);
84+
void nxagentProcessOptions(char * string);
8485
void nxagentProcessOptionsFile(char * filename);
8586

8687
void nxagentSetPackMethod(void);

nx-X11/programs/Xserver/hw/nxagent/Reconnect.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ extern Bool nxagentRenderEnable;
103103

104104
extern char *nxagentKeyboard;
105105

106-
extern char *nxagentOptionsFilename;
106+
extern char *nxagentOptionsFilenameOrString;
107107

108108
enum SESSION_STATE nxagentSessionState = SESSION_STARTING;
109109

@@ -456,7 +456,7 @@ Bool nxagentReconnectSession(void)
456456

457457
nxagentResetOptions();
458458

459-
nxagentProcessOptionsFile(nxagentOptionsFilename);
459+
nxagentProcessOptions(nxagentOptionsFilenameOrString);
460460

461461
if (nxagentReconnectDisplay(reconnectLossyLevel[DISPLAY_STEP]) == 0)
462462
{

0 commit comments

Comments
 (0)