aboutsummaryrefslogtreecommitdiff
path: root/nx-X11
diff options
context:
space:
mode:
authorUlrich Sibiller <uli42@gmx.de>2019-12-29 13:26:34 +0100
committerMike Gabriel <mike.gabriel@das-netzwerkteam.de>2020-01-05 23:31:20 +0100
commitd6cc85e56c49f77f75e9bc33753e7d996d9a4b80 (patch)
tree2a404f2d90e8536357839b6b22f43c75d66cdeaf /nx-X11
parent03544b3ab661d3e26a806879be38331ff42e0030 (diff)
downloadnx-libs-d6cc85e56c49f77f75e9bc33753e7d996d9a4b80.tar.gz
nx-libs-d6cc85e56c49f77f75e9bc33753e7d996d9a4b80.tar.bz2
nx-libs-d6cc85e56c49f77f75e9bc33753e7d996d9a4b80.zip
Error.c: make nxagentHomeDir a pointer
no more hardcoded string length
Diffstat (limited to 'nx-X11')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Error.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Error.c b/nx-X11/programs/Xserver/hw/nxagent/Error.c
index a5d4426e9..14c5321d4 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Error.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Error.c
@@ -85,7 +85,7 @@ char *nxagentClientsLogName = NULL;
* User's home.
*/
-static char nxagentHomeDir[DEFAULT_STRING_LENGTH] = { 0 };
+static char *nxagentHomeDir = NULL;
/*
* NX root directory.
@@ -323,9 +323,13 @@ void nxagentEndRedirectToClientsLog(void)
nxagentCloseClientsLogFile();
}
+/*
+ * returns a pointer to the static nxagentHomeDir. The caller must not free
+ * this pointer!
+ */
char *nxagentGetHomePath(void)
{
- if (*nxagentHomeDir == '\0')
+ if (!nxagentHomeDir)
{
/*
* Check the NX_HOME environment.
@@ -336,7 +340,7 @@ char *nxagentGetHomePath(void)
if (homeEnv == NULL || *homeEnv == '\0')
{
#ifdef TEST
- fprintf(stderr, "nxagentGetHomePath: No environment for NX_HOME.\n");
+ fprintf(stderr, "%s: No environment for NX_HOME.\n", __func__);
#endif
homeEnv = getenv("HOME");
@@ -344,40 +348,31 @@ char *nxagentGetHomePath(void)
if (homeEnv == NULL || *homeEnv == '\0')
{
#ifdef PANIC
- fprintf(stderr, "nxagentGetHomePath: PANIC! No environment for HOME.\n");
+ fprintf(stderr, "%s: PANIC! No environment for HOME.\n", __func__);
#endif
return NULL;
}
}
- if (strlen(homeEnv) > DEFAULT_STRING_LENGTH - 1)
+ /* FIXME: this is currently never freed as it is thought to last
+ over the complete runtime. We should add a free call at shutdown
+ eventually... */
+ nxagentHomeDir = strdup(homeEnv);
+ if (!nxagentHomeDir)
{
#ifdef PANIC
- fprintf(stderr, "nxagentGetHomePath: PANIC! Invalid value for the NX "
- "home directory '%s'.\n", homeEnv);
+ fprintf(stderr, "%s: PANIC! Can't allocate memory for the home path.\n", __func__);
#endif
+ return NULL;
}
- snprintf(nxagentHomeDir, DEFAULT_STRING_LENGTH, "%s", homeEnv);
-
#ifdef TEST
- fprintf(stderr, "nxagentGetHomePath: Assuming NX user's home directory '%s'.\n", nxagentHomeDir);
- #endif
- }
-
- char *homePath = strdup(nxagentHomeDir);
-
- if (homePath == NULL)
- {
- #ifdef PANIC
- fprintf(stderr, "nxagentGetHomePath: PANIC! Can't allocate memory for the home path.\n");
+ fprintf(stderr, "%s: Assuming NX user's home directory '%s'.\n", __func__, nxagentHomeDir);
#endif
-
- return NULL;
}
- return homePath;
+ return nxagentHomeDir;
}
char *nxagentGetRootPath(void)
@@ -416,8 +411,6 @@ char *nxagentGetRootPath(void)
"home directory '%s'.\n", homeEnv);
#endif
- SAFE_free(homeEnv);
-
return NULL;
}
@@ -427,8 +420,6 @@ char *nxagentGetRootPath(void)
snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s/.nx", homeEnv);
- SAFE_free(homeEnv);
-
/*
* Create the NX root directory.
*/