+/*
+ * CDE - Common Desktop Environment
+ *
+ * Copyright (c) 1993-2012, The Open Group. All rights reserved.
+ *
+ * These libraries and programs are free software; you can
+ * redistribute them and/or modify them under the terms of the GNU
+ * Lesser General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * These libraries and programs are distributed in the hope that
+ * they will be useful, but WITHOUT ANY WARRANTY; without even the
+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU Lesser General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with these libraries and programs; if not, write
+ * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
+ * Floor, Boston, MA 02110-1301 USA
+ */
/* $TOG: SmRestore.c /main/26 1998/12/14 20:13:07 mgreess $ */
/* *
* (c) Copyright 1993, 1994 Hewlett-Packard Company *
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
+#include <string.h>
#ifdef _SUN_OS /* to get the define for NOFILE */
#include <sys/param.h>
#endif /* _SUN_OS */
#include <sys/types.h>
#include <stdlib.h>
-#ifdef __apollo
-#include <X11/apollosys.h> /* for pid_t struct in hp-ux sys/types.h */
-#endif
#include <sys/socket.h>
+#include <sys/wait.h>
#include <netinet/in.h>
#include <netdb.h>
#include <errno.h>
#include <Dt/MsgLog.h>
#include <bms/spc.h>
#include <Dt/CmdInv.h>
+#include <Dt/ActionUtilP.h>
#include "Sm.h"
#include "SmResource.h"
#include "SmDB.h"
#include "SmProp.h"
-#ifndef __osf__
#include <X11/Xlibint.h>
-#endif /* __osf__ */
/*
* Local variables
#define SM_MAX_ARGS MAXLINE
-#if defined (SVR4) || defined (__osf__)
+#if defined (SVR4)
#define REMOTE_CMD_STRING "rsh %s -n %s &"
#else
#define REMOTE_CMD_STRING "remsh %s -n %s &"
static void SetTemporaryDisplay (
int screenNum);
+int RestorePreferences(char *filename);
+
static void RestoreDisplay (
int screenNum);
{
void (*signalHandler) ();
- signalHandler = (void (*)())signal (SIGCLD, SIG_DFL);
+ signalHandler = (void (*)())signal (SIGCHLD, SIG_DFL);
system (pchCmd);
- signal (SIGCLD, signalHandler);
+ signal (SIGCHLD, signalHandler);
} /* END OF FUNTION SystemCmd */
fileSize = MAXLINE + 1;
}
- line = (unsigned char *) malloc ((fileSize + 1) * sizeof(char *));
+ line = malloc(fileSize + 1);
if (line == NULL)
{
line = fallBackLine;
Boolean goodWmStartup = True;
int status;
- if((smGD.wmStartup == NULL) || (*smGD.wmStartup == NULL))
+ if((smGD.wmStartup == NULL) || (*smGD.wmStartup == 0))
{
ForkWM();
}
char *argv[20];
va_list args;
+#if 0
+ /* JET - this seems like a bad (and unused) idea */
/*
* Check for alternate resource loader.
*/
{
pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
}
+#else
+ pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
+#endif
/*
* By convention, exec() wants arg0 to be the program name. Ex: if pgrm
setegid(smGD.runningGID);
#endif
#endif
-#ifdef __osf__
+#if defined(CSRG_BASED)
setsid();
#else
(void) setpgrp();
-#endif /* __osf__ */
+#endif /* CSRG_BASED */
MarkFileDescriptors (3, F_SETFD, 1);
{
char clientMessage[MAXPATHLEN + 256];
- sprintf(clientMessage, ((char *)GETMESSAGE(16, 1, "Unable to exec process %s. No session resources will be restored.")), pgrm);
+ memset(clientMessage, 0, MAXPATHLEN + 256);
+ snprintf(clientMessage, (MAXPATHLEN + 256) - 1,
+ ((char *)GETMESSAGE(16, 1, "Unable to exec process %s. No session resources will be restored.")), pgrm);
PrintErrnoError(DtError, clientMessage);
SM_EXIT(-1);
}
/*
* Load the resources from the SM database file
*/
- if (smGD.settingPath[0] != NULL)
+ if (smGD.settingPath[0] != 0)
{
smBase = XrmGetFileDatabase(smGD.settingPath);
ptrSize += 50;
restorePtrArray = (char **)SM_REALLOC((char *)
restorePtrArray, ptrSize *
- sizeof(char **));
+ sizeof(char *));
if(restorePtrArray == NULL)
{
PrintErrnoError(DtError, smNLS.cantMallocErrorString);
/*
* This is only involked when there is auto repeats set for
* specific keys only. It is VERY SLOW code so unless you
- * have to save off auto repeats for single keys - DONT
+ * have to save off auto repeats for single keys - DON'T
*/
while(tmpKey != NULL)
{
Boolean resIndep = False, resRet;
char *resdata;
- if(((smGD.sessionLang == NULL) || (*smGD.sessionLang == NULL)) &&
+ if(((smGD.sessionLang == NULL) || (*smGD.sessionLang == 0)) &&
(smRes.displayResolution == 0))
{
/*
sessionType = SM_CURRENT_FONT_DIRECTORY;
}
- sprintf(fontPath, "%s/%s/%s/%s.%s", smGD.savePath, sessionType,
- currentLangPtr, SM_FONT_FILE, sessionRes);
+ memset(fontPath, 0, MAXPATHLEN + 1);
+ snprintf(fontPath, MAXPATHLEN, "%s/%s/%s/%s.%s",
+ smGD.savePath, sessionType,
+ currentLangPtr, SM_FONT_FILE, sessionRes);
status = stat(fontPath, &buf);
if(status == -1)
{
* User has nothing there - look in the system defaults
* first in the language dep -then in lang independent
*/
- fontPath[0] = '\0';
+ memset(fontPath, 0, MAXPATHLEN + 1);
if((currentLangPtr != NULL) && (*currentLangPtr != 0))
{
strcat(fontPath, "/");
- strcat(fontPath, currentLangPtr);
+ strncat(fontPath, currentLangPtr, MAXPATHLEN);
}
- strcat(fontPath, "/");
- strcat(fontPath, SM_SYSTEM_FONT_FILE);
+ strncat(fontPath, "/", MAXPATHLEN);
+ strncat(fontPath, SM_SYSTEM_FONT_FILE, MAXPATHLEN);
FixPath(fontPath);
if((currentLangPtr != NULL) && (*currentLangPtr != 0) &&
(strcmp(currentLangPtr, "C")))
{
- strcpy(fontPath, "/C/");
- strcat(fontPath, SM_SYSTEM_FONT_FILE);
+ memset(fontPath, 0, MAXPATHLEN + 1);
+ strcpy(fontPath, "/C/");
+ strncat(fontPath, SM_SYSTEM_FONT_FILE, MAXPATHLEN);
FixPath(fontPath);
* If this is the first DT 3.0 session for a DT 2.0 user then we will
* also launch the helpviewer. If this is the first DT 3.0 session for a
* DT 2.0 user then we will also run convertVS.sh to change all
- * occurances of /usr/bin/X11/hpterm to .../dt/bin/hpterm,
+ * occurrences of /usr/bin/X11/hpterm to .../dt/bin/hpterm,
* /usr/bin/X11/xterm to .../dt/bin/xterm and
* /usr/bin/X11/xload to .../dt/bin/xload.
*
RestoreClients( void )
{
unsigned char *lineP, *string;
- char *pch, *dispPtr;
+ char *pch, *dispPtr = NULL;
char *dispEnv, *dispSav, *dispEnvHelpview, *dispSavHelpview;
unsigned char *hostPtr=NULL, *cmdPtr=NULL, *hintPtr = NULL;
unsigned char *remoteDisplay;
SM_FREE((char *) remoteBuf[i]);
}
}
+ free(displayName);
return(-1);
}
hintPtr = NULL;
SM_FREE((char *) remoteBuf[i]);
}
}
+ free(displayName);
return(-1);
}
cmdPtr = NULL;
{
string = (unsigned char *) fgets((char *)line, fileSize, cfileP);
}
- else if ((parseP != NULL) && (*parseP != NULL))
+ else if ((parseP != NULL) && (*parseP != 0))
/* read parse string */
{
string = line;
#ifdef MULTIBYTE
- while ((*parseP != NULL) &&
+ while ((*parseP != 0) &&
((chlen = mblen ((char *) parseP, MB_CUR_MAX)) > 0) &&
(*parseP != '\n'))
/* copy all but NULL and newlines to line buffer */
*(string++) = *(parseP++);
}
#endif
- *string = NULL;
+ *string = 0;
if (*parseP == '\n')
{
parseP++;
lnwsP++;
if (lnwsP < endP)
{
- *lnwsP = NULL;
+ *lnwsP = 0;
}
}
* NULL -> point to NULL
*/
- if (*endP != NULL)
+ if (*endP != 0)
{
- *endP = NULL; /* write NULL over terminator */
+ *endP = 0; /* write NULL over terminator */
*linePP = ++curP; /* point beyond terminator */
}
else
smRes.ignoreEnvironment, ',');
}
- if (!defaultCwd) {
- if (getenv ("HOME"))
- defaultCwd = strdup (getenv ("HOME"));
- else
- defaultCwd = getcwd (NULL, MAXPATHLEN + 1);
-
- (void) gethostname (localHost, MAXHOSTNAMELEN);
- }
+ if (!defaultCwd)
+ {
+ char *tstr = getenv("HOME");
+ if (tstr)
+ {
+ int slen = strlen(tstr) + 1;
+ defaultCwd = XtCalloc(1, slen);
+ snprintf(defaultCwd, slen, "%s", tstr);
+ }
+ else
+ defaultCwd = getcwd (NULL, MAXPATHLEN + 1);
+
+ (void) gethostname (localHost, MAXHOSTNAMELEN);
+ }
if (!cwd) {
cwdNull = True;
else
tmpEnv = envp;
- for (ppchar = tmpEnv; ppchar && *ppchar; *ppchar++)
+ for (ppchar = tmpEnv; ppchar && *ppchar; ppchar++)
putenv (strdup (*ppchar));
}
_DtEnvControl(DT_ENV_RESTORE_PRE_DT);
-#ifdef __osf__
+#if defined(CSRG_BASED)
setsid();
#else
(void)setpgrp();
-#endif /* __osf__ */
+#endif /* CSRG_BASED */
MarkFileDescriptors (3, F_SETFD, 1);
#endif
_DtEnvControl(DT_ENV_RESTORE_PRE_DT);
-#ifdef __osf__
+#if defined(CSRG_BASED)
setsid();
#else
(void)setpgrp();
-#endif /* __osf__ */
+#endif /* CSRG_BASED */
MarkFileDescriptors (3, F_SETFD, 1);
/*
* Disassociate from parent
*/
-#ifdef __osf__
+#if defined(CSRG_BASED)
setsid();
#else
setpgrp();
-#endif /* __osf__ */
+#endif /* CSRG_BASED */
}
*
* Description:
* -----------
- * This is the event handler registered to recieve the client message
+ * This is the event handler registered to receive the client message
* from dtwm when dtwm is ready for business
*
*
int i;
extern char **environ; /* MODIFIED - DISPLAY is remove if found. */
- for (i=0, ppchar = environ; *ppchar; *ppchar++, i++)
+ for (i=0, ppchar = environ; *ppchar; ppchar++, i++)
{
if ((strncmp (*ppchar, DISPLAY_NAME_EQUAL, strlen(DISPLAY_NAME_EQUAL))) == 0)
{
/*
* Change the DISPLAY environment variable.
*/
- for (; *ppchar; *ppchar++, i++)
+ for (; *ppchar; ppchar++, i++)
{
environ[i]=environ[i+1];
}
if (!envp)
return (NULL);
- for (count = 0, ppchar = envp; ppchar && *ppchar; count++, *ppchar++) ;
+ for (count = 0, ppchar = envp; ppchar && *ppchar; count++, ppchar++) ;
retEnv = (char **) XtMalloc ((count + 1) * sizeof (char *));
if (!retEnv)
if (!ignoreEnvPtr) {
for (count = 0, ppchar = envp; ppchar && *ppchar;
- count++, *ppchar++) {
+ count++, ppchar++) {
retEnv[count] = *ppchar;
}
retEnv[count] = NULL;
return (retEnv);
}
- for (count = 0, ppchar = envp; ppchar && *ppchar; *ppchar++) {
+ for (count = 0, ppchar = envp; ppchar && *ppchar; ppchar++) {
found = False;
- for (ppchar2 = ignoreEnvPtr; ppchar2 && *ppchar2; *ppchar2++) {
+ for (ppchar2 = ignoreEnvPtr; ppchar2 && *ppchar2; ppchar2++) {
if ((!strncmp (*ppchar, *ppchar2, strlen (*ppchar2))) &&
(((*ppchar)[strlen(*ppchar2)]) == '=')) {
#ifdef _SUN_OS
open_max = NOFILE;
#else
-#if defined(USL) || defined(__uxp__) || defined(_AIX)
+#if defined(_AIX)
open_max = FOPEN_MAX;
#else
open_max = FD_SETSIZE;