2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: SmRestore.c /main/26 1998/12/14 20:13:07 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
30 /*************************************<+>*************************************
31 *****************************************************************************
35 ** Project: HP DT Session Manager (dtsession)
39 ** This file contains functions that are in charge of restoring state.
40 ** When the session manager is first started, it restores the state that
41 ** was either last saved (home state), or last exited (current state). The
42 ** state restored depends on values the user has configured.
46 *******************************************************************
47 ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
48 ** reserved. Copying or other reproduction of this program
49 ** except for archival purposes is prohibited without prior
50 ** written consent of Hewlett-Packard Company.
51 ********************************************************************
55 *****************************************************************************
56 *************************************<+>*************************************/
61 #ifdef _SUN_OS /* to get the define for NOFILE */
62 #include <sys/param.h>
64 #include <sys/types.h>
67 #include <X11/apollosys.h> /* for pid_t struct in hp-ux sys/types.h */
69 #include <sys/socket.h>
70 #include <netinet/in.h>
75 #include <X11/Intrinsic.h>
76 #include <X11/Xutil.h>
77 #include <X11/Xatom.h>
78 #include <X11/StringDefs.h>
79 #include <X11/keysymdef.h>
80 #include <X11/SM/SMlib.h>
84 # define Va_start(a,b) va_start(a,b)
87 #include <Dt/Message.h>
88 #include <Dt/CommandM.h>
89 #include <Dt/Connect.h>
92 #include <Dt/UserMsg.h>
93 #include <Dt/SessionM.h>
94 #include <Dt/EnvControlP.h>
95 #include <Dt/Utility.h>
96 #include <Dt/MsgLog.h>
98 #include <Dt/CmdInv.h>
101 #include "SmResource.h"
103 #include "SmCommun.h"
104 #include "SmRestore.h"
105 #include "SmProtocol.h"
106 #include "SmConMgmt.h"
109 #include "SmGlobals.h"
115 #include <X11/Xlibint.h>
121 static const char * DISPLAY_NAME_EQUAL = "DISPLAY=";
122 static const char * DISPLAY_NAME = "DISPLAY";
123 static char * savedDisplay = NULL;
129 #define MAXPATHSM 1023
130 #define MAX_QUOTE_DEPTH 10
132 #define SM_MAX_ARGS MAXLINE
134 #if defined (SVR4) || defined (__osf__)
135 #define REMOTE_CMD_STRING "rsh %s -n %s &"
137 #define REMOTE_CMD_STRING "remsh %s -n %s &"
146 unsigned char *hostPtr;
147 unsigned char *cmdPtr;
151 * Variables global to this module only
153 static XtResource settingsResources[] =
155 {SmNaccelNum, SmCaccelNum, XtRInt, sizeof(int),
156 XtOffset(SessionSettingsPtr, accelNum),
157 XtRImmediate, (XtPointer) -1},
158 {SmNaccelDenom, SmCaccelDenom, XtRInt, sizeof(int),
159 XtOffset(SessionSettingsPtr, accelDenom),
160 XtRImmediate, (XtPointer) -1},
161 {SmNthreshold, SmCthreshold, XtRInt, sizeof(int),
162 XtOffset(SessionSettingsPtr, threshold),
163 XtRImmediate, (XtPointer) -1},
165 {SmNtimeout, SmCtimeout, XtRInt, sizeof(int),
166 XtOffset(SessionSettingsPtr, timeout),
167 XtRImmediate, (XtPointer) -1},
168 {SmNinterval, SmCinterval, XtRInt, sizeof(int),
169 XtOffset(SessionSettingsPtr, interval),
170 XtRImmediate, (XtPointer) -1},
171 {SmNpreferBlank, SmCpreferBlank, XtRInt, sizeof(int),
172 XtOffset(SessionSettingsPtr, preferBlank),
173 XtRImmediate, (XtPointer) 0},
174 {SmNallowExp, SmCallowExp, XtRInt, sizeof(int),
175 XtOffset(SessionSettingsPtr, allowExp),
176 XtRImmediate, (XtPointer) 0},
178 {SmNfontPath, SmCfontPath, XtRString, sizeof(String),
179 XtOffset(SessionSettingsPtr, fontDirs), XtRString, (XtPointer) ""},
181 {SmNkeyClick, SmCkeyClick, XtRInt, sizeof(int),
182 XtOffset(SessionSettingsPtr, kbdState.key_click_percent),
183 XtRImmediate, (XtPointer) -1},
184 {SmNbellPercent, SmCbellPercent, XtRInt, sizeof(int),
185 XtOffset(SessionSettingsPtr, kbdState.bell_percent),
186 XtRImmediate, (XtPointer) -1},
187 {SmNbellPitch, SmCbellPitch, XtRInt, sizeof(int),
188 XtOffset(SessionSettingsPtr, kbdState.bell_pitch),
189 XtRImmediate, (XtPointer) -1},
190 {SmNbellDuration, SmCbellDuration, XtRInt, sizeof(int),
191 XtOffset(SessionSettingsPtr, kbdState.bell_duration),
192 XtRImmediate, (XtPointer) -1},
193 {SmNledMask, SmCledMask, XtRInt, sizeof(int),
194 XtOffset(SessionSettingsPtr, kbdState.led_mask),
195 XtRImmediate, (XtPointer) 0},
196 {SmNglobalRepeats, SmCglobalRepeats, XtRInt, sizeof(int),
197 XtOffset(SessionSettingsPtr, kbdState.global_auto_repeat),
198 XtRImmediate, (XtPointer) 2},
199 {SmNautoRepeats, SmCautoRepeats, XtRString, sizeof(String),
200 XtOffset(SessionSettingsPtr, autoRepeats), XtRString, (XtPointer) ""},
202 {SmNbuttonMap, SmCbuttonMap, XtRString, sizeof(String),
203 XtOffset(SessionSettingsPtr, buttonMap), XtRString, (XtPointer) ""},
205 {SmNnumKeyCode, SmCnumKeyCode, XtRInt, sizeof(int),
206 XtOffset(SessionSettingsPtr, numKeyCode), XtRImmediate, (XtPointer) 0},
207 {SmNkeySymsPerKey, SmCkeySymsPerKey, XtRInt, sizeof(int),
208 XtOffset(SessionSettingsPtr, keySymPerCode),
209 XtRImmediate, (XtPointer) 0},
210 {SmNkeySyms, SmCkeySyms, XtRString, sizeof(String),
211 XtOffset(SessionSettingsPtr, keySyms), XtRString, (XtPointer) ""},
213 {SmNmaxKeyPerMod, SmCmaxKeyPerMod, XtRInt, sizeof(int),
214 XtOffset(SessionSettingsPtr, maxKeyPerMod),
215 XtRImmediate, (XtPointer) 0},
216 {SmNmodMap, SmCmodMap, XtRString, sizeof(String),
217 XtOffset(SessionSettingsPtr, modSyms),
218 XtRString, (XtPointer) ""},
220 {SmNdidQuerySettings, SmCdidQuerySettings, XtRBoolean, sizeof(Boolean),
221 XtOffset(SessionSettingsPtr, didQuery),
222 XtRImmediate, (XtPointer) False},
223 {SmNshutDownState, SmCshutDownState, XtRInt, sizeof(int),
224 XtOffset(SessionSettingsPtr, confirmMode),
225 XtRImmediate, (XtPointer) 1},
226 {SmNshutDownMode, SmCshutDownMode, XtRInt, sizeof(int),
227 XtOffset(SessionSettingsPtr, startState),
228 XtRImmediate, (XtPointer) 4},
232 * Variables used for parsing code
235 static unsigned char fallBackLine[MAXLINE+2]; /* line buffer */
236 static unsigned char *line; /* line buffer */
237 static FILE *cfileP = NULL; /* fopen'ed configuration file or NULL */
238 static int linec = 0; /* line counter for parser */
239 static unsigned char *parseP = NULL; /* pointer to parse string */
240 static int fileSize = 0;
241 char **smExecArray = NULL;
244 * Variables used for remote execution
246 static int numRemoteExecs = 0;
247 unsigned char *remoteBuf[MAX_SCREENS_SAVED];
248 unsigned int actRemoteSize[MAX_SCREENS_SAVED];
249 RemoteReq remoteBufPtr[MAX_REMOTE_CLIENTS];
250 static char localHost[MAXHOSTNAMELEN];
251 static char ** ignoreEnvPtr = NULL;
254 * Timeout for workspace manager handshake
256 static Boolean wmTimeout;
259 * These lines were added to support the builtin
263 char tmpExecWmFile[MAXPATHSM+1];
264 static Boolean localWmLaunched = False;
267 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
268 * End of lines were added to support the builtin
283 "*XmTextField*FontList",
284 "*DtEditor*textFontList",
289 static char *fontclass[] = {
297 "*XmTextField*FontList",
298 "*DtEditor*textFontList",
307 static int RestoreSettings( void ) ;
308 static int RestoreClients( void ) ;
309 static unsigned char * GetNextLine( void ) ;
310 static unsigned int PeekAhead( unsigned char *, unsigned int ) ;
311 static unsigned char * GetSmartString( unsigned char **) ;
312 static void ForkWM( void ) ;
313 static int FillCmdBuf( unsigned char *, unsigned char **,
314 unsigned int *, unsigned int *,
315 unsigned int, unsigned int *) ;
316 static int FillRemoteBuf( unsigned char *, unsigned char *,
317 unsigned char *, unsigned char **,
318 unsigned int *, unsigned int *, unsigned int) ;
319 static int FillHintBuf(unsigned char *, unsigned char **,
320 unsigned int *, unsigned int *,
321 unsigned int, unsigned int *);
322 static void WaitForWM( void ) ;
323 static void HandleWMClientMessage(Widget smWidget, XtPointer dummy,
325 static void WaitWMTimeout( XtPointer , XtIntervalId *) ;
326 static void FixEnvironmentData( void ) ;
327 static void ResetScreenInfo(unsigned char **,
328 int *, unsigned int *,
331 static void RemoteRequestFailed(char *, void *);
332 static void RemoteRequestSucceeded(char *, void *);
334 static void SetTemporaryDisplay (
337 static void RestoreDisplay (
340 static Boolean StartLocalClient (
346 Boolean useIgnoreEnvResource);
348 static Boolean StartRemoteClient (
354 Boolean useIgnoreEnvResource);
356 static Boolean CheckRequiredProperties (
357 XSMPClientDBRecPtr pDbRec,
358 char * databaseName);
360 static Boolean CheckRequiredFields (
361 ProxyClientDBRecPtr pDbRec,
365 static void LogXSMPOpenDatabaseFailure (
367 DtMsgLogType msgType,
370 static void LogMissingPropertyMessage (
371 XSMPClientDBRecPtr pDbRec,
374 DtMsgLogType msgType);
376 static void LogCWDMessage (
381 static char ** RemoveEnvironmentVars (
384 static void MarkFileDescriptors (
390 /*************************************<->*************************************
397 * Sets _DT_SM_STATE_INFO for dtstyle indicating compatibility mode
410 * The only thing dtstyle should be looking at is the compatMode
412 *************************************<->***********************************/
414 SetCompatState( void )
419 * BEFORE any clients are started
420 * set a property on the top level window
421 * which lets the style manager know what state the sm is in
423 state.flags = SM_STATE_ALL;
424 state.smStartState = 0;
425 state.smConfirmMode = 0;
426 state.smCompatMode = True;
427 state.smSendSettings = False;
428 state.smCoverScreen = True;
429 state.smLockOnTimeoutStatus = smGD.lockOnTimeoutStatus;
430 state.smCycleTimeout = 0;
431 state.smLockTimeout = 0;
432 state.smSaverTimeout = 0;
434 state.smDisplaySpecific = smGD.displaySpecific;
436 _DtSetSmState(smGD.display, smGD.topLevelWindow, &state);
438 XFlush(smGD.display);
442 } /* END OF FUNCTION SetCompatState */
445 /*************************************<->*************************************
452 * This function fiddles with our signal handling and calls the
453 * system() function to invoke a unix command.
458 * pchCmd = string with the command we want to exec.
466 * The system() command is touchy about the SIGCLD behavior. Restore
467 * the default SIGCLD handler during the time we run system().
469 *************************************<->***********************************/
472 SystemCmd (char *pchCmd)
474 void (*signalHandler) ();
476 signalHandler = (void (*)())signal (SIGCLD, SIG_DFL);
480 signal (SIGCLD, signalHandler);
481 } /* END OF FUNTION SystemCmd */
485 /*************************************<->*************************************
501 * When this routine is finished, all settings and resources will be restored.
502 * Clients may not be, as they are actually restored by different processes.
504 *************************************<->***********************************/
510 char convertCommand[MAXPATHSM+1];
512 Boolean fixedBuffer = False;
515 Boolean useXrmDB = False;
518 * Restore all the X settings which were active at the time of shutdown
522 if (smGD.sessionType == HOME_SESSION)
523 smSettings.startState = DtSM_HOME_STATE;
525 smSettings.startState = DtSM_CURRENT_STATE;
528 * BEFORE any clients are started
529 * set a property on the top level window
530 * which lets the style manager know what state the sm is in
532 state.flags = SM_STATE_ALL;
533 state.smStartState = smSettings.startState;
534 state.smConfirmMode = smSettings.confirmMode;
535 state.smCompatMode = smGD.compatMode;
536 state.smSendSettings = !smRes.querySettings;
537 state.smLockOnTimeoutStatus = smGD.lockOnTimeoutStatus;
538 state.smCycleTimeout = smSaverRes.cycleTimeout;
539 state.smLockTimeout = smSaverRes.lockTimeout;
540 state.smSaverTimeout = smSaverRes.saverTimeout;
541 state.smRandom = smSaverRes.random;
542 state.smDisplaySpecific = smGD.displaySpecific;
544 _DtSetSmState(smGD.display, smGD.topLevelWindow, &state);
546 saver.saverList = smGD.saverList;
547 _DtSetSmSaver(smGD.display, smGD.topLevelWindow, &saver);
550 * Set up the Property telling all applications what session is being
553 XaSmRestoreMode = XInternAtom(smGD.display, _XA_DT_RESTORE_MODE, False);
554 XChangeProperty(smGD.display, RootWindow(smGD.display, 0),
555 XaSmRestoreMode, XA_STRING, 8, PropModeReplace,
556 (unsigned char *)smGD.restoreSession, strlen(smGD.restoreSession));
557 XFlush(smGD.display);
560 * Check the session database and either parse it as an
561 * Xrm-database or the CDE1.0 format
563 if ((pchar = strrchr (smGD.clientPath, '/')) != NULL)
566 if ((*pchar != '\0') && (!strcmp (pchar, SM_CLIENT_FILE2)))
572 return (StartXSMPSession (smGD.clientPath));
576 * Malloc line for parsing.
578 status = stat(smGD.clientPath, &buf);
581 fileSize = buf.st_size;
584 if (fileSize < MAXLINE + 1)
586 fileSize = MAXLINE + 1;
589 line = (unsigned char *) malloc ((fileSize + 1) * sizeof(char *));
593 fileSize = MAXLINE + 1;
596 cfileP = fopen(smGD.clientPath, "r");
599 PrintErrnoError(DtError, smNLS.cantOpenFileString);
600 if (!fixedBuffer && line)
602 SM_FREE((char *)line);
609 if (!fixedBuffer && line)
611 SM_FREE((char *)line);
620 /*************************************<->*************************************
627 * Start up the window manager. The default is to start dtmwm unless
628 * another one is specified in a resource.
641 * When this routine is finished, all settings and resources will be restored.
642 * Clients may not be, as they are actually restored by different processes.
644 *************************************<->***********************************/
648 char wmStartupErrorString[(2 * MAXPATHSM) + 1];
649 char localWmErrorString[(2 * MAXPATHSM) + 1];
650 Boolean goodWmStartup = True;
653 if((smGD.wmStartup == NULL) || (*smGD.wmStartup == NULL))
659 CreateExecString(smGD.wmStartup);
662 * check to see if the wmStartup string exists and is
665 status = access(smExecArray[0], F_OK | X_OK);
668 goodWmStartup = False;
669 CreateExecString(CDE_INSTALLATION_TOP "/bin/dtwm");
672 if(smExecArray[0] != NULL)
674 (void) StartClient(smExecArray[0], smExecArray, NULL, NULL,
675 NULL, False, False, -1);
680 * We used to start the message server before the window
681 * manager and then if the message server did not start
682 * we would exit. Now we start the window manager, then
683 * start the message server and then wait for the window
684 * manager. This seems to improve performance.
689 if (goodWmStartup == False)
691 sprintf(wmStartupErrorString, GETMESSAGE(16, 7,
692 "The wmStartupCommand resource is set to:\n\n"
694 "This file does not exist or is not executable.\n"
695 CDE_INSTALLATION_TOP "/bin/dtwm will be started "
698 PrintError(DtError, wmStartupErrorString);
704 * These lines were added to support the builtin
708 if (localWmLaunched && wmTimeout)
710 if (!smGD.userSetWaitWmTimeout)
712 smRes.waitWmTimeout = smGD.savedWaitWmTimeout;
715 localWmLaunched = False;
717 * A special version of a built-in Xterminal dtwm
718 * was attempted and failed.
719 * Try to launch .../dt/bin/dtwm instead
722 CreateExecString(CDE_INSTALLATION_TOP "/bin/dtwm");
723 if(smExecArray[0] != NULL)
725 (void) StartClient(smExecArray[0], smExecArray, NULL,
726 NULL, NULL, False, False, -1);
729 sprintf(localWmErrorString, GETMESSAGE(16, 9,
730 "The following window manager did not start:\n\n"
732 "This message indicates you tried to start a\n"
733 "window manager that is built into an X terminal.\n"
734 "This will only work with X terminals that support this protocol.\n"
735 CDE_INSTALLATION_TOP "/bin/dtwm will be started instead.\n"),
737 PrintError(DtError, localWmErrorString);
740 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
741 * End of lines were added to support the builtin
750 /*************************************<->*************************************
757 * Reloads RESOURCE_MANAGER during running session
769 *************************************<->***********************************/
772 ReloadResources(void)
775 * Load sys.resources and .Xdefaults
777 RestoreResources(True,
784 * Merge _DT_SM_PREFERENCES
786 RestorePreferences(NULL);
792 /*************************************<->*************************************
794 * RestoreResources (errorHandlerInstalled, options ... )
799 * Calls routines responsible for restoring resources.
800 * Resources are restored by a fork and exec of dtsession_res.
813 * When this routine is finished, all settings and resources will be restored.
814 * Clients may not be, as they are actually restored by different processes.
816 *************************************<->***********************************/
819 RestoreResources( Boolean errorHandlerInstalled, ... )
822 int childStatus, execStatus, i;
828 * Check for alternate resource loader.
830 if ((pgrm = getenv("DTLOADRESOURCES")) == NULL)
832 pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
836 * By convention, exec() wants arg0 to be the program name. Ex: if pgrm
837 * is /usr/dt/bin/dtsession_res, the program name is dtsession_res.
838 * If all else fails, use pgrm.
840 argv[0] = (p = strrchr(pgrm, '/')) != NULL && *(p+1) != '\0' ? p+1 : pgrm;
843 Va_start(args,errorHandlerInstalled);
847 argv[i] = va_arg(args, char *);
853 * if an error handler is installed - remove it
855 if(errorHandlerInstalled)
857 sigaction(SIGCHLD, &smGD.defvec, (struct sigaction *) NULL);
861 * Fork and exec the xrdb process to load in the file created by
862 * writing out the resource manager string generated by the last
863 * session termination.
866 for(i = 0;(i < 10) && ((forkrc = vfork()) < 0);i++)
877 PrintErrnoError(DtError, smNLS.cantForkClientString);
882 * Fork succeeded - now do the exec
886 SetSIGPIPEToDefault ();
890 * Set the gid of the process back from bin
893 setregid(smGD.runningGID, smGD.runningGID);
895 setgid(smGD.runningGID);
896 setegid(smGD.runningGID);
905 MarkFileDescriptors (3, F_SETFD, 1);
907 execStatus = execv(pgrm, argv);
911 char clientMessage[MAXPATHLEN + 256];
913 sprintf(clientMessage, ((char *)GETMESSAGE(16, 1, "Unable to exec process %s. No session resources will be restored.")), pgrm);
914 PrintErrnoError(DtError, clientMessage);
919 while(wait(&childStatus) != forkrc);
922 * if an error handler is installed - remove it
924 if(errorHandlerInstalled)
926 sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
933 /*************************************<->*************************************
935 * RestorePreferences ( filename)
941 * This routine has two roles:
943 * 1) If 'filename' specified, the content of filename is read, and
944 * _DT_SM_PREFERENCES is populated with its content. This is used
945 * at session startup to set the initial state of _DT_SM_PREFERENCES.
947 * 2) If 'filename' is NULL, the content of _DT_SM_PREFERENCES is
948 * merged into RESOURCE_MANAGER. This is used when resources are
949 * reloaded at user request during a session.
962 *************************************<->***********************************/
974 struct stat statinfo;
976 if(access(filename,R_OK) != 0)
982 * Determine size of file.
984 if (stat(filename, &statinfo) == -1)
992 if ((data = (char *)SM_MALLOC(statinfo.st_size + 1)) == NULL)
998 * Read file into memory.
1000 if ((fp = fopen(filename, "r")) == NULL)
1006 size = fread(data, 1, statinfo.st_size, fp);
1008 if (size == statinfo.st_size)
1011 * Merge .Xdefaults string into RESOURCE_MANAGER database, and
1012 * also convert to Xrm database form for later subtraction.
1015 _DtAddResString(smGD.display, data, _DT_ATR_PREFS);
1023 * Read string from _DT_SM_PREFERENCES
1025 data = _DtGetResString(smGD.display, _DT_ATR_PREFS);
1028 * Merge string into RESOURCE_MANAGER
1030 _DtAddResString(smGD.display, data, _DT_ATR_RESMGR);
1039 /*************************************<->*************************************
1041 * RestoreSettings ()
1046 * In charge of restoring all settings. Settings are stored in resource
1047 * format so it gets the values by getting the resource values stored in
1048 * a resource file that was created by the session manager.
1053 * smGD.settingPath = path that points to the settings resource file.
1062 * This routine messes with the actual strings returned by the resource
1063 * manager by tokenizing them, so these session settings resources should
1064 * not be accessed again.
1066 *************************************<->***********************************/
1068 RestoreSettings( void )
1070 XrmDatabase smBase = NULL;
1071 XKeyboardControl kbdControl;
1073 char **restorePtrArray, **tmpRestore;
1074 char *restoreCharArray;
1075 int numArgs, ptrSize, charSize;
1078 KeySym *tmpSyms, codeSym;
1081 XModifierKeymap restoreMod;
1085 restorePtrArray = (char **) SM_MALLOC (ptrSize * sizeof(char *));
1086 restoreCharArray = (char *) SM_MALLOC (charSize * sizeof(char));
1087 if((restorePtrArray == NULL) || (restoreCharArray == NULL))
1089 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1091 if(restorePtrArray != NULL)
1093 SM_FREE((char *) restorePtrArray);
1097 if(restoreCharArray != NULL)
1099 SM_FREE(restoreCharArray);
1106 * Load the resources from the SM database file
1108 if (smGD.settingPath[0] != NULL)
1110 smBase = XrmGetFileDatabase(smGD.settingPath);
1114 PrintError(DtError, GETMESSAGE(16, 2, "Invalid client settings file. No settings restored."));
1119 XrmMergeDatabases(smBase, &(smGD.display->db));
1124 * Retrieve the session settings file from the database
1126 XtGetApplicationResources(smGD.topLevelWid, (XtPointer) &smSettings,
1127 settingsResources, XtNumber(settingsResources),
1131 * Copy any string resources since they may be overwritten in
1134 smGD.fontDirs = SmNewString(smSettings.fontDirs);
1135 smGD.autoRepeats = SmNewString(smSettings.autoRepeats);
1136 smGD.buttonMap = SmNewString(smSettings.buttonMap);
1137 smGD.keySyms = SmNewString(smSettings.keySyms);
1138 smGD.modSyms = SmNewString(smSettings.modSyms);
1142 * This is provided for backward compatibility sake. The values that
1143 * confirmMode can take have changed
1145 if(smSettings.confirmMode == DtSM_ASK_STATE)
1147 smSettings.confirmMode = DtSM_VERBOSE_MODE;
1151 * If the user has previously used the "query" method, and now wishes
1152 * to use "only what I've customized" method, then we have to start
1153 * from scratch. So don't set anything until customizer tells me to
1155 if((smSettings.didQuery == True) && (smRes.querySettings == False))
1157 SM_FREE((char *) restorePtrArray);
1158 SM_FREE(restoreCharArray);
1163 * Restore pointer control settings
1165 if((smSettings.accelNum > -1 ) || (smSettings.threshold > -1))
1167 XChangePointerControl(smGD.display, True, True,
1168 smSettings.accelNum,
1169 smSettings.accelDenom,
1170 smSettings.threshold);
1171 smToSet.pointerChange = True;
1175 smToSet.pointerChange = False;
1179 * Restore screen saver settings if any are set to non-default
1182 if ((smSettings.timeout > -1) || (smSettings.interval > -1) ||
1183 (smSaverRes.saverTimeout > -1) || (smSaverRes.lockTimeout > -1) ||
1184 (smSaverRes.cycleTimeout > -1))
1188 * For the time between Screen Savers, use the cycleTimeout
1189 * if the user has set this value. Otherwise, use the interval
1190 * value that was set when the session was saved.
1192 if (smSaverRes.cycleTimeout < 0)
1194 screenSaverVals.smInterval = smSettings.interval;
1198 screenSaverVals.smInterval = smSaverRes.cycleTimeout;
1202 * For the screen saver time, use the minimum of the values set for
1203 * saverTimeout or lockTimeout if the user has set one of these
1206 * Otherwise, use the Timeout value that was set when the
1207 * session was saved.
1209 * If it is not set, then use the minimum of the values set for
1210 * saverTimeout or lockTimeout. Set timeout to the Timeout value
1213 if ((smSaverRes.saverTimeout > -1) ||
1214 (smSaverRes.lockTimeout > -1))
1216 if (smSaverRes.saverTimeout > -1)
1218 if ((smSaverRes.lockTimeout > -1) &&
1219 (smSaverRes.lockTimeout < smSaverRes.saverTimeout))
1221 screenSaverVals.smTimeout = smSaverRes.lockTimeout;
1225 screenSaverVals.smTimeout = smSaverRes.saverTimeout;
1230 screenSaverVals.smTimeout = smSaverRes.lockTimeout;
1235 screenSaverVals.smTimeout = smSettings.timeout;
1237 screenSaverVals.smPreferBlank = smSettings.preferBlank;
1238 screenSaverVals.smAllowExp = smSettings.allowExp;
1240 /* Notify X of the new screen saver values */
1241 XSetScreenSaver(smGD.display, screenSaverVals.smTimeout,
1242 screenSaverVals.smInterval,
1243 screenSaverVals.smPreferBlank,
1244 screenSaverVals.smAllowExp);
1247 * If using timeout or interval values that were
1248 * previously saved, then set flag to indicate that they
1249 * should be saved again when the state for the session
1252 if ((smSettings.timeout > -1) || (smSettings.interval > -1))
1254 smToSet.screenSavChange = True;
1258 smToSet.screenSavChange = False;
1264 smToSet.screenSavChange = False;
1268 * Get the font path. Then set it.
1270 tmpRestore = restorePtrArray;
1272 *tmpRestore = strtok(smGD.fontDirs, ",");
1274 while(*tmpRestore != NULL)
1276 numArgs++; tmpRestore++;
1277 *tmpRestore = strtok(NULL, ",");
1278 if((numArgs >= ptrSize) && (*tmpRestore != NULL))
1281 restorePtrArray = (char **)SM_REALLOC((char *)
1282 restorePtrArray, ptrSize *
1284 if(restorePtrArray == NULL)
1286 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1287 SM_FREE(restoreCharArray);
1295 XSetFontPath(smGD.display, restorePtrArray, numArgs);
1299 * Restore the keyboard control information. In order for it
1300 * to be restored it has to be changed from a XKeyboardState
1301 * format to an XKeyboardControl format.
1303 if((smSettings.kbdState.key_click_percent > -1) ||
1304 (smSettings.kbdState.bell_percent > -1) ||
1305 (smSettings.kbdState.bell_pitch > -1) ||
1306 (smSettings.kbdState.bell_duration > -1))
1310 if((smSettings.kbdState.bell_percent > -1) ||
1311 (smSettings.kbdState.bell_pitch > -1) ||
1312 (smSettings.kbdState.bell_duration > -1))
1314 kbdControl.bell_percent = smSettings.kbdState.bell_percent;
1315 kbdControl.bell_pitch = smSettings.kbdState.bell_pitch;
1316 kbdControl.bell_duration = smSettings.kbdState.bell_duration;
1317 kbdControlMask |= (KBBellPercent | KBBellPitch | KBBellDuration);
1318 smToSet.audioChange = True;
1319 audioVals.smBellPercent = smSettings.kbdState.bell_percent;
1320 audioVals.smBellPitch = smSettings.kbdState.bell_pitch;
1321 audioVals.smBellDuration = smSettings.kbdState.bell_duration;
1325 smToSet.audioChange = False;
1328 if((smSettings.kbdState.key_click_percent > -1) ||
1329 (smSettings.kbdState.global_auto_repeat != AutoRepeatModeOn))
1331 kbdControl.key_click_percent =
1332 smSettings.kbdState.key_click_percent;
1333 kbdControlMask |= KBKeyClickPercent;
1334 smToSet.keyboardChange = True;
1335 keyboardVals.smKeyClickPercent = kbdControl.key_click_percent;
1339 smToSet.keyboardChange = False;
1344 * NOTICE THAT THE LED'S DON'T GET RESET. THIS IS BECAUSE LED STUFF
1345 * IS MACHINE DEPENDENT.
1348 * Set the auto repeat stuff
1350 tmpKey = strtok(smGD.autoRepeats, ",");
1351 if((tmpKey == NULL) &&
1352 ((smSettings.kbdState.global_auto_repeat == AutoRepeatModeOff) ||
1353 (smSettings.kbdState.global_auto_repeat == AutoRepeatModeOn)))
1355 smToSet.keyboardChange = True;
1356 kbdControl.auto_repeat_mode =
1357 smSettings.kbdState.global_auto_repeat;
1358 kbdControlMask |= KBAutoRepeatMode;
1359 XChangeKeyboardControl(smGD.display, kbdControlMask, &kbdControl);
1360 keyboardVals.smGlobalAutoRepeat =
1361 smSettings.kbdState.global_auto_repeat;
1367 smToSet.keyboardChange = True;
1368 kbdControl.auto_repeat_mode = smSettings.kbdState.global_auto_repeat;
1369 kbdControlMask |= KBAutoRepeatMode;
1370 XChangeKeyboardControl(smGD.display,
1371 kbdControlMask, &kbdControl);
1372 kbdControl.auto_repeat_mode = AutoRepeatModeOn;
1373 kbdControlMask = KBAutoRepeatMode | KBKey;
1375 * This is only involked when there is auto repeats set for
1376 * specific keys only. It is VERY SLOW code so unless you
1377 * have to save off auto repeats for single keys - DONT
1379 while(tmpKey != NULL)
1381 kbdControl.key = atoi(tmpKey);
1382 XChangeKeyboardControl(smGD.display,
1383 kbdControlMask, &kbdControl);
1384 tmpKey = strtok(NULL, ",");
1389 if(kbdControlMask != 0)
1391 XChangeKeyboardControl(smGD.display,
1392 kbdControlMask, &kbdControl);
1399 smToSet.audioChange = False;
1400 smToSet.keyboardChange = False;
1404 * Restore the button mappings
1407 tmpKey = strtok(smGD.buttonMap, ",");
1411 smToSet.pointerMapChange = True;
1415 smToSet.pointerMapChange = False;
1418 while(tmpKey != NULL)
1420 restoreCharArray[numArgs] = (char) atoi(tmpKey);
1422 tmpKey = strtok(NULL, ",");
1423 if((numArgs >= charSize) && (tmpKey != NULL))
1426 restoreCharArray = (char *) SM_REALLOC(restoreCharArray,
1427 charSize * sizeof(char));
1428 if(restoreCharArray == NULL)
1430 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1431 SM_FREE((char *)restorePtrArray);
1439 XSetPointerMapping(smGD.display, (unsigned char *)restoreCharArray, numArgs);
1442 * Copy the pointer map into the saved map for logout
1444 smToSet.numButton = ((numArgs > 5) ? 5 : numArgs);
1445 for(i = 0; i < smToSet.numButton;i++)
1447 smToSet.pointerMap[i] = restoreCharArray[i];
1452 * Restore the key mappings
1454 if(smSettings.numKeyCode > 0)
1456 tmpSyms = (KeySym *) restoreCharArray;
1457 symSize = (charSize * sizeof(char)) / sizeof(KeySym);
1458 tmpKey = strtok(smGD.keySyms, ",");
1459 for(i = 0;tmpKey != NULL;i++)
1461 tmpSyms[i] = (KeySym) atol(tmpKey);
1462 tmpKey = strtok(NULL, ",");
1464 if((numArgs >= symSize) && (tmpKey != NULL))
1467 symSize = (charSize * sizeof(char))/sizeof(KeySym);
1468 restoreCharArray = (char *) SM_REALLOC(restoreCharArray,
1469 (charSize * sizeof(char)));
1470 if(restoreCharArray == NULL)
1472 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1473 SM_FREE((char *) restorePtrArray);
1476 tmpSyms = (KeySym *) restoreCharArray;
1479 numArgs /= smSettings.keySymPerCode;
1480 XChangeKeyboardMapping(smGD.display, (KeyCode)
1481 smGD.display->min_keycode,
1482 smSettings.keySymPerCode, tmpSyms,
1487 * Restore the modifier mappings
1489 tmpCode = (KeyCode *) restoreCharArray;
1490 tmpKey = strtok(smGD.modSyms, ",");
1493 for(i = 0;i < (8 * smSettings.maxKeyPerMod);i++)
1497 codeSym = (KeySym) atol(tmpKey);
1500 tmpCode[i] = XKeysymToKeycode(smGD.display, codeSym);
1504 tmpCode[i] = (KeyCode) 0;
1509 tmpCode[i] = (KeyCode) 0;
1511 tmpKey = strtok(NULL, ",");
1513 restoreMod.max_keypermod = smSettings.maxKeyPerMod;
1514 restoreMod.modifiermap = tmpCode;
1515 XSetModifierMapping(smGD.display, &restoreMod);
1518 SM_FREE((char *) restorePtrArray);
1519 SM_FREE(restoreCharArray);
1526 /*************************************<->*************************************
1528 * RestoreIndependentResources ()
1533 * In charge of restoring the resources that help make the session more
1534 * resolution and language independent - only restored if they are
1535 * necessary (lang || resolution has changed) and exist
1540 * smResources = global pointer to the resources to be restored by the SM
1550 *************************************<->***********************************/
1552 RestoreIndependentResources( void )
1556 unsigned long nitems, leftover;
1557 unsigned char *data = NULL;
1559 XrmValue fontResourceReturn;
1560 char *currentLangPtr, *resValRet, *sessionType;
1562 int intYRes[2], status,i;
1565 Boolean resIndep = False, resRet;
1568 if(((smGD.sessionLang == NULL) || (*smGD.sessionLang == NULL)) &&
1569 (smRes.displayResolution == 0))
1572 * No saved info to draw from - nothing new is added
1577 currentLangPtr = getenv("LANG");
1579 fltYRes = ((float) DisplayHeight(smGD.display, 0) /
1580 (float) DisplayHeightMM(smGD.display, 0)) * 1000;
1582 if(fltYRes < MED_RES_Y_RES)
1584 intYRes[0] = LOW_RES_Y_RES;
1585 sessionRes = SM_LOW_RES_EXT;
1589 if(fltYRes >= HIGH_RES_Y_RES)
1591 intYRes[0] = HIGH_RES_Y_RES;
1592 sessionRes = SM_HIGH_RES_EXT;
1596 intYRes[0] = MED_RES_Y_RES;
1597 sessionRes = SM_MED_RES_EXT;
1601 if(smRes.displayResolution < MED_RES_Y_RES)
1603 intYRes[1] = LOW_RES_Y_RES;
1607 if(smRes.displayResolution >= HIGH_RES_Y_RES)
1609 intYRes[1] = HIGH_RES_Y_RES;
1613 intYRes[1] = MED_RES_Y_RES;
1618 * If the resolution or the language has changed -
1619 * load the language/resolution independent fonts if
1620 * they exist in the users home directory or in the system
1622 if((strcmp(currentLangPtr, smGD.sessionLang)) ||
1623 (intYRes[0] != intYRes[1]))
1625 char *fontPath = SM_MALLOC(MAXPATHLEN + 1);
1627 if(smGD.sessionType == HOME_SESSION)
1629 sessionType = SM_HOME_FONT_DIRECTORY;
1633 sessionType = SM_CURRENT_FONT_DIRECTORY;
1636 sprintf(fontPath, "%s/%s/%s/%s.%s", smGD.savePath, sessionType,
1637 currentLangPtr, SM_FONT_FILE, sessionRes);
1638 status = stat(fontPath, &buf);
1642 * User has nothing there - look in the system defaults
1643 * first in the language dep -then in lang independent
1647 if((currentLangPtr != NULL) && (*currentLangPtr != 0))
1649 strcat(fontPath, "/");
1650 strcat(fontPath, currentLangPtr);
1653 strcat(fontPath, "/");
1654 strcat(fontPath, SM_SYSTEM_FONT_FILE);
1658 status = stat(fontPath, &buf);
1661 if((currentLangPtr != NULL) && (*currentLangPtr != 0) &&
1662 (strcmp(currentLangPtr, "C")))
1664 strcpy(fontPath, "/C/");
1665 strcat(fontPath, SM_SYSTEM_FONT_FILE);
1669 status = stat(fontPath, &buf);
1686 strncpy(smGD.fontPath, fontPath, MAXPATHLEN);
1688 if(resIndep == True)
1692 * add the auxillary resources onto the root window
1694 RestoreResources(True, "-merge", "-file", smGD.fontPath, NULL);
1697 * Load the resources from the RESOURCE_MANAGER
1698 * property on the root window
1700 if(XGetWindowProperty(smGD.display, RootWindow(smGD.display, 0),
1701 XA_RESOURCE_MANAGER,0L,
1702 100000000L,False,XA_STRING,&actualType,
1703 &actualFormat,&nitems,&leftover,
1704 (unsigned char**) &data) == Success)
1706 smBase = XrmGetStringDatabase((char *)data);
1715 PrintError(DtError, GETMESSAGE(16, 6, "Invalid display/language independent resource file. No display/language independent resources will be restored."));
1716 SM_FREE((char *)data);
1722 * Get the new fontlist from the resources and
1723 * Put it on the application shell. Then add
1724 * the auxillary resources into the display struct
1726 resRet = XrmGetResource(smBase, "*fontList", "*FontList",
1727 &resValRet, &fontResourceReturn);
1730 XtSetArg(uiArgs[i], XmNdefaultFontList,
1731 (XmFontList) fontResourceReturn.addr);i++;
1732 XtSetValues(smGD.topLevelWid, uiArgs, i);
1735 * Overwrite the old font preferences, otherwise,
1736 * they'll come back to haunt us if the user logs in again
1737 * under the current language. We need to get the font
1738 * resources which have just been loaded, then overlay
1739 * them onto the _DT_SM_PREFERENCES root property to make
1740 * sure we get them back when we login again.
1742 for (i = 0; i < XtNumber(fonttype); i++)
1744 resRet = XrmGetResource(smBase, fonttype[i], fontclass[i],
1745 &resValRet, &fontResourceReturn);
1749 (char *)SM_MALLOC(fontResourceReturn.size + 30);
1750 bzero(resdata, fontResourceReturn.size + 30);
1751 strcat(resdata, fonttype[i]);
1752 strcat(resdata, ": ");
1753 strcat(resdata, fontResourceReturn.addr);
1754 strcat(resdata, "\n");
1755 _DtAddResString(smGD.display, resdata, _DT_ATR_PREFS);
1760 XrmMergeDatabases(smBase, &(smGD.display->db));
1761 SM_FREE((char *)data);
1765 SM_FREE((char*) fontPath);
1772 /*************************************<->*************************************
1779 * Reads through the client file and restores its contents. A client file
1780 * consists of hints for the workspace manager, actual client commands, and
1781 * remote execution commands. All commands are processed accordingly.
1782 * If this is the first DT 3.0 session for a DT 2.0 user then we will
1783 * also launch the helpviewer. If this is the first DT 3.0 session for a
1784 * DT 2.0 user then we will also run convertVS.sh to change all
1785 * occurances of /usr/bin/X11/hpterm to .../dt/bin/hpterm,
1786 * /usr/bin/X11/xterm to .../dt/bin/xterm and
1787 * /usr/bin/X11/xload to .../dt/bin/xload.
1798 * Any information read from the client file will be mucked with during
1799 * processing, and should not try to be mucked with again.
1801 * WARNING: This routine closes cfileP - not the calling routine
1802 * DOUBLE-WARNING: This routine starts the window manager
1804 *************************************<->***********************************/
1806 RestoreClients( void )
1808 unsigned char *lineP, *string;
1809 char *pch, *dispPtr;
1810 char *dispEnv, *dispSav, *dispEnvHelpview, *dispSavHelpview;
1811 unsigned char *hostPtr=NULL, *cmdPtr=NULL, *hintPtr = NULL;
1812 unsigned char *remoteDisplay;
1815 unsigned char tmpChar[35];
1816 int screenNum = 0, i, j, chlen, numClientsExec;
1817 int numRemoteDone = 0;
1819 Boolean clientsDone = False, wmHandshake = False, cmdInvInit = False;
1820 XClientMessageEvent smToWmMessage;
1823 * These variables are needed to buffer up the commands and then
1824 * execute them (also buffer up hints then put them on the root window
1826 unsigned char *hintsBuf[MAX_SCREENS_SAVED];
1827 unsigned char *cmdBuf[MAX_SCREENS_SAVED];
1828 unsigned int maxHintsSize[MAX_SCREENS_SAVED];
1829 unsigned int actHintsSize[MAX_SCREENS_SAVED];
1830 unsigned int numHints[MAX_SCREENS_SAVED];
1831 unsigned int maxCmdSize[MAX_SCREENS_SAVED];
1832 unsigned int actCmdSize[MAX_SCREENS_SAVED];
1833 unsigned int numCmd[MAX_SCREENS_SAVED];
1834 unsigned int maxRemoteSize[MAX_SCREENS_SAVED];
1837 * Initialize the buffers and their sizes to null and 0. Because of
1838 * all possible combinations - buffers aren't malloc'd until they're
1841 for(i = 0;i<smGD.numSavedScreens;i++)
1845 remoteBuf[i] = NULL;
1846 maxHintsSize[i] = 0;
1847 actHintsSize[i] = 0;
1852 maxRemoteSize[i] = 0;
1853 actRemoteSize[i] = 0;
1857 * Save the contents of the DISPLAY environment variable so that it
1858 * can be restored when we're through
1860 dispEnv = getenv(DISPLAY_NAME);
1863 dispSav = (char *) SM_MALLOC(((strlen(dispEnv) +
1864 strlen(DISPLAY_NAME_EQUAL)) * sizeof(char) + 1));
1865 sprintf(dispSav, "%s%s", DISPLAY_NAME_EQUAL, dispEnv);
1873 displayName = strdup(smGD.display->display_name);
1874 remoteDisplay = (unsigned char *)
1875 SM_MALLOC(sizeof(unsigned char) * (strlen(displayName) + 101));
1878 * Create the display name for locally executing clients
1904 * Create the display name for remotely executing clients.
1905 * These two may or may not be the same
1907 DtGetShortHostname((char *)remoteDisplay, 100);
1910 * Add the display qualifications to the host name
1911 * screen is added at execution time
1913 strcat((char *)remoteDisplay, (char *)dispPtr);
1916 * Intern the atom needed to put the hints on the root window
1917 * This has to be done here because InitProtocol has not been called yet
1919 XaWmDtHints = XInternAtom(smGD.display, _XA_DT_SESSION_HINTS, False);
1921 while(GetNextLine() != NULL)
1924 string = GetSmartString(&lineP);
1925 if( string != NULL && !strcmp((char *)string, "dtsmcmd"))
1927 while((string = GetSmartString(&lineP)) != NULL )
1929 if(!strcmp((char *)string, "-host"))
1932 * Extract a host pointer - host pointers
1933 * only exist on remote executions
1935 string = GetSmartString(&lineP);
1940 if(!strcmp((char *)string, "-cmd"))
1943 * Extract the command pointer from the
1946 string = GetSmartString(&lineP);
1951 if(!strcmp((char *)string, "-screen"))
1954 * Extract the screen number from the command
1956 string = GetSmartString(&lineP);
1957 screenNum = atoi((char *)string);
1962 if(!strcmp((char *)string, "-hints"))
1965 * Extract the hints string
1967 string = GetSmartString(&lineP);
1976 * Now put our information in buffers and reinitialize the pointers
1980 if(FillHintBuf(hintPtr, hintsBuf, maxHintsSize,
1981 actHintsSize, screenNum, numHints) != 0)
1984 * Free all malloc'd buffers and exit
1986 for(i = 0;i < smGD.numSavedScreens;i++)
1988 if(actHintsSize[i] > 0)
1990 SM_FREE((char *) hintsBuf[i]);
1992 if(actCmdSize[i] > 0)
1994 SM_FREE((char *) cmdBuf[i]);
1996 if(actRemoteSize[i] > 0)
1998 SM_FREE((char *) remoteBuf[i]);
2006 if((cmdPtr != NULL) && (hostPtr == NULL))
2008 if(FillCmdBuf(cmdPtr, cmdBuf, maxCmdSize,
2009 actCmdSize,screenNum, &numCmd[screenNum]) != 0)
2012 * Free all malloc'd buffers and exit
2014 for(i = 0;i < smGD.numSavedScreens;i++)
2016 if(actHintsSize[i] > 0)
2018 SM_FREE((char *) hintsBuf[i]);
2020 if(actCmdSize[i] > 0)
2022 SM_FREE((char *) cmdBuf[i]);
2024 if(actRemoteSize[i] > 0)
2026 SM_FREE((char *) remoteBuf[i]);
2035 if((cmdPtr != NULL) && (hostPtr != NULL))
2037 if(FillRemoteBuf(cmdPtr, hostPtr, remoteDisplay,
2038 remoteBuf, maxRemoteSize,
2039 actRemoteSize, screenNum) != 0)
2042 * Free all malloc'd buffers and exit
2044 for(i = 0;i < smGD.numSavedScreens;i++)
2046 if(actHintsSize[i] > 0)
2048 SM_FREE((char *) hintsBuf[i]);
2050 if(actCmdSize[i] > 0)
2052 SM_FREE((char *) cmdBuf[i]);
2054 if(actRemoteSize[i] > 0)
2056 SM_FREE((char *) remoteBuf[i]);
2065 screenNum = XDefaultScreen(smGD.display);
2070 * All done with file so close it off and set descriptor to NULL -
2071 * This is done so that parsing routines can be used with a buffer later
2077 * Now execute all the buffers, put all hints on the root windows
2078 * Do all remote executions
2080 for(i = 0;i < smGD.numSavedScreens;i++)
2083 * Put the root window property on each root window
2085 if(actHintsSize[i] > 0)
2088 * Append number of hints to front of buffer
2090 sprintf((char *)tmpChar, "%d", numHints[i]);
2091 strncpy((char *)hintsBuf[i], (char *)tmpChar,
2092 strlen((char *)tmpChar));
2093 XChangeProperty(smGD.display, RootWindow(smGD.display, i),
2094 XaWmDtHints, XA_STRING, 8, PropModeReplace,
2095 hintsBuf[i], actHintsSize[i]);
2096 SM_FREE((char *) hintsBuf[i]);
2097 XSync(smGD.display, 0);
2105 * Now exec on the local clients - we're doing contention management
2106 * to make sure the system doesn't get swamped
2110 while((actCmdSize[i] == 0) && (i < smGD.numSavedScreens))
2115 envVal = SM_MALLOC(BUFSIZ);
2116 if(i >= smGD.numSavedScreens)
2122 sprintf(envVal,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, i);
2130 * Keep forking one client after the other until the
2131 * memory utilization gets beyond the threshold -
2132 * (but only if the capability exists) Then go to
2133 * window manager handshaking
2135 #ifdef DEBUG_CONT_MANAGEMENT
2136 if(smRes.contManagement & SM_CM_SYSTEM)
2138 fprintf(stderr, "SM_CM_SYSTEM flag set in smRes.contManagement\n");
2140 if(smRes.contManagement & SM_CM_HANDSHAKE)
2142 fprintf(stderr, "SM_CM_HANDSHAKE flag set in smRes.contManagement\n");
2144 #endif /* DEBUG_CONT */
2146 if((smRes.contManagement & SM_CM_SYSTEM) &&
2147 ((GetMemoryUtilization() != MEM_NOT_AVAILABLE) &&
2148 (clientsDone == False)))
2150 while((GetMemoryUtilization() == MEM_NOT_FULL) &&
2151 (clientsDone == False))
2155 CreateExecString((char *) lineP);
2156 if(smExecArray[0] != NULL)
2158 (void) StartClient(smExecArray[0], (char **)smExecArray, NULL,
2159 NULL, NULL, False, False, -1);
2164 * When all the clients have been exec'd for this screen
2167 if(numClientsExec >= numCmd[i])
2169 ResetScreenInfo(cmdBuf, &i, actCmdSize, &clientsDone,
2170 envVal, displayName);
2177 * After we've checked memory utilization - finish up
2178 * by handshaking with the worksapce manager - if it's there
2180 if(clientsDone == False)
2182 if((smGD.dtwmRunning) && (smRes.contManagement & SM_CM_HANDSHAKE))
2185 * Get the window id of the workspace manager and tell it
2186 * to start messaging
2188 _DtGetMwmWindow(smGD.display, RootWindow(smGD.display, 0),
2190 smToWmMessage.type = ClientMessage;
2191 smToWmMessage.window = dtwmWin;
2192 smToWmMessage.message_type = XaSmWmProtocol;
2193 smToWmMessage.format = 32;
2194 smToWmMessage.data.l[0] = XaSmStartAckWindow;
2195 smToWmMessage.data.l[1] = CurrentTime;
2196 if (XSendEvent(smGD.display, dtwmWin,False,NoEventMask,
2197 (XEvent *) &smToWmMessage) != 0)
2200 XSync(smGD.display, 0);
2206 * Start a client - and wait for the workspace manager to
2207 * map a window to start a new client
2209 while(clientsDone == False)
2213 CreateExecString((char *) lineP);
2214 if(smExecArray[0] != NULL)
2216 (void) StartClient(smExecArray[0], smExecArray,
2217 NULL, NULL, NULL, False, False, -1);
2221 * If we're handshaking with the workspace manager
2222 * wait for the client to be mapped before starting
2225 if(wmHandshake == True)
2233 * When all the clients have been exec'd for this screen
2236 if(numClientsExec >= numCmd[i])
2238 ResetScreenInfo(cmdBuf, &i, actCmdSize, &clientsDone,
2239 envVal, displayName);
2244 if(wmHandshake == True)
2247 * If we are handshaking - tell the workspace manager to
2250 smToWmMessage.type = ClientMessage;
2251 smToWmMessage.window = dtwmWin;
2252 smToWmMessage.message_type = XaSmWmProtocol;
2253 smToWmMessage.format = 32;
2254 smToWmMessage.data.l[0] = XaSmStopAckWindow;
2255 smToWmMessage.data.l[0] = CurrentTime;
2256 XSendEvent(smGD.display, dtwmWin,False,NoEventMask,
2257 (XEvent *) &smToWmMessage);
2262 for(i = 0;i < smGD.numSavedScreens;i++)
2264 if(numRemoteDone == MAX_REMOTE_CLIENTS)
2270 * Send out all the remote execution commands for the screen to
2271 * the command invoker. On failure - do a remsh instead
2273 if(actRemoteSize[i] > 0)
2276 * Initialize the command invoker - if not done
2278 if(cmdInvInit == False)
2280 _DtInitializeCommandInvoker(smGD.display,
2288 * Set up the display environment variable so that the
2289 * application comes back to the right screen
2291 sprintf(envVal,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, i);
2295 parseP = remoteBuf[i];
2296 while(numRemoteExecs > 0 && GetNextLine() != NULL)
2299 * Get the host and the command and send them off
2300 * On failure of the command invoker do a remsh
2303 string = GetSmartString(&lineP);
2305 string = GetSmartString(&lineP);
2308 remoteBufPtr[numRemoteDone].cmdPtr = cmdPtr;
2309 remoteBufPtr[numRemoteDone].hostPtr = hostPtr;
2311 _DtCommandInvokerExecute(DtSTART_SESSION, NULL, NULL, NULL,
2312 "-", (char *) hostPtr, (char *) cmdPtr,
2313 RemoteRequestSucceeded, NULL,
2314 RemoteRequestFailed,
2315 &remoteBufPtr[numRemoteDone]);
2319 * If there is no more room in the remote client
2320 * array - quit exec'ing remote clients
2322 if(numRemoteDone == MAX_REMOTE_CLIENTS)
2324 PrintError(DtError, GETMESSAGE(16, 5, "You have reached the maximum allowed number of remote clients. No further remote clients will be restored."));
2334 * Now return the display variable back to the display that was
2335 * originally opened (the default display)
2343 FixEnvironmentData();
2348 } /* END OF FUNCTION RestoreClients */
2352 /*************************************<->*************************************
2354 * StartEtc ( exiting )
2359 * Call the StartClient routine to fork and exec either the sessionetc file
2360 * (if exiting==False) or the sessionexit file (if exiting==True).
2372 *************************************<->***********************************/
2374 StartEtc( Boolean exiting )
2381 execArray[0] = smGD.exitPath;
2382 execArray[1] = smExitFile;
2384 execArray[0] = smGD.etcPath;
2385 execArray[1] = smEtcFile;
2387 execArray[2] = '\0';
2389 if ((status=stat(execArray[0], &buf)) != -1)
2391 StartClient(execArray[0], execArray, NULL, NULL, NULL, False, False, -1);
2396 /*************************************<->*************************************
2403 * Returns the next line from an fopened configuration file or a newline-
2404 * embedded configuration string.
2409 * cfileP = (global) file pointer to fopened configuration file or NULL
2410 * line = (global) line buffer
2411 * linec = (global) line count
2412 * parseP = (global) parse string pointer if cfileP == NULL
2417 * line = (global) next line
2418 * linec = (global) line count incremented
2419 * parseP = (global) parse string pointer incremented
2420 * Return = line or NULL if file or string is exhausted.
2425 * If there are more than MAXLINE characters on a line in the file cfileP the
2426 * excess are truncated.
2427 * Assumes the line buffer is long enough for any parse string line.
2428 * Code stolen from dtmwm
2430 *************************************<->***********************************/
2431 static unsigned char *
2434 unsigned char *string;
2440 /* read fopened file */
2442 string = (unsigned char *) fgets((char *)line, fileSize, cfileP);
2444 else if ((parseP != NULL) && (*parseP != NULL))
2445 /* read parse string */
2449 while ((*parseP != NULL) &&
2450 ((chlen = mblen ((char *) parseP, MB_CUR_MAX)) > 0) &&
2452 /* copy all but NULL and newlines to line buffer */
2456 *(string++) = *(parseP++);
2460 while ((*parseP != NULL) && (*parseP != '\n'))
2461 /* copy all but NULL and newlines to line buffer */
2463 *(string++) = *(parseP++);
2467 if (*parseP == '\n')
2480 } /* END OF FUNCTION GetNextLine */
2484 /*************************************<->*************************************
2486 * PeekAhead (currentChar, currentLev)
2491 * Returns a new level value if this is a new nesting level of quoted string
2492 * Otherwise it returns a zero
2497 * currentChar = current position in the string
2498 * currentLev = current level of nesting
2503 * Returns either a new level of nesting or zero if the character is copied in
2509 *************************************<->***********************************/
2512 unsigned char *currentChar,
2513 unsigned int currentLev )
2515 Boolean done = False;
2516 unsigned int tmpLev = 1;
2520 while (((chlen = mblen ((char *) currentChar, MB_CUR_MAX)) > 0) &&
2521 (chlen == 1) && ((*currentChar == '"') || (*currentChar == '\\'))
2526 if(((chlen = mblen ((char *) currentChar, MB_CUR_MAX)) > 0) && (chlen == 1) &&
2527 ((*currentChar == '"') || (*currentChar == '\\')))
2530 if(*currentChar == '"')
2541 while((*currentChar != NULL) && (done == False) &&
2542 ((*currentChar == '"') || (*currentChar == '\\')))
2545 if((*currentChar != NULL) &&
2546 ((*currentChar == '"') || (*currentChar == '\\')))
2549 if(*currentChar == '"')
2559 #endif /*MULTIBYTE*/
2562 * Figure out if this is truly a new level of nesting - else ignore it
2563 * This section probably could do some error checking and return -1
2564 * If so, change type of routine from unsigned int to int
2578 /*************************************<->*************************************
2580 * GetSmartString (linePP)
2585 * Returns the next quoted or whitespace-terminated nonquoted string in the
2587 * Additional functionality added to GetString in that anything in a
2588 * quoted string is considered sacred and nothing will be stripped from
2589 * the middle of a quoted string.
2594 * linePP = pointer to current line buffer pointer.
2599 * linePP = pointer to revised line buffer pointer.
2605 * May alter the line buffer contents.
2606 * Handles quoted strings and characters, removing trailing whitespace from
2608 * Returns NULL string if the line is empty or is a comment.
2609 * Code stolen from dtmwm.
2611 *************************************<->***********************************/
2613 static unsigned char *
2615 unsigned char **linePP )
2617 unsigned char *lineP = *linePP;
2618 unsigned char *endP;
2619 unsigned char *curP;
2620 unsigned char *lnwsP;
2621 unsigned int level = 0, checkLev, i, quoteLevel[MAX_QUOTE_DEPTH];
2625 /* get rid of leading white space */
2626 ScanWhitespace (&lineP);
2629 * Return NULL if line is empty, whitespace, or begins with a comment.
2631 if((chlen = mblen ((char *) lineP, MB_CUR_MAX)) < 1)
2637 if ((chlen == 1) && (*lineP == '"'))
2640 quoteLevel[level] = 1;
2642 * Start beyond double quote and find the end of the quoted string.
2643 * '\' quotes the next character - but is not stripped out.
2644 * Otherwise, matching double quote or NULL terminates the string.
2646 * We use lnwsP to point to the last non-whitespace character in the
2647 * quoted string. When we have found the end of the quoted string,
2648 * increment lnwsP and if lnwsP < endP, write NULL into *lnwsP.
2649 * This removes any trailing whitespace without overwriting the
2650 * matching quote, needed later. If the quoted string was all
2651 * whitespace, then this will write a NULL at the beginning of the
2652 * string that will be returned -- OK.
2654 lnwsP = lineP++; /* lnwsP points to first '"' */
2655 curP = endP = lineP; /* other pointers point beyond */
2657 while ((*endP = *curP) &&
2658 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0) &&
2659 ((chlen > 1) || (*curP != '"')))
2660 /* Haven't found matching quote yet.
2661 * First byte of next character has been copied to endP.
2665 if ((chlen == 1) && (*endP == '\\') &&
2666 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0))
2669 * Check to see if this is a quoted quote - if it is
2670 * strip off a level - if not - it's sacred leave it alone
2672 checkLev = PeekAhead((curP - 1), quoteLevel[level]);
2675 if(quoteLevel[level] >= checkLev)
2677 if (level > 0) level--;
2679 else if (level < MAX_QUOTE_DEPTH)
2682 quoteLevel[level] = checkLev;
2685 for(i = 0;i < (checkLev - 2);i++)
2687 *endP++ = *curP++;curP++;
2694 /* Singlebyte character: character copy finished. */
2696 if (isspace (*endP))
2697 /* whitespace character: leave lnwsP unchanged. */
2702 /* non-whitespace character: point lnwsP to it. */
2708 /* Multibyte (nonwhitespace) character: point lnwsP to it.
2709 * Finish character byte copy.
2722 /* get rid of leading white space */
2723 ScanWhitespace (&lineP);
2725 /* Return NULL if line is empty, or whitespace */
2735 quoteLevel[level] = 1;
2737 * Start beyond double quote and find the end of the quoted string.
2738 * '\' quotes the next character.
2739 * Otherwise, matching double quote or NULL terminates the string.
2741 * We use lnwsP to point to the last non-whitespace character in the
2742 * quoted string. When we have found the end of the quoted string,
2743 * increment lnwsP and if lnwsP < endP, write NULL into *lnwsP.
2744 * This removes any trailing whitespace without overwriting the
2745 * matching quote, needed later. If the quoted string was all
2746 * whitespace, then this will write a NULL at the beginning of the
2747 * string that will be returned -- OK.
2749 lnwsP = lineP++; /* lnwsP points to first '"' */
2750 curP = endP = lineP; /* other pointers point beyond */
2752 while ((*endP = *curP) && (*endP != '"'))
2753 /* haven't found matching quote yet */
2755 /* point curP to next character */
2757 if ((*endP == '\\') && (*curP != NULL))
2758 /* shift quoted nonNULL character down and curP ahead */
2761 * Check to see if this is a quoted quote - if it is
2762 * strip off a level - if not - it's sacred leave it alone
2764 checkLev = PeekAhead((curP - 1), quoteLevel[level]);
2767 if(quoteLevel[level] >= checkLev)
2769 if (level > 0) level--;
2771 else if (level < MAX_QUOTE_DEPTH)
2774 quoteLevel[level] = checkLev;
2777 for(i = 0;i < (checkLev - 2);i++)
2779 *endP++ = *curP++;curP++;
2785 if (isspace (*endP))
2786 /* whitespace character: leave lnwsP unchanged. */
2791 /* non-whitespace character: point lnwsP to it. */
2799 * Found matching quote or NULL.
2800 * NULL out any trailing whitespace.
2811 /* Unquoted string */
2814 * Find the end of the nonquoted string.
2815 * '\' quotes the next character.
2816 * Otherwise, whitespace, NULL, terminates the string.
2818 curP = endP = lineP;
2821 while ((*endP = *curP) &&
2822 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0) &&
2823 ((chlen > 1) || (!isspace (*curP))))
2824 /* Haven't found whitespace yet.
2825 * First byte of next character has been copied to endP.
2829 if ((chlen == 1) && (*endP == '\\') &&
2830 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0))
2832 * copy first byte of quoted nonNULL character down.
2833 * point curP to next byte
2840 /* Multibyte character: finish character copy. */
2849 while ((*endP = *curP) && !isspace (*endP))
2851 /* point curP to next character */
2853 if ((*endP == '\\') && (*curP != NULL))
2854 /* shift quoted nonNULL character down and curP ahead */
2864 * Two cases for *endP:
2866 * matching quote -> write NULL over char and point beyond
2867 * NULL -> point to NULL
2872 *endP = NULL; /* write NULL over terminator */
2873 *linePP = ++curP; /* point beyond terminator */
2879 return ((unsigned char *)lineP);
2881 } /* END OF FUNCTION GetString */
2886 /*************************************<->*************************************
2888 * ScanWhitespace(linePP)
2893 * Scan the string, skipping over all white space characters.
2898 * linePP = nonNULL pointer to current line buffer pointer
2903 * linePP = nonNULL pointer to revised line buffer pointer
2908 * Assumes linePP is nonNULL
2909 * Code Stolen from dtmwm
2911 *************************************<->***********************************/
2914 unsigned char **linePP )
2917 while (*linePP && (mblen ((char *) *linePP, MB_CUR_MAX) == 1) && isspace (**linePP))
2919 while (*linePP && isspace (**linePP))
2925 } /* END OF FUNCTION ScanWhitespace */
2929 /*************************************<->*************************************
2931 * FillHintBuf(newHint, hintBuf, maxSize, actSize, screen, numHints)
2936 * Put the new hint into the hint buffer. Each hint is separated by a
2942 * newHint = hint to add to the buffer
2943 * hintBuf = an array of buffers - one for each screen
2944 * maxSize = array of buffers of the current malloced size of each hintBuf
2945 * actSize = array of space currently used by each hintBuf
2946 * screen = screen number for this hint
2947 * numHints = array of the number of hints for each screen
2948 * smGD.numSavedScreens = (global) checked to make sure this hint should be
2953 * hintBuf[screen] = updated hint buf for this screen (newHint added)
2954 * maxSize[screen] = enlarged if not big enough or malloced if not done before
2955 * actSize[screen] = updated size of the hints buffer
2956 * numHints[screen] = updated by 1 if this hint is added
2962 *************************************<->***********************************/
2965 unsigned char *newHint,
2966 unsigned char **hintBuf,
2967 unsigned int *maxSize,
2968 unsigned int *actSize,
2969 unsigned int screen,
2970 unsigned int *numHints)
2972 static int hintBufSize = 5000;
2975 * If the screen that this hint was meant for is not in the current
2976 * set of available screens, don't save it
2978 if(screen >= smGD.numSavedScreens)
2984 * Check to see if this buffer has been malloc'd before - if it hasn't
2985 * malloc it. If it has - check to make sure it's big enough to hold the
2988 if(maxSize[screen] == 0)
2990 hintBuf[screen] = (unsigned char *) SM_MALLOC(hintBufSize * sizeof(char));
2991 if(hintBuf[screen] == NULL)
2993 actSize[screen] = 0;
2994 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
2997 maxSize[screen] = hintBufSize * sizeof(char);
3000 * Now reserve 4 bytes for the length
3002 strcpy((char *)hintBuf[screen], " \n");
3006 if((actSize[screen] + strlen((char *)newHint) + 2) >= maxSize[screen])
3008 hintBuf[screen] = (unsigned char *)
3009 SM_REALLOC((char *) hintBuf[screen],
3013 if(hintBuf[screen] == NULL)
3015 actSize[screen] = 0;
3016 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3019 maxSize[screen] = maxSize[screen] + (hintBufSize * sizeof(char));
3024 * add the new hint AFTER the last newline
3026 strcat((char *)hintBuf[screen], (char *)newHint);
3027 strcat((char *)hintBuf[screen], "\n");
3028 actSize[screen] = strlen((char *)hintBuf[screen]);
3029 numHints[screen] += 1;
3036 /*************************************<->*************************************
3038 * FillCmdBuf(newCmd, cmdBuf, maxSize, actSize, screen)
3043 * Put a new command into the command buffer. The command buffer is just
3044 * one big long string of stuff to be executed.
3049 * newCmd = command to add to the buffer
3050 * cmdBuf = an array of buffers - one for each screen
3051 * maxSize = array of buffers of the current malloced size of each cmdBuf
3052 * actSize = array of space currently used by each cmdBuf
3053 * screen = screen number for this command
3054 * smGD.numSavedScreens = (global) checked to make sure this hint should be
3059 * cmdBuf[screen] = updated command buf for this screen (newCmd added)
3060 * maxSize[screen] = enlarged if not big enough or malloced if not done before
3061 * actSize[screen] = updated size of the command buffer
3067 *************************************<->***********************************/
3070 unsigned char *newCmd,
3071 unsigned char **cmdBuf,
3072 unsigned int *maxSize,
3073 unsigned int *actSize,
3074 unsigned int screen,
3075 unsigned int *numCmd )
3077 static int cmdBufSize = 5000;
3080 * If the screen that this command was meant for is not in the current
3081 * set of available screens, don't save it
3083 if(screen >= smGD.numSavedScreens)
3089 * Check to see if this buffer has been malloc'd before - if it hasn't
3090 * malloc it. If it has - check to make sure it's big enough to hold the
3093 if(maxSize[screen] == 0)
3095 cmdBuf[screen] = (unsigned char *) SM_MALLOC(cmdBufSize * sizeof(char));
3096 if(cmdBuf[screen] == NULL)
3098 actSize[screen] = 0;
3099 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3102 maxSize[screen] = cmdBufSize * sizeof(char);
3106 if((actSize[screen] + strlen((char *)newCmd)) >= maxSize[screen])
3108 cmdBuf[screen] = (unsigned char *) SM_REALLOC((char *)cmdBuf[screen],
3112 if(cmdBuf[screen] == NULL)
3114 actSize[screen] = 0;
3115 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3118 maxSize[screen] = maxSize[screen] + (cmdBufSize * sizeof(char));
3122 if(actSize[screen] == 0)
3124 strcpy((char *)cmdBuf[screen], (char *)newCmd);
3128 strcat((char *)cmdBuf[screen], (char *)newCmd);
3131 *numCmd = *numCmd + 1;
3132 strcat((char *)cmdBuf[screen], "\n");
3133 actSize[screen] = strlen((char *)cmdBuf[screen]);
3140 /*************************************<->*************************************
3142 * FillRemoteBuf(newCmd, hostName, displayName, remoteBuf,
3143 * maxSize, actSize, screen)
3148 * Put a new command into the remote execution buffer. The command buffer is
3149 * just one big long string of stuff to be executed.
3154 * newCmd = command to add to the buffer
3155 * hostName = host where command is to be executed from
3156 * displayName = display where host is to be executed to
3157 * remoteBuf = an array of buffers - one for each screen
3158 * maxSize = array of buffers of the current malloced size of each cmdBuf
3159 * actSize = array of space currently used by each cmdBuf
3160 * screen = screen number for this command
3161 * smGD.numSavedScreens = (global) checked to make sure this hint should be
3166 * cmdBuf[screen] = updated command buf for this screen (newCmd added)
3167 * in remote format (host name and display name)
3168 * maxSize[screen] = enlarged if not big enough or malloced if not done before
3169 * actSize[screen] = updated size of the command buffer
3175 *************************************<->***********************************/
3178 unsigned char *newCmd,
3179 unsigned char *hostName,
3180 unsigned char *displayName,
3181 unsigned char *remoteBuf[] ,
3182 unsigned int *maxSize ,
3183 unsigned int *actSize ,
3184 unsigned int screen )
3186 unsigned char *string;
3187 static int remoteBufSize = 5000;
3190 * If the screen that this command was meant for is not in the current
3191 * set of available screens, don't save it
3193 if(screen >= smGD.numSavedScreens)
3199 * Check to see if this buffer has been malloc'd before - if it hasn't
3200 * malloc it. If it has - check to make sure it's big enough to hold the
3203 if(maxSize[screen] == 0)
3205 remoteBuf[screen] = (unsigned char *)
3206 SM_MALLOC(remoteBufSize * sizeof(char));
3207 if(remoteBuf[screen] == NULL)
3209 actSize[screen] = 0;
3210 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3213 maxSize[screen] = remoteBufSize * sizeof(char);
3217 if((actSize[screen] + strlen((char *)newCmd) +
3218 strlen((char *)hostName) +
3219 strlen((char *)displayName) +
3220 strlen("-display ") + 5) >= maxSize[screen])
3222 remoteBuf[screen] = (unsigned char *)
3223 SM_REALLOC((char *)remoteBuf[screen],
3225 (remoteBufSize * sizeof(char)));
3226 if(remoteBuf[screen] == NULL)
3228 actSize[screen] = 0;
3229 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3232 maxSize[screen] = maxSize[screen] + (remoteBufSize * sizeof(char));
3236 if(actSize[screen] == 0)
3239 * If the buffer is empty fill it with the initial contents
3241 strcpy((char *)remoteBuf[screen], (char *)hostName);
3242 strcat((char *)remoteBuf[screen], " ");
3247 * if this buffer is not emtpy
3248 * add the new command BEFORE the last null terminator
3249 * Commands for remote executions are separated by newlines
3251 strcat((char *)remoteBuf[screen], "\n");
3252 strcat((char *)remoteBuf[screen], (char *)hostName);
3256 * Copy the command in - quote it
3258 strcat((char *)remoteBuf[screen], " \"");
3259 string = GetSmartString(&newCmd);
3260 strcat((char *)remoteBuf[screen], (char *)string);
3261 strcat((char *)remoteBuf[screen], " ");
3264 * Once display name has been put in place - concatenate the
3265 * rest of the command
3267 while((string = GetSmartString(&newCmd)) != NULL )
3269 strcat((char *)remoteBuf[screen], " ");
3270 strcat((char *)remoteBuf[screen], (char *)string);
3274 * Now close off the command with a quote
3276 strcat((char *)remoteBuf[screen], "\"");
3278 actSize[screen] = strlen((char *)remoteBuf[screen]);
3281 * Bump the remote command counter
3289 /*************************************<->*************************************
3291 * CreateExecString(execString)
3296 * Create a string that can be fed to a fork and exec by breaking it up
3297 * into argc and argv
3302 * execString = whole command
3306 * smExecArray = global modified to contain pointers to argc and argv
3312 *************************************<->***********************************/
3320 static int iSizeArgv = ARG_AMT;
3325 if (smExecArray == NULL)
3327 smExecArray = (char **) XtMalloc (ARG_AMT * sizeof(char *));
3329 string = (char *) GetSmartString((unsigned char **) &execString);
3330 while(string != NULL)
3332 smExecArray[argc] = string;
3334 if (argc >= iSizeArgv)
3336 iSizeArgv += ARG_AMT;
3337 smExecArray = (char **)
3338 XtRealloc ((char *)smExecArray, (iSizeArgv * sizeof(char *)));
3340 string = (char *) GetSmartString((unsigned char **) &execString);
3344 * If the last string is a background character
3349 if(!strcmp((char *)smExecArray[argc - 1], "&"))
3351 smExecArray[argc - 1] = '\0';
3355 smExecArray[argc] = '\0';
3357 } /* END OF FUNCTION CreateExecString */
3361 * SetTemporaryDisplay - does a putenv of the current value of the
3362 * DISPLAY environment variable but with the given screen number.
3368 SetTemporaryDisplay (
3371 static char * tmpDisplay = NULL;
3372 static int lastScreen = -1;
3375 if (screenNum == -1)
3378 if (!savedDisplay) {
3381 if ((dispEnv = getenv (DISPLAY_NAME)) == NULL)
3383 savedDisplay = XtMalloc (strlen (DISPLAY_NAME_EQUAL) +
3384 strlen (dispEnv) + 2);
3387 sprintf (savedDisplay, "%s%s", DISPLAY_NAME_EQUAL, dispEnv);
3390 if (lastScreen == screenNum && tmpDisplay != NULL) {
3391 putenv (tmpDisplay);
3394 lastScreen = screenNum;
3399 tmpDisplay = XtMalloc (strlen (savedDisplay) + 4);
3402 strcpy (tmpDisplay, savedDisplay);
3405 if (pch = strrchr (tmpDisplay, ':')) {
3408 if (pch2 = strchr (pch, '.'))
3410 pch3 = XtMalloc (strlen (tmpDisplay) + 4);
3413 sprintf (pch3, "%s.%d", tmpDisplay, screenNum);
3414 strcpy (tmpDisplay, pch3);
3415 XtFree ((char *) pch3);
3417 putenv (tmpDisplay);
3423 * RestoreDisplay - does a putenv of the global variable savedDisplay
3429 if (screenNum != -1 && savedDisplay)
3430 putenv (savedDisplay);
3434 /*************************************<->*************************************
3436 * StartClient - calls StartLocalClient or StartRemoteClient depending
3437 * on the value of hostName.
3441 * Starts a local or remote application
3445 * program = execArray[0]
3446 * execArray = command to fork and exec
3447 * hostName = the name of the host where program should be executed
3448 * cwd = directory to chdir to before doing the exec
3449 * envp = the envrironment variables to add to the child processes env
3450 * checkCwd = if True and cwd is NULL, a message will be logged; if
3451 * False, cwd will not be checked and the cwd will be set to $HOME
3452 * useIgnoreEnvironmentResource = if True, the variables listed in the
3453 * IgnoreEnvironment resource will be removed from 'environ' before
3454 * execArray is exec'd
3455 * screen = if set to -1, it will be ignored; otherwise, the screen
3456 * number will be used to define DISPLAY for the duration of this
3457 * function - DISPLAY will be reset before the function returns.
3461 * Returns True if the command is successfully executed; False otherwise.
3465 * localHost - is modified
3467 *************************************<->***********************************/
3476 Boolean useIgnoreEnvironmentResource,
3479 static char * defaultCwd = NULL;
3480 Boolean cwdNull = False;
3481 Boolean startStatus;
3483 SetTemporaryDisplay (screen);
3485 if (!ignoreEnvPtr && useIgnoreEnvironmentResource) {
3486 if (smRes.ignoreEnvironment)
3487 ignoreEnvPtr = _DtVectorizeInPlace (
3488 smRes.ignoreEnvironment, ',');
3492 if (getenv ("HOME"))
3493 defaultCwd = strdup (getenv ("HOME"));
3495 defaultCwd = getcwd (NULL, MAXPATHLEN + 1);
3497 (void) gethostname (localHost, MAXHOSTNAMELEN);
3505 if (!hostName || (_DtIsSameHost (localHost, hostName)))
3506 startStatus = StartLocalClient (program, execArray,
3507 cwd, envp, checkCwd,
3508 useIgnoreEnvironmentResource);
3510 startStatus = StartRemoteClient (program, execArray, hostName,
3512 useIgnoreEnvironmentResource);
3514 RestoreDisplay (screen);
3516 return (startStatus);
3519 /*************************************<->*************************************
3525 * Starts a local application.
3528 * Returns True if the command is successfully executed; False otherwise.
3530 *************************************<->***********************************/
3538 Boolean useIgnoreEnvironmentResource)
3542 char clientMessage[MAXPATHLEN + 30];
3543 char **tmpEnv, **ppchar;
3546 * Fork and exec the client process
3548 clientFork = vfork();
3551 * If the fork fails - Send out an error and return
3555 PrintErrnoError(DtError, smNLS.cantForkClientString);
3560 * Fork succeeded - now do the exec
3564 SetSIGPIPEToDefault ();
3567 * Log a warning if the given cwd is not valid
3571 if ((chdir (cwd)) == -1)
3575 tmpCwd = getcwd (NULL, MAXPATHLEN + 1);
3577 LogCWDMessage (cwd, program, tmpCwd);
3582 * Add envp to the client's environ if the variable
3583 * is not in the ignoreEnvironment list
3585 if (useIgnoreEnvironmentResource && envp) {
3588 tmpEnv = RemoveEnvironmentVars (envp);
3592 for (ppchar = tmpEnv; ppchar && *ppchar; *ppchar++)
3593 putenv (strdup (*ppchar));
3598 * Set the gid of the process back from bin
3601 setregid(smGD.runningGID, smGD.runningGID);
3603 setgid(smGD.runningGID);
3604 setegid(smGD.runningGID);
3608 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
3614 #endif /* __osf__ */
3616 MarkFileDescriptors (3, F_SETFD, 1);
3618 execStatus = execvp(program, execArray);
3621 sprintf(clientMessage, ((char *)GETMESSAGE(16, 3, "Unable to exec %s.")), execArray[0]);
3622 PrintErrnoError(DtError, clientMessage);
3630 /*************************************<->*************************************
3636 * Starts a remote application.
3639 * Returns True if the command is successfully executed; False otherwise.
3641 *************************************<->***********************************/
3649 Boolean useIgnoreEnvironmentResource)
3652 SPC_Channel_Ptr channel;
3654 char errorMessage[1024];
3656 static Boolean cmdInvokerInitialized = False;
3657 char ** tmpEnv = envp;
3659 ioMode = SPCIO_NOIO | SPCIO_FORCE_CONTEXT;
3661 if (!cmdInvokerInitialized) {
3662 _DtInitializeCommandInvoker(smGD.display,
3666 cmdInvokerInitialized = True;
3669 (void) strcpy (errorMessage, "");
3671 channel = (SPC_Channel_Ptr) _DtSPCOpen (hostName, ioMode, errorMessage);
3672 if (channel == SPC_ERROR) {
3673 message = strdup ((char *) GETMESSAGE (40, 13,
3674 "The following application cannot be started on host '%s'\nbecause this host cannot be reached from host '%s':\n\n %s"));
3677 DtMsgLogMessage (smGD.programName, DtMsgLogError,
3678 message, hostName, localHost, program);
3684 netfile = tt_host_file_netfile (hostName, cwd);
3685 if (tt_pointer_error (netfile) != TT_OK) {
3687 message = strdup ((char *) GETMESSAGE (40, 14,
3688 "An attempt to start application '%s'\non host '%s' failed because the following directory\ncould not be translated into cannonical form:\n\n %s\n\n[%s]"));
3691 DtMsgLogMessage (smGD.programName, DtMsgLogError,
3692 message, program, hostName, cwd,
3693 tt_status_message (tt_pointer_error (
3701 * Add envp to the client's environ if the variable
3702 * is not in the ignoreEnvironment list
3704 if (useIgnoreEnvironmentResource && ignoreEnvPtr && envp)
3705 tmpEnv = RemoveEnvironmentVars (envp);
3707 if ((_DtSPCSpawn (program, netfile, execArray, tmpEnv, channel,
3708 hostName, NULL, cwd, errorMessage)) == SPC_ERROR) {
3709 DtMsgLogMessage (smGD.programName, DtMsgLogError, errorMessage);
3711 XtFree ((char *) tmpEnv);
3717 XtFree ((char *) tmpEnv);
3723 /*************************************<->*************************************
3730 * Fork and exec the default window manager
3743 *************************************<->***********************************/
3752 * These lines were added to support the builtin
3757 char *displayName,*dpy;
3759 hostName = SM_MALLOC(MAXPATHSM);
3760 displayName = SM_MALLOC(MAXPATHSM);
3762 if( gethostname(hostName, (sizeof(hostName) - 1) ) == 0)
3764 hostName[MAXPATHSM - 1] = '\0';
3765 dpy = getenv(DISPLAY_NAME);
3766 homeDir = getenv("HOME");
3769 strcpy(displayName, dpy);
3770 dpy = strchr(displayName, ':');
3775 sprintf(tmpExecWmFile, "%s/.dt/bin/%s/%s/dtwm", homeDir,
3776 hostName,displayName);
3777 if (access(tmpExecWmFile,X_OK) != 0)
3779 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3783 localWmLaunched = True;
3784 if (!smGD.userSetWaitWmTimeout)
3786 smRes.waitWmTimeout = 60000;
3792 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3797 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3801 SM_FREE(displayName);
3803 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
3804 * End of lines were added to support the builtin
3808 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3813 * Fork and exec the client process
3815 clientFork = vfork();
3818 * If the fork fails - Send out an error and return
3822 PrintErrnoError(DtError, smNLS.cantForkClientString);
3827 * Fork succeeded - now do the exec
3831 SetSIGPIPEToDefault ();
3835 * Set the gid of the process back from bin
3838 setregid(smGD.runningGID, smGD.runningGID);
3840 setgid(smGD.runningGID);
3841 setegid(smGD.runningGID);
3844 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
3850 #endif /* __osf__ */
3852 MarkFileDescriptors (3, F_SETFD, 1);
3855 * These lines were added to support the builtin
3858 * execStatus = execlp(".../dt/bin/dtwm", "dtwm", (char *) 0);
3861 execStatus = execlp(tmpExecWmFile, "dtwm", (char *) 0);
3864 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
3865 * End of lines were added to support the builtin
3869 if(execStatus != 0 && (!localWmLaunched))
3871 PrintErrnoError(DtError, GETMESSAGE(16, 4, "Unable to exec process /usr/dt/bin/dtwm. No window manager will be started."));
3878 /*************************************<->*************************************
3885 * Fork a copy of ourselves and kill the parent off so that scripts starting
3886 * up the session manager can continue.
3898 *************************************<->***********************************/
3906 * Fork and exec the client process
3908 clientFork = fork();
3911 * If the fork fails - We have to exit so that the rest of the
3912 * script can continue
3916 PrintErrnoError(DtError, smNLS.cantForkClientString);
3921 * Fork succeeded - now kill the parent
3929 * Disassociate from parent
3935 #endif /* __osf__ */
3940 /*************************************<->*************************************
3947 * This routine waits for the window manager to start. It uses a
3948 * resource (waitWmTimeout) with a dynamic default to determine how many
3949 * seconds to wait for WM start and then starts clients.
3954 * appContext = application context for the window
3955 * window = window id for the
3964 *************************************<->***********************************/
3969 XtIntervalId wmTimerId;
3971 XtAddEventHandler(smGD.topLevelWid,
3974 (XtEventHandler)HandleWMClientMessage,
3978 * Set a timer which stops the block on waiting for the
3979 * window manager to start
3982 wmTimerId = XtAppAddTimeOut(smGD.appCon,
3983 smRes.waitWmTimeout,
3984 WaitWMTimeout, NULL);
3986 while((smGD.dtwmRunning == False) && (wmTimeout == False))
3988 XtAppProcessEvent(smGD.appCon, XtIMAll);
3991 XtRemoveTimeOut(wmTimerId);
3992 XtRemoveEventHandler(smGD.topLevelWid,
3995 (XtEventHandler)HandleWMClientMessage,
3999 } /* END OF FUNCTION WaitForWM */
4002 /*************************************<->*************************************
4009 * Timeout procedure the WaitForCommand routine. It stops a loop waiting
4010 * for the window manager to get started.
4019 * wmTimeout = (global) flag that stops the loop
4024 *************************************<->***********************************/
4027 XtPointer client_data,
4032 } /* END OF FUNCTION WaitWMTimeout */
4036 /*************************************<->*************************************
4038 * HandleWMClientMessage
4043 * This is the event handler registered to recieve the client message
4044 * from dtwm when dtwm is ready for business
4047 *************************************<->***********************************/
4049 HandleWMClientMessage( Widget smWidget,
4053 if (event->type == ClientMessage)
4055 ProcessClientMessage(event);
4058 } /* END OF FUNCTION HandleWMClientMessage */
4063 /*************************************<->*************************************
4065 * FixEnvironmentData
4070 * If DISPLAY variable exists in the environment - remove it
4079 * wmTimeout = (global) flag that stops the loop
4084 *************************************<->***********************************/
4086 FixEnvironmentData( void )
4090 extern char **environ; /* MODIFIED - DISPLAY is remove if found. */
4092 for (i=0, ppchar = environ; *ppchar; *ppchar++, i++)
4094 if ((strncmp (*ppchar, DISPLAY_NAME_EQUAL, strlen(DISPLAY_NAME_EQUAL))) == 0)
4097 * Change the DISPLAY environment variable.
4099 for (; *ppchar; *ppchar++, i++)
4101 environ[i]=environ[i+1];
4110 /*************************************<->*************************************
4117 * After one screen is finished - set up the info for the next
4122 * cmdBuf - Buffer that holds all the invocation information
4123 * screen - Pointer to the screen number that we're currently working on
4124 * env - used to set up the environment for changing the display var
4125 * displayName - name of the current display
4129 * cmdBuf - old buffers are freed
4130 * screen - updated to point to the new screen info
4131 * done - tells whether the clients are done being exec'd
4132 * linec - *GLOBAL* sets line being read from
4138 *************************************<->***********************************/
4140 ResetScreenInfo(unsigned char **cmdBuf,
4142 unsigned int *cmdSize,
4147 SM_FREE((char *) cmdBuf[*screen]);
4149 while((cmdSize[*screen] == 0) && (*screen < smGD.numSavedScreens))
4154 if(*screen >= smGD.numSavedScreens)
4160 sprintf((char *)env,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, *screen);
4164 parseP = cmdBuf[*screen];
4170 /*************************************<->*************************************
4172 * RemoteRequestFailed ()
4177 * If a request to the command invoker fails, this callback will be called.
4178 * It will then try to execute the command by performing a remsh on it.
4191 *************************************<->***********************************/
4193 RemoteRequestFailed(char *message,
4196 static char *cmdBuf = NULL;
4197 static char *tmpCmdBuf = NULL;
4198 char *errorString = NULL;
4201 static int cmdBufSize = 0;
4204 RemoteReq *tmpReq = (RemoteReq *) client_data;
4207 * If the memory for the buffer has not been malloced - do so
4211 cmdBuf = SM_MALLOC((200 * sizeof(char)) + 1 );
4214 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4217 cmdBufSize = 200 + 1;
4219 tmpCmdBuf = SM_MALLOC((200 * sizeof(char)) + 1 );
4220 if(tmpCmdBuf == NULL)
4222 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4227 * Copy in the host and command field and execute the command
4230 tmpSize = (strlen(REMOTE_CMD_STRING) +
4231 strlen((char *) tmpReq->hostPtr) +
4232 strlen((char *) tmpReq->cmdPtr) + 1);
4234 if(tmpSize >= cmdBufSize)
4236 cmdBuf = SM_REALLOC(cmdBuf, (tmpSize) * sizeof(char));
4240 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4244 cmdBufSize = tmpSize;
4246 if(tmpCmdBuf != NULL)
4248 tmpCmdBuf = SM_REALLOC(tmpCmdBuf, (tmpSize) * sizeof(char));
4249 if(tmpCmdBuf == NULL)
4251 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4256 sprintf(cmdBuf, REMOTE_CMD_STRING, tmpReq->hostPtr, tmpReq->cmdPtr);
4259 * save cmdBuf for error message, cmdBuf is changed
4260 * by CreateExecString
4262 if (tmpCmdBuf != NULL)
4264 strcpy(tmpCmdBuf,cmdBuf);
4267 CreateExecString(cmdBuf);
4268 if(smExecArray[0] != NULL)
4270 (void) StartClient(smExecArray[0], smExecArray, NULL, NULL,
4271 NULL, False, False, -1);
4273 if (tmpCmdBuf != NULL)
4275 tmpString = GETMESSAGE(16, 8,
4276 "An attempt to restore the following\ncommand (using the DT remote execution process)\non host \"%s\" failed:\n\n %s\n\nThe following execution string will be tried:\n\n %s\n\n");
4279 (char *)SM_MALLOC((strlen(tmpString) +
4280 strlen((char *)tmpReq->hostPtr) +
4281 strlen((char *)tmpReq->cmdPtr) +
4282 strlen(tmpCmdBuf) + 1 ) *
4285 if(errorString == NULL)
4287 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4291 sprintf(errorString, tmpString, tmpReq->hostPtr,
4292 tmpReq->cmdPtr, tmpCmdBuf );
4293 PrintError(DtError, errorString);
4294 SM_FREE(errorString);
4299 * Now check to make sure that this isn't the last remote request.
4300 * If so, free the data
4304 if(numRemoteExecs == 0)
4306 for(i = 0;i < smGD.numSavedScreens;i++)
4308 if(actRemoteSize[i] > 0)
4310 SM_FREE((char *) remoteBuf[i]);
4320 /*************************************<->*************************************
4322 * RemoteRequestSucceeded ()
4327 * If a request to the command invoker succeeds, this callback will be called.
4328 * It decrements the remote execution counter, and frees the info if
4329 * remote executions are finished
4342 *************************************<->***********************************/
4344 RemoteRequestSucceeded(char *message,
4351 if(numRemoteExecs == 0)
4353 for(i = 0;i < smGD.numSavedScreens;i++)
4355 if(actRemoteSize[i] > 0)
4357 SM_FREE((char *) remoteBuf[i]);
4363 /**************************************************************************
4367 **************************************************************************/
4371 char * databaseName)
4374 XSMPClientDBRecPtr pXSMPRec;
4375 ProxyClientDBRecPtr pProxyRec;
4380 if ((inputDB = OpenInputClientDB (databaseName,
4382 &smXSMP.dbSessionId)) == NULL) {
4383 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogError, 1);
4387 if (!smXSMP.dbVersion) {
4388 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogWarning, 2);
4389 smXSMP.dbVersion = SM_VENDOR_NAME;
4392 if (!smXSMP.dbSessionId) {
4393 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogWarning, 3);
4394 smXSMP.dbSessionId = SM_RELEASE_NAME;
4398 * First start the XSMP clients
4402 if ((pXSMPRec = GetXSMPClientDBRec (inputDB)) == NULL)
4405 if (!CheckRequiredProperties (pXSMPRec, databaseName)) {
4406 FreeXSMPClientDBRec (pXSMPRec);
4410 if (StartXSMPClient (pXSMPRec, databaseName)) {
4412 XSMPClientDBRecPtr tmpRecPtr;
4414 pXSMPRec->next = NULL;
4416 if (!smXSMP.xsmpDbList) {
4417 smXSMP.xsmpDbList = pXSMPRec;
4422 * Find the end of the list
4424 for (tmpRecPtr = smXSMP.xsmpDbList;
4425 tmpRecPtr && tmpRecPtr->next != NULL;
4426 tmpRecPtr = tmpRecPtr->next);
4428 tmpRecPtr->next = pXSMPRec;
4431 FreeXSMPClientDBRec (pXSMPRec);
4435 * Now start the Proxy clients
4437 for (i = 0; ; i++) {
4439 if ((pProxyRec = GetProxyClientDBRec (inputDB)) == NULL)
4442 if (!CheckRequiredFields (pProxyRec, databaseName, i)) {
4443 FreeProxyClientDBRec (pProxyRec);
4447 (void) StartProxyClient (pProxyRec);
4449 FreeProxyClientDBRec (pProxyRec);
4452 (void) CloseClientDB (inputDB, False);
4460 XSMPClientDBRecPtr pDbRec,
4461 char * databaseName)
4463 return (StartClient (pDbRec->restartCommand[0],
4464 pDbRec->restartCommand,
4467 pDbRec->environment,
4470 pDbRec->screenNum));
4476 ProxyClientDBRecPtr pDbRec)
4478 return (StartClient (pDbRec->command[0],
4485 pDbRec->screenNum));
4490 ExecuteCommandProperty (
4492 ClientRecPtr pClientRec)
4495 char ** envp = NULL;
4497 PropertyRecPtr pPropRec;
4501 if ((pPropRec = GetPropertyRec (pClientRec, commandName)) == NULL)
4504 argv = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
4509 for (i = 0; i < pPropRec->prop.num_vals; i++)
4510 argv[i] = pPropRec->prop.vals[i].value;
4511 argv[pPropRec->prop.num_vals] = NULL;
4513 cwd = GetArrayPropertyValue (pClientRec, SmCurrentDirectory);
4516 if ((pPropRec = GetPropertyRec (pClientRec, SmEnvironment)) != NULL) {
4517 envp = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
4522 for (i = 0; i < pPropRec->prop.num_vals; i++)
4523 envp[i] = pPropRec->prop.vals[i].value;
4524 envp[pPropRec->prop.num_vals] = NULL;
4527 retValue = StartClient (argv[0], argv,
4528 pClientRec->clientHost,
4531 pClientRec->screenNum);
4533 XtFree ((char *) argv);
4535 XtFree ((char *) envp);
4541 /*************************************<->*************************************
4543 * ExecuteDiscardCommands -
4545 * Description: Executes all of the DiscardCommand properties in the
4546 * given client database
4550 *************************************<->***********************************/
4552 ExecuteDiscardCommands (
4556 XSMPClientDBRecPtr pXSMPRec;
4557 char * version = NULL;
4561 if ((inputDB = OpenInputClientDB (db, &version, &id )) == NULL) {
4562 str = strdup ((char *) GETMESSAGE (40, 26,
4563 "The following client database cannot be opened:\n\n %s\n\nThe 'DiscardCommand' properties cannot be run."));
4566 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, str, db);
4572 XtFree ((char *) version);
4574 XtFree ((char *) id);
4577 if ((pXSMPRec = GetXSMPClientDBRec (inputDB)) == NULL)
4580 if (!pXSMPRec->discardCommand)
4583 if (!StartClient (pXSMPRec->discardCommand[0],
4584 pXSMPRec->discardCommand,
4585 pXSMPRec->clientHost,
4587 pXSMPRec->environment,
4590 pXSMPRec->screenNum)) {
4591 str = strdup ((char *) GETMESSAGE (40, 27,
4592 "An attempt to execute the 'DiscardCommand' property for\napplication '%s' failed."));
4595 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, str,
4600 FreeXSMPClientDBRec (pXSMPRec);
4603 (void) CloseClientDB (inputDB, False);
4608 CheckRequiredProperties (
4609 XSMPClientDBRecPtr pDbRec,
4610 char * databaseName)
4612 Boolean propsOK = True;
4614 if (!pDbRec->program) {
4615 LogMissingPropertyMessage (pDbRec, SmProgram,
4616 databaseName, DtMsgLogError);
4620 if (!pDbRec->restartCommand) {
4621 LogMissingPropertyMessage (pDbRec, SmRestartCommand,
4622 databaseName, DtMsgLogError);
4631 CheckRequiredFields (
4632 ProxyClientDBRecPtr pDbRec,
4633 char * databaseName,
4638 if (!pDbRec->command) {
4640 message = strdup ((char *) GETMESSAGE (40, 11,
4641 "The required resource '%s' is missing for client '%d'\nin the file '%s'."));
4646 DtMsgLogMessage (smGD.programName, DtMsgLogError, message,
4647 SmProgram, clientNum, databaseName);
4659 LogXSMPOpenDatabaseFailure (
4660 char * databaseName,
4661 DtMsgLogType msgType,
4664 char * message = NULL;
4669 case 1: data = databaseName;
4671 message = strdup ((char *) GETMESSAGE (40, msgNum,
4672 "The following session database could not be opened:\n\n '%s'"));
4675 case 2: data = versionStr;
4677 message = strdup ((char *) GETMESSAGE (40, msgNum,
4678 "The following session database does not contain\nthe required resource '%s':\n\n %s"));
4681 case 3: data = dtsessionIDStr;
4683 message = strdup ((char *) GETMESSAGE (40, msgNum,
4684 "The following session database does not contain\nthe required resource '%s':\n\n %s"));
4692 DtMsgLogMessage (smGD.programName, msgType, message, data);
4694 DtMsgLogMessage (smGD.programName, msgType, message,
4695 data, databaseName);
4702 LogMissingPropertyMessage (
4703 XSMPClientDBRecPtr pDbRec,
4705 char * databaseName,
4706 DtMsgLogType msgType)
4710 message = strdup ((char *) GETMESSAGE (40, 10,
4711 "The required property '%s' is missing for client\n\n %s\n\nin the file '%s'."));
4716 DtMsgLogMessage (smGD.programName, msgType, message,
4717 propName, pDbRec->clientId, databaseName);
4731 message = strdup ((char *) GETMESSAGE (40, 12,
4732 "The directory '%s'\nis not available for application '%s'.\n\nThe following directory will be used:\n\n %s"));
4737 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, message,
4738 badDir, appName, goodDir);
4745 char ** RemoveEnvironmentVars (
4749 char ** retEnv = NULL;
4750 char **ppchar, **ppchar2;
4757 for (count = 0, ppchar = envp; ppchar && *ppchar; count++, *ppchar++) ;
4759 retEnv = (char **) XtMalloc ((count + 1) * sizeof (char *));
4763 if (!ignoreEnvPtr) {
4764 for (count = 0, ppchar = envp; ppchar && *ppchar;
4765 count++, *ppchar++) {
4766 retEnv[count] = *ppchar;
4768 retEnv[count] = NULL;
4773 for (count = 0, ppchar = envp; ppchar && *ppchar; *ppchar++) {
4777 for (ppchar2 = ignoreEnvPtr; ppchar2 && *ppchar2; *ppchar2++) {
4779 if ((!strncmp (*ppchar, *ppchar2, strlen (*ppchar2))) &&
4780 (((*ppchar)[strlen(*ppchar2)]) == '=')) {
4786 retEnv[count] = *ppchar;
4790 retEnv[count] = NULL;
4796 * MarkFileDescriptors - mark file descriptiors start_fd through open_max
4797 * with the given "cmd" and "data".
4799 * The code for calculating open_max was taken from DtSvc/DtUtil1/CmdMain.c
4802 MarkFileDescriptors (
4810 open_max = sysconf(_SC_OPEN_MAX);
4812 if (open_max == -1) {
4816 #if defined(USL) || defined(__uxp__) || defined(_AIX)
4817 open_max = FOPEN_MAX;
4819 open_max = FD_SETSIZE;
4821 #endif /* _SUN_OS */
4824 for (i = start_fd; i < open_max; i++)
4825 (void) fcntl (i, cmd, data);