Commit d6215574 authored by Ulrich Sibiller's avatar Ulrich Sibiller

Error.c: scope improvements

parent f0742c7f
...@@ -325,16 +325,13 @@ void nxagentEndRedirectToClientsLog(void) ...@@ -325,16 +325,13 @@ void nxagentEndRedirectToClientsLog(void)
char *nxagentGetHomePath(void) char *nxagentGetHomePath(void)
{ {
char *homeEnv;
char *homePath;
if (*nxagentHomeDir == '\0') if (*nxagentHomeDir == '\0')
{ {
/* /*
* Check the NX_HOME environment. * Check the NX_HOME environment.
*/ */
homeEnv = getenv("NX_HOME"); char *homeEnv = getenv("NX_HOME");
if (homeEnv == NULL || *homeEnv == '\0') if (homeEnv == NULL || *homeEnv == '\0')
{ {
...@@ -369,7 +366,7 @@ char *nxagentGetHomePath(void) ...@@ -369,7 +366,7 @@ char *nxagentGetHomePath(void)
#endif #endif
} }
homePath = strdup(nxagentHomeDir); char *homePath = strdup(nxagentHomeDir);
if (homePath == NULL) if (homePath == NULL)
{ {
...@@ -385,19 +382,13 @@ char *nxagentGetHomePath(void) ...@@ -385,19 +382,13 @@ char *nxagentGetHomePath(void)
char *nxagentGetRootPath(void) char *nxagentGetRootPath(void)
{ {
char *rootEnv;
char *homeEnv;
char *rootPath;
struct stat dirStat;
if (*nxagentRootDir == '\0') if (*nxagentRootDir == '\0')
{ {
/* /*
* Check the NX_ROOT environment. * Check the NX_ROOT environment.
*/ */
rootEnv = getenv("NX_ROOT"); char *rootEnv = getenv("NX_ROOT");
if (rootEnv == NULL || *rootEnv == '\0') if (rootEnv == NULL || *rootEnv == '\0')
{ {
...@@ -411,7 +402,7 @@ char *nxagentGetRootPath(void) ...@@ -411,7 +402,7 @@ char *nxagentGetRootPath(void)
* settings. * settings.
*/ */
homeEnv = nxagentGetHomePath(); char *homeEnv = nxagentGetHomePath();
if (homeEnv == NULL) if (homeEnv == NULL)
{ {
...@@ -443,6 +434,8 @@ char *nxagentGetRootPath(void) ...@@ -443,6 +434,8 @@ char *nxagentGetRootPath(void)
* Create the NX root directory. * Create the NX root directory.
*/ */
struct stat dirStat;
if ((stat(nxagentRootDir, &dirStat) == -1) && (errno == ENOENT)) if ((stat(nxagentRootDir, &dirStat) == -1) && (errno == ENOENT))
{ {
if (mkdir(nxagentRootDir, 0777) < 0 && (errno != EEXIST)) if (mkdir(nxagentRootDir, 0777) < 0 && (errno != EEXIST))
...@@ -478,7 +471,7 @@ char *nxagentGetRootPath(void) ...@@ -478,7 +471,7 @@ char *nxagentGetRootPath(void)
} }
rootPath = strdup(nxagentRootDir); char *rootPath = strdup(nxagentRootDir);
if (rootPath == NULL) if (rootPath == NULL)
{ {
...@@ -494,12 +487,6 @@ char *nxagentGetRootPath(void) ...@@ -494,12 +487,6 @@ char *nxagentGetRootPath(void)
char *nxagentGetSessionPath(void) char *nxagentGetSessionPath(void)
{ {
char *rootPath;
char *sessionPath;
struct stat dirStat;
if (*nxagentSessionDir == '\0') if (*nxagentSessionDir == '\0')
{ {
/* /*
...@@ -518,7 +505,7 @@ char *nxagentGetSessionPath(void) ...@@ -518,7 +505,7 @@ char *nxagentGetSessionPath(void)
return NULL; return NULL;
} }
rootPath = nxagentGetRootPath(); char *rootPath = nxagentGetRootPath();
if (rootPath == NULL) if (rootPath == NULL)
{ {
...@@ -544,6 +531,8 @@ char *nxagentGetSessionPath(void) ...@@ -544,6 +531,8 @@ char *nxagentGetSessionPath(void)
SAFE_free(rootPath); SAFE_free(rootPath);
struct stat dirStat;
if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT)) if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT))
{ {
if (mkdir(nxagentSessionDir, 0777) < 0 && (errno != EEXIST)) if (mkdir(nxagentSessionDir, 0777) < 0 && (errno != EEXIST))
...@@ -564,7 +553,7 @@ char *nxagentGetSessionPath(void) ...@@ -564,7 +553,7 @@ char *nxagentGetSessionPath(void)
} }
sessionPath = strdup(nxagentSessionDir); char *sessionPath = strdup(nxagentSessionDir);
if (sessionPath == NULL) if (sessionPath == NULL)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment