aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/nxagent/Error.c
diff options
context:
space:
mode:
Diffstat (limited to 'nx-X11/programs/Xserver/hw/nxagent/Error.c')
-rw-r--r--nx-X11/programs/Xserver/hw/nxagent/Error.c77
1 files changed, 33 insertions, 44 deletions
diff --git a/nx-X11/programs/Xserver/hw/nxagent/Error.c b/nx-X11/programs/Xserver/hw/nxagent/Error.c
index c56275922..f5fb297b3 100644
--- a/nx-X11/programs/Xserver/hw/nxagent/Error.c
+++ b/nx-X11/programs/Xserver/hw/nxagent/Error.c
@@ -78,7 +78,7 @@ static int nxagentClientsLog = -1;
* Clients log file name.
*/
-char nxagentClientsLogName[DEFAULT_STRING_LENGTH] = { 0 };
+char nxagentClientsLogName[NXAGENTCLIENTSLOGNAMELENGTH] = { 0 };
/*
* User's home.
@@ -102,7 +102,7 @@ void nxagentGetClientsPath(void);
static int nxagentPrintError(Display *dpy, XErrorEvent *event, FILE *fp);
-/* declare an error handler that does not exit when an error
+/* declare an error handler that does not exit when an error
* event is catched.
*/
@@ -118,6 +118,8 @@ int nxagentErrorHandler(Display *dpy, XErrorEvent *event)
/* copied from XlibInt.c */
/* extension stuff roughly commented out */
+/* FIXME: why? What's wrong with printing extension stuff?
+ We could drop this in favour of _XprintDefaultError then! */
static int nxagentPrintError(dpy, event, fp)
Display *dpy;
XErrorEvent *event;
@@ -138,7 +140,7 @@ static int nxagentPrintError(dpy, event, fp)
mesg, BUFSIZ);
(void) fprintf(fp, mesg, event->request_code);
if (event->request_code < 128) {
- sprintf(number, "%d", event->request_code);
+ snprintf(number, sizeof(number), "%d", event->request_code);
XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ);
} else {
/* for (ext = dpy->ext_procs;
@@ -146,7 +148,7 @@ static int nxagentPrintError(dpy, event, fp)
ext = ext->next)
;
if (ext)
- strcpy(buffer, ext->name);
+ strncpy(buffer, ext->name, BUFSIZ);
else
*/
buffer[0] = '\0';
@@ -159,7 +161,7 @@ static int nxagentPrintError(dpy, event, fp)
(void) fprintf(fp, mesg, event->minor_code);
/*
if (ext) {
- sprintf(mesg, "%s.%d", ext->name, event->minor_code);
+ snprintf(mesg, sizeof(mesg), "%s.%d", ext->name, event->minor_code);
XGetErrorDatabaseText(dpy, "XRequest", mesg, "", buffer, BUFSIZ);
(void) fprintf(fp, " (%s)", buffer);
}
@@ -171,7 +173,7 @@ static int nxagentPrintError(dpy, event, fp)
buffer[0] = '\0';
/*
for (ext = dpy->ext_procs; ext; ext = ext->next) {
- if (ext->error_string)
+ if (ext->error_string)
(*ext->error_string)(dpy, event->error_code, &ext->codes,
buffer, BUFSIZ);
if (buffer[0]) {
@@ -182,9 +184,9 @@ static int nxagentPrintError(dpy, event, fp)
ext->codes.first_error < (int)event->error_code &&
(!bext || ext->codes.first_error > bext->codes.first_error))
bext = ext;
- }
+ }
if (bext)
- sprintf(buffer, "%s.%d", bext->name,
+ snprintf(buffer, sizeof(buffer), "%s.%d", bext->name,
event->error_code - bext->codes.first_error);
else
*/
@@ -225,14 +227,14 @@ static int nxagentPrintError(dpy, event, fp)
(void) fprintf(fp, mesg, event->resourceid);
fputs("\n", fp);
}
- XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
+ XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d",
mesg, BUFSIZ);
fputs(" ", fp);
(void) fprintf(fp, mesg, event->serial);
- XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
+ /* XGetErrorDatabaseText(dpy, mtype, "CurrentSerial", "Current Serial #%d",
mesg, BUFSIZ);
fputs("\n ", fp);
- /* (void) fprintf(fp, mesg, dpy->request); */
+ (void) fprintf(fp, mesg, dpy->request); */
fputs("\n", fp);
if (event->error_code == BadImplementation) return 0;
return 1;
@@ -252,7 +254,7 @@ void nxagentOpenClientsLogFile()
nxagentGetClientsPath();
}
- if (nxagentClientsLogName != NULL && *nxagentClientsLogName !='\0')
+ if (nxagentClientsLogName != NULL && *nxagentClientsLogName != '\0')
{
nxagentClientsLog = open(nxagentClientsLogName, O_RDWR | O_CREAT | O_APPEND, 0600);
@@ -283,12 +285,12 @@ void nxagentStartRedirectToClientsLog(void)
{
if (nxagentStderrBackup == -1)
{
- nxagentStderrBackup = dup(2);
+ nxagentStderrBackup = dup(STDERR_FILENO);
}
if (nxagentStderrBackup != -1)
{
- nxagentStderrDup = dup2(nxagentClientsLog, 2);
+ nxagentStderrDup = dup2(nxagentClientsLog, STDERR_FILENO);
if (nxagentStderrDup == -1)
{
@@ -308,7 +310,7 @@ void nxagentEndRedirectToClientsLog(void)
{
if (nxagentStderrBackup != -1)
{
- nxagentStderrDup = dup2(nxagentStderrBackup, 2);
+ nxagentStderrDup = dup2(nxagentStderrBackup, STDERR_FILENO);
if (nxagentStderrDup == -1)
{
@@ -359,14 +361,14 @@ char *nxagentGetHomePath(void)
#endif
}
- strncpy(nxagentHomeDir, homeEnv, DEFAULT_STRING_LENGTH - 1);
+ snprintf(nxagentHomeDir, DEFAULT_STRING_LENGTH, "%s", homeEnv);
#ifdef TEST
fprintf(stderr, "nxagentGetHomePath: Assuming NX user's home directory '%s'.\n", nxagentHomeDir);
#endif
}
- homePath = (char*) malloc(strlen(nxagentHomeDir) + 1);
+ homePath = strdup(nxagentHomeDir);
if (homePath == NULL)
{
@@ -377,8 +379,6 @@ char *nxagentGetHomePath(void)
return NULL;
}
- strcpy(homePath, nxagentHomeDir);
-
return homePath;
}
@@ -414,10 +414,6 @@ char *nxagentGetRootPath(void)
if (homeEnv == NULL)
{
-
- #ifdef PANIC
- #endif
-
return NULL;
}
@@ -438,8 +434,7 @@ char *nxagentGetRootPath(void)
fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory in '%s'.\n", homeEnv);
#endif
- strcpy(nxagentRootDir, homeEnv);
- strcat(nxagentRootDir, "/.nx");
+ snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s/.nx", homeEnv);
free(homeEnv);
@@ -472,17 +467,17 @@ char *nxagentGetRootPath(void)
return NULL;
}
- strcpy(nxagentRootDir, rootEnv);
+ snprintf(nxagentRootDir, DEFAULT_STRING_LENGTH, "%s", rootEnv);
}
#ifdef TEST
fprintf(stderr, "nxagentGetRootPath: Assuming NX root directory '%s'.\n",
nxagentRootDir);
#endif
-
+
}
- rootPath = malloc(strlen(nxagentRootDir) + 1);
+ rootPath = strdup(nxagentRootDir);
if (rootPath == NULL)
{
@@ -493,8 +488,6 @@ char *nxagentGetRootPath(void)
return NULL;
}
- strcpy(rootPath, nxagentRootDir);
-
return rootPath;
}
@@ -531,9 +524,8 @@ char *nxagentGetSessionPath(void)
return NULL;
}
- strcpy(nxagentSessionDir, rootPath);
-
- free(rootPath);
+ /* FIXME: necessary? */
+ snprintf(nxagentSessionDir, DEFAULT_STRING_LENGTH, "%s", rootPath);
if (strlen(nxagentSessionDir) + strlen("/C-") + strlen(nxagentSessionId) > DEFAULT_STRING_LENGTH - 1)
{
@@ -542,12 +534,14 @@ char *nxagentGetSessionPath(void)
nxagentSessionDir);
#endif
+ free(rootPath);
+
return NULL;
}
- strcat(nxagentSessionDir, "/C-");
+ snprintf(nxagentSessionDir, DEFAULT_STRING_LENGTH, "%s/C-%s", rootPath, nxagentSessionId);
- strcat(nxagentSessionDir, nxagentSessionId);
+ free(rootPath);
if ((stat(nxagentSessionDir, &dirStat) == -1) && (errno == ENOENT))
{
@@ -569,9 +563,9 @@ char *nxagentGetSessionPath(void)
}
- sessionPath = malloc(strlen(nxagentSessionDir) + 1);
+ sessionPath = strdup(nxagentSessionDir);
- if (sessionPath == NULL)
+ if (sessionPath == NULL)
{
#ifdef PANIC
fprintf(stderr, "nxagentGetSessionPath:: PANIC! Can't allocate memory for the session path.\n");
@@ -580,9 +574,6 @@ char *nxagentGetSessionPath(void)
return NULL;
}
-
- strcpy(sessionPath, nxagentSessionDir);
-
return sessionPath;
}
@@ -598,7 +589,7 @@ void nxagentGetClientsPath()
return;
}
- if (strlen(sessionPath) + strlen("/clients") > DEFAULT_STRING_LENGTH - 1)
+ if (strlen(sessionPath) + strlen("/clients") > NXAGENTCLIENTSLOGNAMELENGTH - 1)
{
#ifdef PANIC
fprintf(stderr, "nxagentGetClientsPath: PANIC! Invalid value for the NX clients Log File Path ''.\n");
@@ -609,9 +600,7 @@ void nxagentGetClientsPath()
return;
}
- strcpy(nxagentClientsLogName, sessionPath);
-
- strcat(nxagentClientsLogName, "/clients");
+ snprintf(nxagentClientsLogName, NXAGENTCLIENTSLOGNAMELENGTH, "%s/clients", sessionPath);
free(sessionPath);
}