Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nx-libs
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dimbor
nx-libs
Commits
609b23f1
Commit
609b23f1
authored
Dec 29, 2019
by
Ulrich Sibiller
Committed by
Mike Gabriel
Jan 05, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Error.c: make nxagentRootDir a pointer
no more hardcoded string length
parent
d6cc85e5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
37 deletions
+22
-37
Error.c
nx-X11/programs/Xserver/hw/nxagent/Error.c
+22
-37
No files found.
nx-X11/programs/Xserver/hw/nxagent/Error.c
View file @
609b23f1
...
@@ -91,7 +91,7 @@ static char *nxagentHomeDir = NULL;
...
@@ -91,7 +91,7 @@ static char *nxagentHomeDir = NULL;
* NX root directory.
* NX root directory.
*/
*/
static
char
nxagentRootDir
[
DEFAULT_STRING_LENGTH
]
=
{
0
}
;
static
char
*
nxagentRootDir
=
NULL
;
/*
/*
* Session log Directory.
* Session log Directory.
...
@@ -375,9 +375,13 @@ char *nxagentGetHomePath(void)
...
@@ -375,9 +375,13 @@ char *nxagentGetHomePath(void)
return
nxagentHomeDir
;
return
nxagentHomeDir
;
}
}
/*
* returns a pointer to the static nxagentRootDir. The caller must not free
* this pointer!
*/
char
*
nxagentGetRootPath
(
void
)
char
*
nxagentGetRootPath
(
void
)
{
{
if
(
*
nxagentRootDir
==
'\0'
)
if
(
!
nxagentRootDir
)
{
{
/*
/*
* Check the NX_ROOT environment.
* Check the NX_ROOT environment.
...
@@ -388,7 +392,7 @@ char *nxagentGetRootPath(void)
...
@@ -388,7 +392,7 @@ char *nxagentGetRootPath(void)
if
(
rootEnv
==
NULL
||
*
rootEnv
==
'\0'
)
if
(
rootEnv
==
NULL
||
*
rootEnv
==
'\0'
)
{
{
#ifdef TEST
#ifdef TEST
fprintf
(
stderr
,
"
nxagentGetRootPath: WARNING! No environment for NX_ROOT.
\n
"
);
fprintf
(
stderr
,
"
%s: WARNING! No environment for NX_ROOT.
\n
"
,
__func__
);
#endif
#endif
/*
/*
...
@@ -403,23 +407,23 @@ char *nxagentGetRootPath(void)
...
@@ -403,23 +407,23 @@ char *nxagentGetRootPath(void)
return
NULL
;
return
NULL
;
}
}
if
(
strlen
(
homeEnv
)
>
DEFAULT_STRING_LENGTH
-
/* FIXME: this is currently never freed as it is thought to last
strlen
(
"/.nx"
)
-
1
)
over the complete runtime. We should add a free call at shutdown
eventually... */
int
len
=
asprintf
(
&
nxagentRootDir
,
"%s/.nx"
,
homeEnv
);
if
(
len
==
-
1
)
{
{
#ifdef PANIC
#ifdef PANIC
fprintf
(
stderr
,
"nxagentGetRootPath: PANIC! Invalid value for the NX "
fprintf
(
stderr
,
"%s: could not build NX Root Dir string
\n
"
,
__func__
);
"home directory '%s'.
\n
"
,
homeEnv
);
#endif
#endif
return
NULL
;
return
NULL
;
}
}
#ifdef TEST
#ifdef TEST
fprintf
(
stderr
,
"
nxagentGetRootPath: Assuming NX root directory in '%s'.
\n
"
,
homeEnv
);
fprintf
(
stderr
,
"
%s: Assuming NX root directory in '%s'.
\n
"
,
__func__
,
homeEnv
);
#endif
#endif
snprintf
(
nxagentRootDir
,
DEFAULT_STRING_LENGTH
,
"%s/.nx"
,
homeEnv
);
/*
/*
* Create the NX root directory.
* Create the NX root directory.
*/
*/
...
@@ -430,7 +434,7 @@ char *nxagentGetRootPath(void)
...
@@ -430,7 +434,7 @@ char *nxagentGetRootPath(void)
if
(
mkdir
(
nxagentRootDir
,
0777
)
<
0
&&
(
errno
!=
EEXIST
))
if
(
mkdir
(
nxagentRootDir
,
0777
)
<
0
&&
(
errno
!=
EEXIST
))
{
{
#ifdef PANIC
#ifdef PANIC
fprintf
(
stderr
,
"
nxagentGetRootPath: PANIC! Can't create directory '%s'. Error is %d '%s'.
\n
"
,
fprintf
(
stderr
,
"
%s: PANIC! Can't create directory '%s'. Error is %d '%s'.
\n
"
,
__func__
,
nxagentRootDir
,
errno
,
strerror
(
errno
));
nxagentRootDir
,
errno
,
strerror
(
errno
));
#endif
#endif
...
@@ -440,38 +444,20 @@ char *nxagentGetRootPath(void)
...
@@ -440,38 +444,20 @@ char *nxagentGetRootPath(void)
}
}
else
else
{
{
if
(
strlen
(
rootEnv
)
>
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
#ifdef PANIC
eventually... */
fprintf
(
stderr
,
"nxagentGetRootPath: PANIC! Invalid value for the NX root directory '%s'.
\n
"
,
nxagentRootDir
=
strdup
(
rootEnv
);
rootEnv
);
#endif
return
NULL
;
}
snprintf
(
nxagentRootDir
,
DEFAULT_STRING_LENGTH
,
"%s"
,
rootEnv
);
}
}
#ifdef TEST
#ifdef TEST
fprintf
(
stderr
,
"
nxagentGetRootPath: Assuming NX root directory '%s'.
\n
"
,
fprintf
(
stderr
,
"
%s: Assuming NX root directory '%s'.
\n
"
,
__func__
,
nxagentRootDir
);
nxagentRootDir
);
#endif
#endif
}
}
char
*
rootPath
=
strdup
(
nxagentRootDir
);
return
nxagentRootDir
;
if
(
rootPath
==
NULL
)
{
#ifdef PANIC
fprintf
(
stderr
,
"nxagentGetRootPath: Can't allocate memory for the root path.
\n
"
);
#endif
return
NULL
;
}
return
rootPath
;
}
}
/*
/*
...
@@ -499,7 +485,7 @@ char *nxagentGetSessionPath(void)
...
@@ -499,7 +485,7 @@ char *nxagentGetSessionPath(void)
char
*
rootPath
=
nxagentGetRootPath
();
char
*
rootPath
=
nxagentGetRootPath
();
if
(
rootPath
==
NULL
)
if
(
!
rootPath
)
{
{
return
NULL
;
return
NULL
;
}
}
...
@@ -508,7 +494,6 @@ char *nxagentGetSessionPath(void)
...
@@ -508,7 +494,6 @@ char *nxagentGetSessionPath(void)
and will last over the runtime otherwise. We should add a free call
and will last over the runtime otherwise. We should add a free call
eventually... */
eventually... */
int
len
=
asprintf
(
&
nxagentSessionDir
,
"%s/C-%s"
,
rootPath
,
nxagentSessionId
);
int
len
=
asprintf
(
&
nxagentSessionDir
,
"%s/C-%s"
,
rootPath
,
nxagentSessionId
);
SAFE_free
(
rootPath
);
if
(
len
==
-
1
)
if
(
len
==
-
1
)
{
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment