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 *************************************<+>*************************************/
62 #ifdef _SUN_OS /* to get the define for NOFILE */
63 #include <sys/param.h>
65 #include <sys/types.h>
68 #include <X11/apollosys.h> /* for pid_t struct in hp-ux sys/types.h */
70 #include <sys/socket.h>
72 #include <netinet/in.h>
77 #include <X11/Intrinsic.h>
78 #include <X11/Xutil.h>
79 #include <X11/Xatom.h>
80 #include <X11/StringDefs.h>
81 #include <X11/keysymdef.h>
82 #include <X11/SM/SMlib.h>
86 # define Va_start(a,b) va_start(a,b)
89 #include <Dt/Message.h>
90 #include <Dt/CommandM.h>
91 #include <Dt/Connect.h>
94 #include <Dt/UserMsg.h>
95 #include <Dt/SessionM.h>
96 #include <Dt/EnvControlP.h>
97 #include <Dt/Utility.h>
98 #include <Dt/MsgLog.h>
100 #include <Dt/CmdInv.h>
101 #include <Dt/ActionUtilP.h>
104 #include "SmResource.h"
106 #include "SmCommun.h"
107 #include "SmRestore.h"
108 #include "SmProtocol.h"
109 #include "SmConMgmt.h"
112 #include "SmGlobals.h"
118 #include <X11/Xlibint.h>
124 static const char * DISPLAY_NAME_EQUAL = "DISPLAY=";
125 static const char * DISPLAY_NAME = "DISPLAY";
126 static char * savedDisplay = NULL;
132 #define MAXPATHSM 1023
133 #define MAX_QUOTE_DEPTH 10
135 #define SM_MAX_ARGS MAXLINE
137 #if defined (SVR4) || defined (__osf__)
138 #define REMOTE_CMD_STRING "rsh %s -n %s &"
140 #define REMOTE_CMD_STRING "remsh %s -n %s &"
149 unsigned char *hostPtr;
150 unsigned char *cmdPtr;
154 * Variables global to this module only
156 static XtResource settingsResources[] =
158 {SmNaccelNum, SmCaccelNum, XtRInt, sizeof(int),
159 XtOffset(SessionSettingsPtr, accelNum),
160 XtRImmediate, (XtPointer) -1},
161 {SmNaccelDenom, SmCaccelDenom, XtRInt, sizeof(int),
162 XtOffset(SessionSettingsPtr, accelDenom),
163 XtRImmediate, (XtPointer) -1},
164 {SmNthreshold, SmCthreshold, XtRInt, sizeof(int),
165 XtOffset(SessionSettingsPtr, threshold),
166 XtRImmediate, (XtPointer) -1},
168 {SmNtimeout, SmCtimeout, XtRInt, sizeof(int),
169 XtOffset(SessionSettingsPtr, timeout),
170 XtRImmediate, (XtPointer) -1},
171 {SmNinterval, SmCinterval, XtRInt, sizeof(int),
172 XtOffset(SessionSettingsPtr, interval),
173 XtRImmediate, (XtPointer) -1},
174 {SmNpreferBlank, SmCpreferBlank, XtRInt, sizeof(int),
175 XtOffset(SessionSettingsPtr, preferBlank),
176 XtRImmediate, (XtPointer) 0},
177 {SmNallowExp, SmCallowExp, XtRInt, sizeof(int),
178 XtOffset(SessionSettingsPtr, allowExp),
179 XtRImmediate, (XtPointer) 0},
181 {SmNfontPath, SmCfontPath, XtRString, sizeof(String),
182 XtOffset(SessionSettingsPtr, fontDirs), XtRString, (XtPointer) ""},
184 {SmNkeyClick, SmCkeyClick, XtRInt, sizeof(int),
185 XtOffset(SessionSettingsPtr, kbdState.key_click_percent),
186 XtRImmediate, (XtPointer) -1},
187 {SmNbellPercent, SmCbellPercent, XtRInt, sizeof(int),
188 XtOffset(SessionSettingsPtr, kbdState.bell_percent),
189 XtRImmediate, (XtPointer) -1},
190 {SmNbellPitch, SmCbellPitch, XtRInt, sizeof(int),
191 XtOffset(SessionSettingsPtr, kbdState.bell_pitch),
192 XtRImmediate, (XtPointer) -1},
193 {SmNbellDuration, SmCbellDuration, XtRInt, sizeof(int),
194 XtOffset(SessionSettingsPtr, kbdState.bell_duration),
195 XtRImmediate, (XtPointer) -1},
196 {SmNledMask, SmCledMask, XtRInt, sizeof(int),
197 XtOffset(SessionSettingsPtr, kbdState.led_mask),
198 XtRImmediate, (XtPointer) 0},
199 {SmNglobalRepeats, SmCglobalRepeats, XtRInt, sizeof(int),
200 XtOffset(SessionSettingsPtr, kbdState.global_auto_repeat),
201 XtRImmediate, (XtPointer) 2},
202 {SmNautoRepeats, SmCautoRepeats, XtRString, sizeof(String),
203 XtOffset(SessionSettingsPtr, autoRepeats), XtRString, (XtPointer) ""},
205 {SmNbuttonMap, SmCbuttonMap, XtRString, sizeof(String),
206 XtOffset(SessionSettingsPtr, buttonMap), XtRString, (XtPointer) ""},
208 {SmNnumKeyCode, SmCnumKeyCode, XtRInt, sizeof(int),
209 XtOffset(SessionSettingsPtr, numKeyCode), XtRImmediate, (XtPointer) 0},
210 {SmNkeySymsPerKey, SmCkeySymsPerKey, XtRInt, sizeof(int),
211 XtOffset(SessionSettingsPtr, keySymPerCode),
212 XtRImmediate, (XtPointer) 0},
213 {SmNkeySyms, SmCkeySyms, XtRString, sizeof(String),
214 XtOffset(SessionSettingsPtr, keySyms), XtRString, (XtPointer) ""},
216 {SmNmaxKeyPerMod, SmCmaxKeyPerMod, XtRInt, sizeof(int),
217 XtOffset(SessionSettingsPtr, maxKeyPerMod),
218 XtRImmediate, (XtPointer) 0},
219 {SmNmodMap, SmCmodMap, XtRString, sizeof(String),
220 XtOffset(SessionSettingsPtr, modSyms),
221 XtRString, (XtPointer) ""},
223 {SmNdidQuerySettings, SmCdidQuerySettings, XtRBoolean, sizeof(Boolean),
224 XtOffset(SessionSettingsPtr, didQuery),
225 XtRImmediate, (XtPointer) False},
226 {SmNshutDownState, SmCshutDownState, XtRInt, sizeof(int),
227 XtOffset(SessionSettingsPtr, confirmMode),
228 XtRImmediate, (XtPointer) 1},
229 {SmNshutDownMode, SmCshutDownMode, XtRInt, sizeof(int),
230 XtOffset(SessionSettingsPtr, startState),
231 XtRImmediate, (XtPointer) 4},
235 * Variables used for parsing code
238 static unsigned char fallBackLine[MAXLINE+2]; /* line buffer */
239 static unsigned char *line; /* line buffer */
240 static FILE *cfileP = NULL; /* fopen'ed configuration file or NULL */
241 static int linec = 0; /* line counter for parser */
242 static unsigned char *parseP = NULL; /* pointer to parse string */
243 static int fileSize = 0;
244 char **smExecArray = NULL;
247 * Variables used for remote execution
249 static int numRemoteExecs = 0;
250 unsigned char *remoteBuf[MAX_SCREENS_SAVED];
251 unsigned int actRemoteSize[MAX_SCREENS_SAVED];
252 RemoteReq remoteBufPtr[MAX_REMOTE_CLIENTS];
253 static char localHost[MAXHOSTNAMELEN];
254 static char ** ignoreEnvPtr = NULL;
257 * Timeout for workspace manager handshake
259 static Boolean wmTimeout;
262 * These lines were added to support the builtin
266 char tmpExecWmFile[MAXPATHSM+1];
267 static Boolean localWmLaunched = False;
270 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
271 * End of lines were added to support the builtin
286 "*XmTextField*FontList",
287 "*DtEditor*textFontList",
292 static char *fontclass[] = {
300 "*XmTextField*FontList",
301 "*DtEditor*textFontList",
310 static int RestoreSettings( void ) ;
311 static int RestoreClients( void ) ;
312 static unsigned char * GetNextLine( void ) ;
313 static unsigned int PeekAhead( unsigned char *, unsigned int ) ;
314 static unsigned char * GetSmartString( unsigned char **) ;
315 static void ForkWM( void ) ;
316 static int FillCmdBuf( unsigned char *, unsigned char **,
317 unsigned int *, unsigned int *,
318 unsigned int, unsigned int *) ;
319 static int FillRemoteBuf( unsigned char *, unsigned char *,
320 unsigned char *, unsigned char **,
321 unsigned int *, unsigned int *, unsigned int) ;
322 static int FillHintBuf(unsigned char *, unsigned char **,
323 unsigned int *, unsigned int *,
324 unsigned int, unsigned int *);
325 static void WaitForWM( void ) ;
326 static void HandleWMClientMessage(Widget smWidget, XtPointer dummy,
328 static void WaitWMTimeout( XtPointer , XtIntervalId *) ;
329 static void FixEnvironmentData( void ) ;
330 static void ResetScreenInfo(unsigned char **,
331 int *, unsigned int *,
334 static void RemoteRequestFailed(char *, void *);
335 static void RemoteRequestSucceeded(char *, void *);
337 static void SetTemporaryDisplay (
340 int RestorePreferences(char *filename);
342 static void RestoreDisplay (
345 static Boolean StartLocalClient (
351 Boolean useIgnoreEnvResource);
353 static Boolean StartRemoteClient (
359 Boolean useIgnoreEnvResource);
361 static Boolean CheckRequiredProperties (
362 XSMPClientDBRecPtr pDbRec,
363 char * databaseName);
365 static Boolean CheckRequiredFields (
366 ProxyClientDBRecPtr pDbRec,
370 static void LogXSMPOpenDatabaseFailure (
372 DtMsgLogType msgType,
375 static void LogMissingPropertyMessage (
376 XSMPClientDBRecPtr pDbRec,
379 DtMsgLogType msgType);
381 static void LogCWDMessage (
386 static char ** RemoveEnvironmentVars (
389 static void MarkFileDescriptors (
395 /*************************************<->*************************************
402 * Sets _DT_SM_STATE_INFO for dtstyle indicating compatibility mode
415 * The only thing dtstyle should be looking at is the compatMode
417 *************************************<->***********************************/
419 SetCompatState( void )
424 * BEFORE any clients are started
425 * set a property on the top level window
426 * which lets the style manager know what state the sm is in
428 state.flags = SM_STATE_ALL;
429 state.smStartState = 0;
430 state.smConfirmMode = 0;
431 state.smCompatMode = True;
432 state.smSendSettings = False;
433 state.smCoverScreen = True;
434 state.smLockOnTimeoutStatus = smGD.lockOnTimeoutStatus;
435 state.smCycleTimeout = 0;
436 state.smLockTimeout = 0;
437 state.smSaverTimeout = 0;
439 state.smDisplaySpecific = smGD.displaySpecific;
441 _DtSetSmState(smGD.display, smGD.topLevelWindow, &state);
443 XFlush(smGD.display);
447 } /* END OF FUNCTION SetCompatState */
450 /*************************************<->*************************************
457 * This function fiddles with our signal handling and calls the
458 * system() function to invoke a unix command.
463 * pchCmd = string with the command we want to exec.
471 * The system() command is touchy about the SIGCLD behavior. Restore
472 * the default SIGCLD handler during the time we run system().
474 *************************************<->***********************************/
477 SystemCmd (char *pchCmd)
479 void (*signalHandler) ();
481 signalHandler = (void (*)())signal (SIGCHLD, SIG_DFL);
485 signal (SIGCHLD, signalHandler);
486 } /* END OF FUNTION SystemCmd */
490 /*************************************<->*************************************
506 * When this routine is finished, all settings and resources will be restored.
507 * Clients may not be, as they are actually restored by different processes.
509 *************************************<->***********************************/
515 char convertCommand[MAXPATHSM+1];
517 Boolean fixedBuffer = False;
520 Boolean useXrmDB = False;
523 * Restore all the X settings which were active at the time of shutdown
527 if (smGD.sessionType == HOME_SESSION)
528 smSettings.startState = DtSM_HOME_STATE;
530 smSettings.startState = DtSM_CURRENT_STATE;
533 * BEFORE any clients are started
534 * set a property on the top level window
535 * which lets the style manager know what state the sm is in
537 state.flags = SM_STATE_ALL;
538 state.smStartState = smSettings.startState;
539 state.smConfirmMode = smSettings.confirmMode;
540 state.smCompatMode = smGD.compatMode;
541 state.smSendSettings = !smRes.querySettings;
542 state.smLockOnTimeoutStatus = smGD.lockOnTimeoutStatus;
543 state.smCycleTimeout = smSaverRes.cycleTimeout;
544 state.smLockTimeout = smSaverRes.lockTimeout;
545 state.smSaverTimeout = smSaverRes.saverTimeout;
546 state.smRandom = smSaverRes.random;
547 state.smDisplaySpecific = smGD.displaySpecific;
549 _DtSetSmState(smGD.display, smGD.topLevelWindow, &state);
551 saver.saverList = smGD.saverList;
552 _DtSetSmSaver(smGD.display, smGD.topLevelWindow, &saver);
555 * Set up the Property telling all applications what session is being
558 XaSmRestoreMode = XInternAtom(smGD.display, _XA_DT_RESTORE_MODE, False);
559 XChangeProperty(smGD.display, RootWindow(smGD.display, 0),
560 XaSmRestoreMode, XA_STRING, 8, PropModeReplace,
561 (unsigned char *)smGD.restoreSession, strlen(smGD.restoreSession));
562 XFlush(smGD.display);
565 * Check the session database and either parse it as an
566 * Xrm-database or the CDE1.0 format
568 if ((pchar = strrchr (smGD.clientPath, '/')) != NULL)
571 if ((*pchar != '\0') && (!strcmp (pchar, SM_CLIENT_FILE2)))
577 return (StartXSMPSession (smGD.clientPath));
581 * Malloc line for parsing.
583 status = stat(smGD.clientPath, &buf);
586 fileSize = buf.st_size;
589 if (fileSize < MAXLINE + 1)
591 fileSize = MAXLINE + 1;
594 line = malloc(fileSize + 1);
598 fileSize = MAXLINE + 1;
601 cfileP = fopen(smGD.clientPath, "r");
604 PrintErrnoError(DtError, smNLS.cantOpenFileString);
605 if (!fixedBuffer && line)
607 SM_FREE((char *)line);
614 if (!fixedBuffer && line)
616 SM_FREE((char *)line);
625 /*************************************<->*************************************
632 * Start up the window manager. The default is to start dtmwm unless
633 * another one is specified in a resource.
646 * When this routine is finished, all settings and resources will be restored.
647 * Clients may not be, as they are actually restored by different processes.
649 *************************************<->***********************************/
653 char wmStartupErrorString[(2 * MAXPATHSM) + 1];
654 char localWmErrorString[(2 * MAXPATHSM) + 1];
655 Boolean goodWmStartup = True;
658 if((smGD.wmStartup == NULL) || (*smGD.wmStartup == 0))
664 CreateExecString(smGD.wmStartup);
667 * check to see if the wmStartup string exists and is
670 status = access(smExecArray[0], F_OK | X_OK);
673 goodWmStartup = False;
674 CreateExecString(CDE_INSTALLATION_TOP "/bin/dtwm");
677 if(smExecArray[0] != NULL)
679 (void) StartClient(smExecArray[0], smExecArray, NULL, NULL,
680 NULL, False, False, -1);
685 * We used to start the message server before the window
686 * manager and then if the message server did not start
687 * we would exit. Now we start the window manager, then
688 * start the message server and then wait for the window
689 * manager. This seems to improve performance.
694 if (goodWmStartup == False)
696 sprintf(wmStartupErrorString, GETMESSAGE(16, 7,
697 "The wmStartupCommand resource is set to:\n\n"
699 "This file does not exist or is not executable.\n"
700 CDE_INSTALLATION_TOP "/bin/dtwm will be started "
703 PrintError(DtError, wmStartupErrorString);
709 * These lines were added to support the builtin
713 if (localWmLaunched && wmTimeout)
715 if (!smGD.userSetWaitWmTimeout)
717 smRes.waitWmTimeout = smGD.savedWaitWmTimeout;
720 localWmLaunched = False;
722 * A special version of a built-in Xterminal dtwm
723 * was attempted and failed.
724 * Try to launch .../dt/bin/dtwm instead
727 CreateExecString(CDE_INSTALLATION_TOP "/bin/dtwm");
728 if(smExecArray[0] != NULL)
730 (void) StartClient(smExecArray[0], smExecArray, NULL,
731 NULL, NULL, False, False, -1);
734 sprintf(localWmErrorString, GETMESSAGE(16, 9,
735 "The following window manager did not start:\n\n"
737 "This message indicates you tried to start a\n"
738 "window manager that is built into an X terminal.\n"
739 "This will only work with X terminals that support this protocol.\n"
740 CDE_INSTALLATION_TOP "/bin/dtwm will be started instead.\n"),
742 PrintError(DtError, localWmErrorString);
745 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
746 * End of lines were added to support the builtin
755 /*************************************<->*************************************
762 * Reloads RESOURCE_MANAGER during running session
774 *************************************<->***********************************/
777 ReloadResources(void)
780 * Load sys.resources and .Xdefaults
782 RestoreResources(True,
789 * Merge _DT_SM_PREFERENCES
791 RestorePreferences(NULL);
797 /*************************************<->*************************************
799 * RestoreResources (errorHandlerInstalled, options ... )
804 * Calls routines responsible for restoring resources.
805 * Resources are restored by a fork and exec of dtsession_res.
818 * When this routine is finished, all settings and resources will be restored.
819 * Clients may not be, as they are actually restored by different processes.
821 *************************************<->***********************************/
824 RestoreResources( Boolean errorHandlerInstalled, ... )
827 int childStatus, execStatus, i;
833 /* JET - this seems like a bad (and unused) idea */
835 * Check for alternate resource loader.
837 if ((pgrm = getenv("DTLOADRESOURCES")) == NULL)
839 pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
842 pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
846 * By convention, exec() wants arg0 to be the program name. Ex: if pgrm
847 * is /usr/dt/bin/dtsession_res, the program name is dtsession_res.
848 * If all else fails, use pgrm.
850 argv[0] = (p = strrchr(pgrm, '/')) != NULL && *(p+1) != '\0' ? p+1 : pgrm;
853 Va_start(args,errorHandlerInstalled);
857 argv[i] = va_arg(args, char *);
863 * if an error handler is installed - remove it
865 if(errorHandlerInstalled)
867 sigaction(SIGCHLD, &smGD.defvec, (struct sigaction *) NULL);
871 * Fork and exec the xrdb process to load in the file created by
872 * writing out the resource manager string generated by the last
873 * session termination.
876 for(i = 0;(i < 10) && ((forkrc = vfork()) < 0);i++)
887 PrintErrnoError(DtError, smNLS.cantForkClientString);
892 * Fork succeeded - now do the exec
896 SetSIGPIPEToDefault ();
900 * Set the gid of the process back from bin
903 setregid(smGD.runningGID, smGD.runningGID);
905 setgid(smGD.runningGID);
906 setegid(smGD.runningGID);
909 #if defined(__osf__) || defined(CSRG_BASED)
915 MarkFileDescriptors (3, F_SETFD, 1);
917 execStatus = execv(pgrm, argv);
921 char clientMessage[MAXPATHLEN + 256];
923 memset(clientMessage, 0, MAXPATHLEN + 256);
924 snprintf(clientMessage, (MAXPATHLEN + 256) - 1,
925 ((char *)GETMESSAGE(16, 1, "Unable to exec process %s. No session resources will be restored.")), pgrm);
926 PrintErrnoError(DtError, clientMessage);
931 while(wait(&childStatus) != forkrc);
934 * if an error handler is installed - remove it
936 if(errorHandlerInstalled)
938 sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
945 /*************************************<->*************************************
947 * RestorePreferences ( filename)
953 * This routine has two roles:
955 * 1) If 'filename' specified, the content of filename is read, and
956 * _DT_SM_PREFERENCES is populated with its content. This is used
957 * at session startup to set the initial state of _DT_SM_PREFERENCES.
959 * 2) If 'filename' is NULL, the content of _DT_SM_PREFERENCES is
960 * merged into RESOURCE_MANAGER. This is used when resources are
961 * reloaded at user request during a session.
974 *************************************<->***********************************/
986 struct stat statinfo;
988 if(access(filename,R_OK) != 0)
994 * Determine size of file.
996 if (stat(filename, &statinfo) == -1)
1004 if ((data = (char *)SM_MALLOC(statinfo.st_size + 1)) == NULL)
1010 * Read file into memory.
1012 if ((fp = fopen(filename, "r")) == NULL)
1018 size = fread(data, 1, statinfo.st_size, fp);
1020 if (size == statinfo.st_size)
1023 * Merge .Xdefaults string into RESOURCE_MANAGER database, and
1024 * also convert to Xrm database form for later subtraction.
1027 _DtAddResString(smGD.display, data, _DT_ATR_PREFS);
1035 * Read string from _DT_SM_PREFERENCES
1037 data = _DtGetResString(smGD.display, _DT_ATR_PREFS);
1040 * Merge string into RESOURCE_MANAGER
1042 _DtAddResString(smGD.display, data, _DT_ATR_RESMGR);
1051 /*************************************<->*************************************
1053 * RestoreSettings ()
1058 * In charge of restoring all settings. Settings are stored in resource
1059 * format so it gets the values by getting the resource values stored in
1060 * a resource file that was created by the session manager.
1065 * smGD.settingPath = path that points to the settings resource file.
1074 * This routine messes with the actual strings returned by the resource
1075 * manager by tokenizing them, so these session settings resources should
1076 * not be accessed again.
1078 *************************************<->***********************************/
1080 RestoreSettings( void )
1082 XrmDatabase smBase = NULL;
1083 XKeyboardControl kbdControl;
1085 char **restorePtrArray, **tmpRestore;
1086 char *restoreCharArray;
1087 int numArgs, ptrSize, charSize;
1090 KeySym *tmpSyms, codeSym;
1093 XModifierKeymap restoreMod;
1097 restorePtrArray = (char **) SM_MALLOC (ptrSize * sizeof(char *));
1098 restoreCharArray = (char *) SM_MALLOC (charSize * sizeof(char));
1099 if((restorePtrArray == NULL) || (restoreCharArray == NULL))
1101 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1103 if(restorePtrArray != NULL)
1105 SM_FREE((char *) restorePtrArray);
1109 if(restoreCharArray != NULL)
1111 SM_FREE(restoreCharArray);
1118 * Load the resources from the SM database file
1120 if (smGD.settingPath[0] != 0)
1122 smBase = XrmGetFileDatabase(smGD.settingPath);
1126 PrintError(DtError, GETMESSAGE(16, 2, "Invalid client settings file. No settings restored."));
1131 XrmMergeDatabases(smBase, &(smGD.display->db));
1136 * Retrieve the session settings file from the database
1138 XtGetApplicationResources(smGD.topLevelWid, (XtPointer) &smSettings,
1139 settingsResources, XtNumber(settingsResources),
1143 * Copy any string resources since they may be overwritten in
1146 smGD.fontDirs = SmNewString(smSettings.fontDirs);
1147 smGD.autoRepeats = SmNewString(smSettings.autoRepeats);
1148 smGD.buttonMap = SmNewString(smSettings.buttonMap);
1149 smGD.keySyms = SmNewString(smSettings.keySyms);
1150 smGD.modSyms = SmNewString(smSettings.modSyms);
1154 * This is provided for backward compatibility sake. The values that
1155 * confirmMode can take have changed
1157 if(smSettings.confirmMode == DtSM_ASK_STATE)
1159 smSettings.confirmMode = DtSM_VERBOSE_MODE;
1163 * If the user has previously used the "query" method, and now wishes
1164 * to use "only what I've customized" method, then we have to start
1165 * from scratch. So don't set anything until customizer tells me to
1167 if((smSettings.didQuery == True) && (smRes.querySettings == False))
1169 SM_FREE((char *) restorePtrArray);
1170 SM_FREE(restoreCharArray);
1175 * Restore pointer control settings
1177 if((smSettings.accelNum > -1 ) || (smSettings.threshold > -1))
1179 XChangePointerControl(smGD.display, True, True,
1180 smSettings.accelNum,
1181 smSettings.accelDenom,
1182 smSettings.threshold);
1183 smToSet.pointerChange = True;
1187 smToSet.pointerChange = False;
1191 * Restore screen saver settings if any are set to non-default
1194 if ((smSettings.timeout > -1) || (smSettings.interval > -1) ||
1195 (smSaverRes.saverTimeout > -1) || (smSaverRes.lockTimeout > -1) ||
1196 (smSaverRes.cycleTimeout > -1))
1200 * For the time between Screen Savers, use the cycleTimeout
1201 * if the user has set this value. Otherwise, use the interval
1202 * value that was set when the session was saved.
1204 if (smSaverRes.cycleTimeout < 0)
1206 screenSaverVals.smInterval = smSettings.interval;
1210 screenSaverVals.smInterval = smSaverRes.cycleTimeout;
1214 * For the screen saver time, use the minimum of the values set for
1215 * saverTimeout or lockTimeout if the user has set one of these
1218 * Otherwise, use the Timeout value that was set when the
1219 * session was saved.
1221 * If it is not set, then use the minimum of the values set for
1222 * saverTimeout or lockTimeout. Set timeout to the Timeout value
1225 if ((smSaverRes.saverTimeout > -1) ||
1226 (smSaverRes.lockTimeout > -1))
1228 if (smSaverRes.saverTimeout > -1)
1230 if ((smSaverRes.lockTimeout > -1) &&
1231 (smSaverRes.lockTimeout < smSaverRes.saverTimeout))
1233 screenSaverVals.smTimeout = smSaverRes.lockTimeout;
1237 screenSaverVals.smTimeout = smSaverRes.saverTimeout;
1242 screenSaverVals.smTimeout = smSaverRes.lockTimeout;
1247 screenSaverVals.smTimeout = smSettings.timeout;
1249 screenSaverVals.smPreferBlank = smSettings.preferBlank;
1250 screenSaverVals.smAllowExp = smSettings.allowExp;
1252 /* Notify X of the new screen saver values */
1253 XSetScreenSaver(smGD.display, screenSaverVals.smTimeout,
1254 screenSaverVals.smInterval,
1255 screenSaverVals.smPreferBlank,
1256 screenSaverVals.smAllowExp);
1259 * If using timeout or interval values that were
1260 * previously saved, then set flag to indicate that they
1261 * should be saved again when the state for the session
1264 if ((smSettings.timeout > -1) || (smSettings.interval > -1))
1266 smToSet.screenSavChange = True;
1270 smToSet.screenSavChange = False;
1276 smToSet.screenSavChange = False;
1280 * Get the font path. Then set it.
1282 tmpRestore = restorePtrArray;
1284 *tmpRestore = strtok(smGD.fontDirs, ",");
1286 while(*tmpRestore != NULL)
1288 numArgs++; tmpRestore++;
1289 *tmpRestore = strtok(NULL, ",");
1290 if((numArgs >= ptrSize) && (*tmpRestore != NULL))
1293 restorePtrArray = (char **)SM_REALLOC((char *)
1294 restorePtrArray, ptrSize *
1296 if(restorePtrArray == NULL)
1298 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1299 SM_FREE(restoreCharArray);
1307 XSetFontPath(smGD.display, restorePtrArray, numArgs);
1311 * Restore the keyboard control information. In order for it
1312 * to be restored it has to be changed from a XKeyboardState
1313 * format to an XKeyboardControl format.
1315 if((smSettings.kbdState.key_click_percent > -1) ||
1316 (smSettings.kbdState.bell_percent > -1) ||
1317 (smSettings.kbdState.bell_pitch > -1) ||
1318 (smSettings.kbdState.bell_duration > -1))
1322 if((smSettings.kbdState.bell_percent > -1) ||
1323 (smSettings.kbdState.bell_pitch > -1) ||
1324 (smSettings.kbdState.bell_duration > -1))
1326 kbdControl.bell_percent = smSettings.kbdState.bell_percent;
1327 kbdControl.bell_pitch = smSettings.kbdState.bell_pitch;
1328 kbdControl.bell_duration = smSettings.kbdState.bell_duration;
1329 kbdControlMask |= (KBBellPercent | KBBellPitch | KBBellDuration);
1330 smToSet.audioChange = True;
1331 audioVals.smBellPercent = smSettings.kbdState.bell_percent;
1332 audioVals.smBellPitch = smSettings.kbdState.bell_pitch;
1333 audioVals.smBellDuration = smSettings.kbdState.bell_duration;
1337 smToSet.audioChange = False;
1340 if((smSettings.kbdState.key_click_percent > -1) ||
1341 (smSettings.kbdState.global_auto_repeat != AutoRepeatModeOn))
1343 kbdControl.key_click_percent =
1344 smSettings.kbdState.key_click_percent;
1345 kbdControlMask |= KBKeyClickPercent;
1346 smToSet.keyboardChange = True;
1347 keyboardVals.smKeyClickPercent = kbdControl.key_click_percent;
1351 smToSet.keyboardChange = False;
1356 * NOTICE THAT THE LED'S DON'T GET RESET. THIS IS BECAUSE LED STUFF
1357 * IS MACHINE DEPENDENT.
1360 * Set the auto repeat stuff
1362 tmpKey = strtok(smGD.autoRepeats, ",");
1363 if((tmpKey == NULL) &&
1364 ((smSettings.kbdState.global_auto_repeat == AutoRepeatModeOff) ||
1365 (smSettings.kbdState.global_auto_repeat == AutoRepeatModeOn)))
1367 smToSet.keyboardChange = True;
1368 kbdControl.auto_repeat_mode =
1369 smSettings.kbdState.global_auto_repeat;
1370 kbdControlMask |= KBAutoRepeatMode;
1371 XChangeKeyboardControl(smGD.display, kbdControlMask, &kbdControl);
1372 keyboardVals.smGlobalAutoRepeat =
1373 smSettings.kbdState.global_auto_repeat;
1379 smToSet.keyboardChange = True;
1380 kbdControl.auto_repeat_mode = smSettings.kbdState.global_auto_repeat;
1381 kbdControlMask |= KBAutoRepeatMode;
1382 XChangeKeyboardControl(smGD.display,
1383 kbdControlMask, &kbdControl);
1384 kbdControl.auto_repeat_mode = AutoRepeatModeOn;
1385 kbdControlMask = KBAutoRepeatMode | KBKey;
1387 * This is only involked when there is auto repeats set for
1388 * specific keys only. It is VERY SLOW code so unless you
1389 * have to save off auto repeats for single keys - DONT
1391 while(tmpKey != NULL)
1393 kbdControl.key = atoi(tmpKey);
1394 XChangeKeyboardControl(smGD.display,
1395 kbdControlMask, &kbdControl);
1396 tmpKey = strtok(NULL, ",");
1401 if(kbdControlMask != 0)
1403 XChangeKeyboardControl(smGD.display,
1404 kbdControlMask, &kbdControl);
1411 smToSet.audioChange = False;
1412 smToSet.keyboardChange = False;
1416 * Restore the button mappings
1419 tmpKey = strtok(smGD.buttonMap, ",");
1423 smToSet.pointerMapChange = True;
1427 smToSet.pointerMapChange = False;
1430 while(tmpKey != NULL)
1432 restoreCharArray[numArgs] = (char) atoi(tmpKey);
1434 tmpKey = strtok(NULL, ",");
1435 if((numArgs >= charSize) && (tmpKey != NULL))
1438 restoreCharArray = (char *) SM_REALLOC(restoreCharArray,
1439 charSize * sizeof(char));
1440 if(restoreCharArray == NULL)
1442 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1443 SM_FREE((char *)restorePtrArray);
1451 XSetPointerMapping(smGD.display, (unsigned char *)restoreCharArray, numArgs);
1454 * Copy the pointer map into the saved map for logout
1456 smToSet.numButton = ((numArgs > 5) ? 5 : numArgs);
1457 for(i = 0; i < smToSet.numButton;i++)
1459 smToSet.pointerMap[i] = restoreCharArray[i];
1464 * Restore the key mappings
1466 if(smSettings.numKeyCode > 0)
1468 tmpSyms = (KeySym *) restoreCharArray;
1469 symSize = (charSize * sizeof(char)) / sizeof(KeySym);
1470 tmpKey = strtok(smGD.keySyms, ",");
1471 for(i = 0;tmpKey != NULL;i++)
1473 tmpSyms[i] = (KeySym) atol(tmpKey);
1474 tmpKey = strtok(NULL, ",");
1476 if((numArgs >= symSize) && (tmpKey != NULL))
1479 symSize = (charSize * sizeof(char))/sizeof(KeySym);
1480 restoreCharArray = (char *) SM_REALLOC(restoreCharArray,
1481 (charSize * sizeof(char)));
1482 if(restoreCharArray == NULL)
1484 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1485 SM_FREE((char *) restorePtrArray);
1488 tmpSyms = (KeySym *) restoreCharArray;
1491 numArgs /= smSettings.keySymPerCode;
1492 XChangeKeyboardMapping(smGD.display, (KeyCode)
1493 smGD.display->min_keycode,
1494 smSettings.keySymPerCode, tmpSyms,
1499 * Restore the modifier mappings
1501 tmpCode = (KeyCode *) restoreCharArray;
1502 tmpKey = strtok(smGD.modSyms, ",");
1505 for(i = 0;i < (8 * smSettings.maxKeyPerMod);i++)
1509 codeSym = (KeySym) atol(tmpKey);
1512 tmpCode[i] = XKeysymToKeycode(smGD.display, codeSym);
1516 tmpCode[i] = (KeyCode) 0;
1521 tmpCode[i] = (KeyCode) 0;
1523 tmpKey = strtok(NULL, ",");
1525 restoreMod.max_keypermod = smSettings.maxKeyPerMod;
1526 restoreMod.modifiermap = tmpCode;
1527 XSetModifierMapping(smGD.display, &restoreMod);
1530 SM_FREE((char *) restorePtrArray);
1531 SM_FREE(restoreCharArray);
1538 /*************************************<->*************************************
1540 * RestoreIndependentResources ()
1545 * In charge of restoring the resources that help make the session more
1546 * resolution and language independent - only restored if they are
1547 * necessary (lang || resolution has changed) and exist
1552 * smResources = global pointer to the resources to be restored by the SM
1562 *************************************<->***********************************/
1564 RestoreIndependentResources( void )
1568 unsigned long nitems, leftover;
1569 unsigned char *data = NULL;
1571 XrmValue fontResourceReturn;
1572 char *currentLangPtr, *resValRet, *sessionType;
1574 int intYRes[2], status,i;
1577 Boolean resIndep = False, resRet;
1580 if(((smGD.sessionLang == NULL) || (*smGD.sessionLang == 0)) &&
1581 (smRes.displayResolution == 0))
1584 * No saved info to draw from - nothing new is added
1589 currentLangPtr = getenv("LANG");
1591 fltYRes = ((float) DisplayHeight(smGD.display, 0) /
1592 (float) DisplayHeightMM(smGD.display, 0)) * 1000;
1594 if(fltYRes < MED_RES_Y_RES)
1596 intYRes[0] = LOW_RES_Y_RES;
1597 sessionRes = SM_LOW_RES_EXT;
1601 if(fltYRes >= HIGH_RES_Y_RES)
1603 intYRes[0] = HIGH_RES_Y_RES;
1604 sessionRes = SM_HIGH_RES_EXT;
1608 intYRes[0] = MED_RES_Y_RES;
1609 sessionRes = SM_MED_RES_EXT;
1613 if(smRes.displayResolution < MED_RES_Y_RES)
1615 intYRes[1] = LOW_RES_Y_RES;
1619 if(smRes.displayResolution >= HIGH_RES_Y_RES)
1621 intYRes[1] = HIGH_RES_Y_RES;
1625 intYRes[1] = MED_RES_Y_RES;
1630 * If the resolution or the language has changed -
1631 * load the language/resolution independent fonts if
1632 * they exist in the users home directory or in the system
1634 if((strcmp(currentLangPtr, smGD.sessionLang)) ||
1635 (intYRes[0] != intYRes[1]))
1637 char *fontPath = SM_MALLOC(MAXPATHLEN + 1);
1639 if(smGD.sessionType == HOME_SESSION)
1641 sessionType = SM_HOME_FONT_DIRECTORY;
1645 sessionType = SM_CURRENT_FONT_DIRECTORY;
1648 memset(fontPath, 0, MAXPATHLEN + 1);
1649 snprintf(fontPath, MAXPATHLEN, "%s/%s/%s/%s.%s",
1650 smGD.savePath, sessionType,
1651 currentLangPtr, SM_FONT_FILE, sessionRes);
1652 status = stat(fontPath, &buf);
1656 * User has nothing there - look in the system defaults
1657 * first in the language dep -then in lang independent
1659 memset(fontPath, 0, MAXPATHLEN + 1);
1661 if((currentLangPtr != NULL) && (*currentLangPtr != 0))
1663 strcat(fontPath, "/");
1664 strncat(fontPath, currentLangPtr, MAXPATHLEN);
1667 strncat(fontPath, "/", MAXPATHLEN);
1668 strncat(fontPath, SM_SYSTEM_FONT_FILE, MAXPATHLEN);
1672 status = stat(fontPath, &buf);
1675 if((currentLangPtr != NULL) && (*currentLangPtr != 0) &&
1676 (strcmp(currentLangPtr, "C")))
1678 memset(fontPath, 0, MAXPATHLEN + 1);
1679 strcpy(fontPath, "/C/");
1680 strncat(fontPath, SM_SYSTEM_FONT_FILE, MAXPATHLEN);
1684 status = stat(fontPath, &buf);
1701 strncpy(smGD.fontPath, fontPath, MAXPATHLEN);
1703 if(resIndep == True)
1707 * add the auxillary resources onto the root window
1709 RestoreResources(True, "-merge", "-file", smGD.fontPath, NULL);
1712 * Load the resources from the RESOURCE_MANAGER
1713 * property on the root window
1715 if(XGetWindowProperty(smGD.display, RootWindow(smGD.display, 0),
1716 XA_RESOURCE_MANAGER,0L,
1717 100000000L,False,XA_STRING,&actualType,
1718 &actualFormat,&nitems,&leftover,
1719 (unsigned char**) &data) == Success)
1721 smBase = XrmGetStringDatabase((char *)data);
1730 PrintError(DtError, GETMESSAGE(16, 6, "Invalid display/language independent resource file. No display/language independent resources will be restored."));
1731 SM_FREE((char *)data);
1737 * Get the new fontlist from the resources and
1738 * Put it on the application shell. Then add
1739 * the auxillary resources into the display struct
1741 resRet = XrmGetResource(smBase, "*fontList", "*FontList",
1742 &resValRet, &fontResourceReturn);
1745 XtSetArg(uiArgs[i], XmNdefaultFontList,
1746 (XmFontList) fontResourceReturn.addr);i++;
1747 XtSetValues(smGD.topLevelWid, uiArgs, i);
1750 * Overwrite the old font preferences, otherwise,
1751 * they'll come back to haunt us if the user logs in again
1752 * under the current language. We need to get the font
1753 * resources which have just been loaded, then overlay
1754 * them onto the _DT_SM_PREFERENCES root property to make
1755 * sure we get them back when we login again.
1757 for (i = 0; i < XtNumber(fonttype); i++)
1759 resRet = XrmGetResource(smBase, fonttype[i], fontclass[i],
1760 &resValRet, &fontResourceReturn);
1764 (char *)SM_MALLOC(fontResourceReturn.size + 30);
1765 bzero(resdata, fontResourceReturn.size + 30);
1766 strcat(resdata, fonttype[i]);
1767 strcat(resdata, ": ");
1768 strcat(resdata, fontResourceReturn.addr);
1769 strcat(resdata, "\n");
1770 _DtAddResString(smGD.display, resdata, _DT_ATR_PREFS);
1775 XrmMergeDatabases(smBase, &(smGD.display->db));
1776 SM_FREE((char *)data);
1780 SM_FREE((char*) fontPath);
1787 /*************************************<->*************************************
1794 * Reads through the client file and restores its contents. A client file
1795 * consists of hints for the workspace manager, actual client commands, and
1796 * remote execution commands. All commands are processed accordingly.
1797 * If this is the first DT 3.0 session for a DT 2.0 user then we will
1798 * also launch the helpviewer. If this is the first DT 3.0 session for a
1799 * DT 2.0 user then we will also run convertVS.sh to change all
1800 * occurances of /usr/bin/X11/hpterm to .../dt/bin/hpterm,
1801 * /usr/bin/X11/xterm to .../dt/bin/xterm and
1802 * /usr/bin/X11/xload to .../dt/bin/xload.
1813 * Any information read from the client file will be mucked with during
1814 * processing, and should not try to be mucked with again.
1816 * WARNING: This routine closes cfileP - not the calling routine
1817 * DOUBLE-WARNING: This routine starts the window manager
1819 *************************************<->***********************************/
1821 RestoreClients( void )
1823 unsigned char *lineP, *string;
1824 char *pch, *dispPtr = NULL;
1825 char *dispEnv, *dispSav, *dispEnvHelpview, *dispSavHelpview;
1826 unsigned char *hostPtr=NULL, *cmdPtr=NULL, *hintPtr = NULL;
1827 unsigned char *remoteDisplay;
1830 unsigned char tmpChar[35];
1831 int screenNum = 0, i, j, chlen, numClientsExec;
1832 int numRemoteDone = 0;
1834 Boolean clientsDone = False, wmHandshake = False, cmdInvInit = False;
1835 XClientMessageEvent smToWmMessage;
1838 * These variables are needed to buffer up the commands and then
1839 * execute them (also buffer up hints then put them on the root window
1841 unsigned char *hintsBuf[MAX_SCREENS_SAVED];
1842 unsigned char *cmdBuf[MAX_SCREENS_SAVED];
1843 unsigned int maxHintsSize[MAX_SCREENS_SAVED];
1844 unsigned int actHintsSize[MAX_SCREENS_SAVED];
1845 unsigned int numHints[MAX_SCREENS_SAVED];
1846 unsigned int maxCmdSize[MAX_SCREENS_SAVED];
1847 unsigned int actCmdSize[MAX_SCREENS_SAVED];
1848 unsigned int numCmd[MAX_SCREENS_SAVED];
1849 unsigned int maxRemoteSize[MAX_SCREENS_SAVED];
1852 * Initialize the buffers and their sizes to null and 0. Because of
1853 * all possible combinations - buffers aren't malloc'd until they're
1856 for(i = 0;i<smGD.numSavedScreens;i++)
1860 remoteBuf[i] = NULL;
1861 maxHintsSize[i] = 0;
1862 actHintsSize[i] = 0;
1867 maxRemoteSize[i] = 0;
1868 actRemoteSize[i] = 0;
1872 * Save the contents of the DISPLAY environment variable so that it
1873 * can be restored when we're through
1875 dispEnv = getenv(DISPLAY_NAME);
1878 dispSav = (char *) SM_MALLOC(((strlen(dispEnv) +
1879 strlen(DISPLAY_NAME_EQUAL)) * sizeof(char) + 1));
1880 sprintf(dispSav, "%s%s", DISPLAY_NAME_EQUAL, dispEnv);
1888 displayName = strdup(smGD.display->display_name);
1889 remoteDisplay = (unsigned char *)
1890 SM_MALLOC(sizeof(unsigned char) * (strlen(displayName) + 101));
1893 * Create the display name for locally executing clients
1919 * Create the display name for remotely executing clients.
1920 * These two may or may not be the same
1922 DtGetShortHostname((char *)remoteDisplay, 100);
1925 * Add the display qualifications to the host name
1926 * screen is added at execution time
1928 strcat((char *)remoteDisplay, (char *)dispPtr);
1931 * Intern the atom needed to put the hints on the root window
1932 * This has to be done here because InitProtocol has not been called yet
1934 XaWmDtHints = XInternAtom(smGD.display, _XA_DT_SESSION_HINTS, False);
1936 while(GetNextLine() != NULL)
1939 string = GetSmartString(&lineP);
1940 if( string != NULL && !strcmp((char *)string, "dtsmcmd"))
1942 while((string = GetSmartString(&lineP)) != NULL )
1944 if(!strcmp((char *)string, "-host"))
1947 * Extract a host pointer - host pointers
1948 * only exist on remote executions
1950 string = GetSmartString(&lineP);
1955 if(!strcmp((char *)string, "-cmd"))
1958 * Extract the command pointer from the
1961 string = GetSmartString(&lineP);
1966 if(!strcmp((char *)string, "-screen"))
1969 * Extract the screen number from the command
1971 string = GetSmartString(&lineP);
1972 screenNum = atoi((char *)string);
1977 if(!strcmp((char *)string, "-hints"))
1980 * Extract the hints string
1982 string = GetSmartString(&lineP);
1991 * Now put our information in buffers and reinitialize the pointers
1995 if(FillHintBuf(hintPtr, hintsBuf, maxHintsSize,
1996 actHintsSize, screenNum, numHints) != 0)
1999 * Free all malloc'd buffers and exit
2001 for(i = 0;i < smGD.numSavedScreens;i++)
2003 if(actHintsSize[i] > 0)
2005 SM_FREE((char *) hintsBuf[i]);
2007 if(actCmdSize[i] > 0)
2009 SM_FREE((char *) cmdBuf[i]);
2011 if(actRemoteSize[i] > 0)
2013 SM_FREE((char *) remoteBuf[i]);
2021 if((cmdPtr != NULL) && (hostPtr == NULL))
2023 if(FillCmdBuf(cmdPtr, cmdBuf, maxCmdSize,
2024 actCmdSize,screenNum, &numCmd[screenNum]) != 0)
2027 * Free all malloc'd buffers and exit
2029 for(i = 0;i < smGD.numSavedScreens;i++)
2031 if(actHintsSize[i] > 0)
2033 SM_FREE((char *) hintsBuf[i]);
2035 if(actCmdSize[i] > 0)
2037 SM_FREE((char *) cmdBuf[i]);
2039 if(actRemoteSize[i] > 0)
2041 SM_FREE((char *) remoteBuf[i]);
2050 if((cmdPtr != NULL) && (hostPtr != NULL))
2052 if(FillRemoteBuf(cmdPtr, hostPtr, remoteDisplay,
2053 remoteBuf, maxRemoteSize,
2054 actRemoteSize, screenNum) != 0)
2057 * Free all malloc'd buffers and exit
2059 for(i = 0;i < smGD.numSavedScreens;i++)
2061 if(actHintsSize[i] > 0)
2063 SM_FREE((char *) hintsBuf[i]);
2065 if(actCmdSize[i] > 0)
2067 SM_FREE((char *) cmdBuf[i]);
2069 if(actRemoteSize[i] > 0)
2071 SM_FREE((char *) remoteBuf[i]);
2081 screenNum = XDefaultScreen(smGD.display);
2086 * All done with file so close it off and set descriptor to NULL -
2087 * This is done so that parsing routines can be used with a buffer later
2093 * Now execute all the buffers, put all hints on the root windows
2094 * Do all remote executions
2096 for(i = 0;i < smGD.numSavedScreens;i++)
2099 * Put the root window property on each root window
2101 if(actHintsSize[i] > 0)
2104 * Append number of hints to front of buffer
2106 sprintf((char *)tmpChar, "%d", numHints[i]);
2107 strncpy((char *)hintsBuf[i], (char *)tmpChar,
2108 strlen((char *)tmpChar));
2109 XChangeProperty(smGD.display, RootWindow(smGD.display, i),
2110 XaWmDtHints, XA_STRING, 8, PropModeReplace,
2111 hintsBuf[i], actHintsSize[i]);
2112 SM_FREE((char *) hintsBuf[i]);
2113 XSync(smGD.display, 0);
2121 * Now exec on the local clients - we're doing contention management
2122 * to make sure the system doesn't get swamped
2126 while((actCmdSize[i] == 0) && (i < smGD.numSavedScreens))
2131 envVal = SM_MALLOC(BUFSIZ);
2132 if(i >= smGD.numSavedScreens)
2138 sprintf(envVal,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, i);
2146 * Keep forking one client after the other until the
2147 * memory utilization gets beyond the threshold -
2148 * (but only if the capability exists) Then go to
2149 * window manager handshaking
2151 #ifdef DEBUG_CONT_MANAGEMENT
2152 if(smRes.contManagement & SM_CM_SYSTEM)
2154 fprintf(stderr, "SM_CM_SYSTEM flag set in smRes.contManagement\n");
2156 if(smRes.contManagement & SM_CM_HANDSHAKE)
2158 fprintf(stderr, "SM_CM_HANDSHAKE flag set in smRes.contManagement\n");
2160 #endif /* DEBUG_CONT */
2162 if((smRes.contManagement & SM_CM_SYSTEM) &&
2163 ((GetMemoryUtilization() != MEM_NOT_AVAILABLE) &&
2164 (clientsDone == False)))
2166 while((GetMemoryUtilization() == MEM_NOT_FULL) &&
2167 (clientsDone == False))
2171 CreateExecString((char *) lineP);
2172 if(smExecArray[0] != NULL)
2174 (void) StartClient(smExecArray[0], (char **)smExecArray, NULL,
2175 NULL, NULL, False, False, -1);
2180 * When all the clients have been exec'd for this screen
2183 if(numClientsExec >= numCmd[i])
2185 ResetScreenInfo(cmdBuf, &i, actCmdSize, &clientsDone,
2186 envVal, displayName);
2193 * After we've checked memory utilization - finish up
2194 * by handshaking with the worksapce manager - if it's there
2196 if(clientsDone == False)
2198 if((smGD.dtwmRunning) && (smRes.contManagement & SM_CM_HANDSHAKE))
2201 * Get the window id of the workspace manager and tell it
2202 * to start messaging
2204 _DtGetMwmWindow(smGD.display, RootWindow(smGD.display, 0),
2206 smToWmMessage.type = ClientMessage;
2207 smToWmMessage.window = dtwmWin;
2208 smToWmMessage.message_type = XaSmWmProtocol;
2209 smToWmMessage.format = 32;
2210 smToWmMessage.data.l[0] = XaSmStartAckWindow;
2211 smToWmMessage.data.l[1] = CurrentTime;
2212 if (XSendEvent(smGD.display, dtwmWin,False,NoEventMask,
2213 (XEvent *) &smToWmMessage) != 0)
2216 XSync(smGD.display, 0);
2222 * Start a client - and wait for the workspace manager to
2223 * map a window to start a new client
2225 while(clientsDone == False)
2229 CreateExecString((char *) lineP);
2230 if(smExecArray[0] != NULL)
2232 (void) StartClient(smExecArray[0], smExecArray,
2233 NULL, NULL, NULL, False, False, -1);
2237 * If we're handshaking with the workspace manager
2238 * wait for the client to be mapped before starting
2241 if(wmHandshake == True)
2249 * When all the clients have been exec'd for this screen
2252 if(numClientsExec >= numCmd[i])
2254 ResetScreenInfo(cmdBuf, &i, actCmdSize, &clientsDone,
2255 envVal, displayName);
2260 if(wmHandshake == True)
2263 * If we are handshaking - tell the workspace manager to
2266 smToWmMessage.type = ClientMessage;
2267 smToWmMessage.window = dtwmWin;
2268 smToWmMessage.message_type = XaSmWmProtocol;
2269 smToWmMessage.format = 32;
2270 smToWmMessage.data.l[0] = XaSmStopAckWindow;
2271 smToWmMessage.data.l[0] = CurrentTime;
2272 XSendEvent(smGD.display, dtwmWin,False,NoEventMask,
2273 (XEvent *) &smToWmMessage);
2278 for(i = 0;i < smGD.numSavedScreens;i++)
2280 if(numRemoteDone == MAX_REMOTE_CLIENTS)
2286 * Send out all the remote execution commands for the screen to
2287 * the command invoker. On failure - do a remsh instead
2289 if(actRemoteSize[i] > 0)
2292 * Initialize the command invoker - if not done
2294 if(cmdInvInit == False)
2296 _DtInitializeCommandInvoker(smGD.display,
2304 * Set up the display environment variable so that the
2305 * application comes back to the right screen
2307 sprintf(envVal,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, i);
2311 parseP = remoteBuf[i];
2312 while(numRemoteExecs > 0 && GetNextLine() != NULL)
2315 * Get the host and the command and send them off
2316 * On failure of the command invoker do a remsh
2319 string = GetSmartString(&lineP);
2321 string = GetSmartString(&lineP);
2324 remoteBufPtr[numRemoteDone].cmdPtr = cmdPtr;
2325 remoteBufPtr[numRemoteDone].hostPtr = hostPtr;
2327 _DtCommandInvokerExecute(DtSTART_SESSION, NULL, NULL, NULL,
2328 "-", (char *) hostPtr, (char *) cmdPtr,
2329 RemoteRequestSucceeded, NULL,
2330 RemoteRequestFailed,
2331 &remoteBufPtr[numRemoteDone]);
2335 * If there is no more room in the remote client
2336 * array - quit exec'ing remote clients
2338 if(numRemoteDone == MAX_REMOTE_CLIENTS)
2340 PrintError(DtError, GETMESSAGE(16, 5, "You have reached the maximum allowed number of remote clients. No further remote clients will be restored."));
2350 * Now return the display variable back to the display that was
2351 * originally opened (the default display)
2359 FixEnvironmentData();
2364 } /* END OF FUNCTION RestoreClients */
2368 /*************************************<->*************************************
2370 * StartEtc ( exiting )
2375 * Call the StartClient routine to fork and exec either the sessionetc file
2376 * (if exiting==False) or the sessionexit file (if exiting==True).
2388 *************************************<->***********************************/
2390 StartEtc( Boolean exiting )
2397 execArray[0] = smGD.exitPath;
2398 execArray[1] = smExitFile;
2400 execArray[0] = smGD.etcPath;
2401 execArray[1] = smEtcFile;
2403 execArray[2] = '\0';
2405 if ((status=stat(execArray[0], &buf)) != -1)
2407 StartClient(execArray[0], execArray, NULL, NULL, NULL, False, False, -1);
2412 /*************************************<->*************************************
2419 * Returns the next line from an fopened configuration file or a newline-
2420 * embedded configuration string.
2425 * cfileP = (global) file pointer to fopened configuration file or NULL
2426 * line = (global) line buffer
2427 * linec = (global) line count
2428 * parseP = (global) parse string pointer if cfileP == NULL
2433 * line = (global) next line
2434 * linec = (global) line count incremented
2435 * parseP = (global) parse string pointer incremented
2436 * Return = line or NULL if file or string is exhausted.
2441 * If there are more than MAXLINE characters on a line in the file cfileP the
2442 * excess are truncated.
2443 * Assumes the line buffer is long enough for any parse string line.
2444 * Code stolen from dtmwm
2446 *************************************<->***********************************/
2447 static unsigned char *
2450 unsigned char *string;
2456 /* read fopened file */
2458 string = (unsigned char *) fgets((char *)line, fileSize, cfileP);
2460 else if ((parseP != NULL) && (*parseP != 0))
2461 /* read parse string */
2465 while ((*parseP != 0) &&
2466 ((chlen = mblen ((char *) parseP, MB_CUR_MAX)) > 0) &&
2468 /* copy all but NULL and newlines to line buffer */
2472 *(string++) = *(parseP++);
2476 while ((*parseP != NULL) && (*parseP != '\n'))
2477 /* copy all but NULL and newlines to line buffer */
2479 *(string++) = *(parseP++);
2483 if (*parseP == '\n')
2496 } /* END OF FUNCTION GetNextLine */
2500 /*************************************<->*************************************
2502 * PeekAhead (currentChar, currentLev)
2507 * Returns a new level value if this is a new nesting level of quoted string
2508 * Otherwise it returns a zero
2513 * currentChar = current position in the string
2514 * currentLev = current level of nesting
2519 * Returns either a new level of nesting or zero if the character is copied in
2525 *************************************<->***********************************/
2528 unsigned char *currentChar,
2529 unsigned int currentLev )
2531 Boolean done = False;
2532 unsigned int tmpLev = 1;
2536 while (((chlen = mblen ((char *) currentChar, MB_CUR_MAX)) > 0) &&
2537 (chlen == 1) && ((*currentChar == '"') || (*currentChar == '\\'))
2542 if(((chlen = mblen ((char *) currentChar, MB_CUR_MAX)) > 0) && (chlen == 1) &&
2543 ((*currentChar == '"') || (*currentChar == '\\')))
2546 if(*currentChar == '"')
2557 while((*currentChar != NULL) && (done == False) &&
2558 ((*currentChar == '"') || (*currentChar == '\\')))
2561 if((*currentChar != NULL) &&
2562 ((*currentChar == '"') || (*currentChar == '\\')))
2565 if(*currentChar == '"')
2575 #endif /*MULTIBYTE*/
2578 * Figure out if this is truly a new level of nesting - else ignore it
2579 * This section probably could do some error checking and return -1
2580 * If so, change type of routine from unsigned int to int
2594 /*************************************<->*************************************
2596 * GetSmartString (linePP)
2601 * Returns the next quoted or whitespace-terminated nonquoted string in the
2603 * Additional functionality added to GetString in that anything in a
2604 * quoted string is considered sacred and nothing will be stripped from
2605 * the middle of a quoted string.
2610 * linePP = pointer to current line buffer pointer.
2615 * linePP = pointer to revised line buffer pointer.
2621 * May alter the line buffer contents.
2622 * Handles quoted strings and characters, removing trailing whitespace from
2624 * Returns NULL string if the line is empty or is a comment.
2625 * Code stolen from dtmwm.
2627 *************************************<->***********************************/
2629 static unsigned char *
2631 unsigned char **linePP )
2633 unsigned char *lineP = *linePP;
2634 unsigned char *endP;
2635 unsigned char *curP;
2636 unsigned char *lnwsP;
2637 unsigned int level = 0, checkLev, i, quoteLevel[MAX_QUOTE_DEPTH];
2641 /* get rid of leading white space */
2642 ScanWhitespace (&lineP);
2645 * Return NULL if line is empty, whitespace, or begins with a comment.
2647 if((chlen = mblen ((char *) lineP, MB_CUR_MAX)) < 1)
2653 if ((chlen == 1) && (*lineP == '"'))
2656 quoteLevel[level] = 1;
2658 * Start beyond double quote and find the end of the quoted string.
2659 * '\' quotes the next character - but is not stripped out.
2660 * Otherwise, matching double quote or NULL terminates the string.
2662 * We use lnwsP to point to the last non-whitespace character in the
2663 * quoted string. When we have found the end of the quoted string,
2664 * increment lnwsP and if lnwsP < endP, write NULL into *lnwsP.
2665 * This removes any trailing whitespace without overwriting the
2666 * matching quote, needed later. If the quoted string was all
2667 * whitespace, then this will write a NULL at the beginning of the
2668 * string that will be returned -- OK.
2670 lnwsP = lineP++; /* lnwsP points to first '"' */
2671 curP = endP = lineP; /* other pointers point beyond */
2673 while ((*endP = *curP) &&
2674 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0) &&
2675 ((chlen > 1) || (*curP != '"')))
2676 /* Haven't found matching quote yet.
2677 * First byte of next character has been copied to endP.
2681 if ((chlen == 1) && (*endP == '\\') &&
2682 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0))
2685 * Check to see if this is a quoted quote - if it is
2686 * strip off a level - if not - it's sacred leave it alone
2688 checkLev = PeekAhead((curP - 1), quoteLevel[level]);
2691 if(quoteLevel[level] >= checkLev)
2693 if (level > 0) level--;
2695 else if (level < MAX_QUOTE_DEPTH)
2698 quoteLevel[level] = checkLev;
2701 for(i = 0;i < (checkLev - 2);i++)
2703 *endP++ = *curP++;curP++;
2710 /* Singlebyte character: character copy finished. */
2712 if (isspace (*endP))
2713 /* whitespace character: leave lnwsP unchanged. */
2718 /* non-whitespace character: point lnwsP to it. */
2724 /* Multibyte (nonwhitespace) character: point lnwsP to it.
2725 * Finish character byte copy.
2738 /* get rid of leading white space */
2739 ScanWhitespace (&lineP);
2741 /* Return NULL if line is empty, or whitespace */
2751 quoteLevel[level] = 1;
2753 * Start beyond double quote and find the end of the quoted string.
2754 * '\' quotes the next character.
2755 * Otherwise, matching double quote or NULL terminates the string.
2757 * We use lnwsP to point to the last non-whitespace character in the
2758 * quoted string. When we have found the end of the quoted string,
2759 * increment lnwsP and if lnwsP < endP, write NULL into *lnwsP.
2760 * This removes any trailing whitespace without overwriting the
2761 * matching quote, needed later. If the quoted string was all
2762 * whitespace, then this will write a NULL at the beginning of the
2763 * string that will be returned -- OK.
2765 lnwsP = lineP++; /* lnwsP points to first '"' */
2766 curP = endP = lineP; /* other pointers point beyond */
2768 while ((*endP = *curP) && (*endP != '"'))
2769 /* haven't found matching quote yet */
2771 /* point curP to next character */
2773 if ((*endP == '\\') && (*curP != NULL))
2774 /* shift quoted nonNULL character down and curP ahead */
2777 * Check to see if this is a quoted quote - if it is
2778 * strip off a level - if not - it's sacred leave it alone
2780 checkLev = PeekAhead((curP - 1), quoteLevel[level]);
2783 if(quoteLevel[level] >= checkLev)
2785 if (level > 0) level--;
2787 else if (level < MAX_QUOTE_DEPTH)
2790 quoteLevel[level] = checkLev;
2793 for(i = 0;i < (checkLev - 2);i++)
2795 *endP++ = *curP++;curP++;
2801 if (isspace (*endP))
2802 /* whitespace character: leave lnwsP unchanged. */
2807 /* non-whitespace character: point lnwsP to it. */
2815 * Found matching quote or NULL.
2816 * NULL out any trailing whitespace.
2827 /* Unquoted string */
2830 * Find the end of the nonquoted string.
2831 * '\' quotes the next character.
2832 * Otherwise, whitespace, NULL, terminates the string.
2834 curP = endP = lineP;
2837 while ((*endP = *curP) &&
2838 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0) &&
2839 ((chlen > 1) || (!isspace (*curP))))
2840 /* Haven't found whitespace yet.
2841 * First byte of next character has been copied to endP.
2845 if ((chlen == 1) && (*endP == '\\') &&
2846 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0))
2848 * copy first byte of quoted nonNULL character down.
2849 * point curP to next byte
2856 /* Multibyte character: finish character copy. */
2865 while ((*endP = *curP) && !isspace (*endP))
2867 /* point curP to next character */
2869 if ((*endP == '\\') && (*curP != NULL))
2870 /* shift quoted nonNULL character down and curP ahead */
2880 * Two cases for *endP:
2882 * matching quote -> write NULL over char and point beyond
2883 * NULL -> point to NULL
2888 *endP = 0; /* write NULL over terminator */
2889 *linePP = ++curP; /* point beyond terminator */
2895 return ((unsigned char *)lineP);
2897 } /* END OF FUNCTION GetString */
2902 /*************************************<->*************************************
2904 * ScanWhitespace(linePP)
2909 * Scan the string, skipping over all white space characters.
2914 * linePP = nonNULL pointer to current line buffer pointer
2919 * linePP = nonNULL pointer to revised line buffer pointer
2924 * Assumes linePP is nonNULL
2925 * Code Stolen from dtmwm
2927 *************************************<->***********************************/
2930 unsigned char **linePP )
2933 while (*linePP && (mblen ((char *) *linePP, MB_CUR_MAX) == 1) && isspace (**linePP))
2935 while (*linePP && isspace (**linePP))
2941 } /* END OF FUNCTION ScanWhitespace */
2945 /*************************************<->*************************************
2947 * FillHintBuf(newHint, hintBuf, maxSize, actSize, screen, numHints)
2952 * Put the new hint into the hint buffer. Each hint is separated by a
2958 * newHint = hint to add to the buffer
2959 * hintBuf = an array of buffers - one for each screen
2960 * maxSize = array of buffers of the current malloced size of each hintBuf
2961 * actSize = array of space currently used by each hintBuf
2962 * screen = screen number for this hint
2963 * numHints = array of the number of hints for each screen
2964 * smGD.numSavedScreens = (global) checked to make sure this hint should be
2969 * hintBuf[screen] = updated hint buf for this screen (newHint added)
2970 * maxSize[screen] = enlarged if not big enough or malloced if not done before
2971 * actSize[screen] = updated size of the hints buffer
2972 * numHints[screen] = updated by 1 if this hint is added
2978 *************************************<->***********************************/
2981 unsigned char *newHint,
2982 unsigned char **hintBuf,
2983 unsigned int *maxSize,
2984 unsigned int *actSize,
2985 unsigned int screen,
2986 unsigned int *numHints)
2988 static int hintBufSize = 5000;
2991 * If the screen that this hint was meant for is not in the current
2992 * set of available screens, don't save it
2994 if(screen >= smGD.numSavedScreens)
3000 * Check to see if this buffer has been malloc'd before - if it hasn't
3001 * malloc it. If it has - check to make sure it's big enough to hold the
3004 if(maxSize[screen] == 0)
3006 hintBuf[screen] = (unsigned char *) SM_MALLOC(hintBufSize * sizeof(char));
3007 if(hintBuf[screen] == NULL)
3009 actSize[screen] = 0;
3010 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3013 maxSize[screen] = hintBufSize * sizeof(char);
3016 * Now reserve 4 bytes for the length
3018 strcpy((char *)hintBuf[screen], " \n");
3022 if((actSize[screen] + strlen((char *)newHint) + 2) >= maxSize[screen])
3024 hintBuf[screen] = (unsigned char *)
3025 SM_REALLOC((char *) hintBuf[screen],
3029 if(hintBuf[screen] == NULL)
3031 actSize[screen] = 0;
3032 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3035 maxSize[screen] = maxSize[screen] + (hintBufSize * sizeof(char));
3040 * add the new hint AFTER the last newline
3042 strcat((char *)hintBuf[screen], (char *)newHint);
3043 strcat((char *)hintBuf[screen], "\n");
3044 actSize[screen] = strlen((char *)hintBuf[screen]);
3045 numHints[screen] += 1;
3052 /*************************************<->*************************************
3054 * FillCmdBuf(newCmd, cmdBuf, maxSize, actSize, screen)
3059 * Put a new command into the command buffer. The command buffer is just
3060 * one big long string of stuff to be executed.
3065 * newCmd = command to add to the buffer
3066 * cmdBuf = an array of buffers - one for each screen
3067 * maxSize = array of buffers of the current malloced size of each cmdBuf
3068 * actSize = array of space currently used by each cmdBuf
3069 * screen = screen number for this command
3070 * smGD.numSavedScreens = (global) checked to make sure this hint should be
3075 * cmdBuf[screen] = updated command buf for this screen (newCmd added)
3076 * maxSize[screen] = enlarged if not big enough or malloced if not done before
3077 * actSize[screen] = updated size of the command buffer
3083 *************************************<->***********************************/
3086 unsigned char *newCmd,
3087 unsigned char **cmdBuf,
3088 unsigned int *maxSize,
3089 unsigned int *actSize,
3090 unsigned int screen,
3091 unsigned int *numCmd )
3093 static int cmdBufSize = 5000;
3096 * If the screen that this command was meant for is not in the current
3097 * set of available screens, don't save it
3099 if(screen >= smGD.numSavedScreens)
3105 * Check to see if this buffer has been malloc'd before - if it hasn't
3106 * malloc it. If it has - check to make sure it's big enough to hold the
3109 if(maxSize[screen] == 0)
3111 cmdBuf[screen] = (unsigned char *) SM_MALLOC(cmdBufSize * sizeof(char));
3112 if(cmdBuf[screen] == NULL)
3114 actSize[screen] = 0;
3115 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3118 maxSize[screen] = cmdBufSize * sizeof(char);
3122 if((actSize[screen] + strlen((char *)newCmd)) >= maxSize[screen])
3124 cmdBuf[screen] = (unsigned char *) SM_REALLOC((char *)cmdBuf[screen],
3128 if(cmdBuf[screen] == NULL)
3130 actSize[screen] = 0;
3131 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3134 maxSize[screen] = maxSize[screen] + (cmdBufSize * sizeof(char));
3138 if(actSize[screen] == 0)
3140 strcpy((char *)cmdBuf[screen], (char *)newCmd);
3144 strcat((char *)cmdBuf[screen], (char *)newCmd);
3147 *numCmd = *numCmd + 1;
3148 strcat((char *)cmdBuf[screen], "\n");
3149 actSize[screen] = strlen((char *)cmdBuf[screen]);
3156 /*************************************<->*************************************
3158 * FillRemoteBuf(newCmd, hostName, displayName, remoteBuf,
3159 * maxSize, actSize, screen)
3164 * Put a new command into the remote execution buffer. The command buffer is
3165 * just one big long string of stuff to be executed.
3170 * newCmd = command to add to the buffer
3171 * hostName = host where command is to be executed from
3172 * displayName = display where host is to be executed to
3173 * remoteBuf = an array of buffers - one for each screen
3174 * maxSize = array of buffers of the current malloced size of each cmdBuf
3175 * actSize = array of space currently used by each cmdBuf
3176 * screen = screen number for this command
3177 * smGD.numSavedScreens = (global) checked to make sure this hint should be
3182 * cmdBuf[screen] = updated command buf for this screen (newCmd added)
3183 * in remote format (host name and display name)
3184 * maxSize[screen] = enlarged if not big enough or malloced if not done before
3185 * actSize[screen] = updated size of the command buffer
3191 *************************************<->***********************************/
3194 unsigned char *newCmd,
3195 unsigned char *hostName,
3196 unsigned char *displayName,
3197 unsigned char *remoteBuf[] ,
3198 unsigned int *maxSize ,
3199 unsigned int *actSize ,
3200 unsigned int screen )
3202 unsigned char *string;
3203 static int remoteBufSize = 5000;
3206 * If the screen that this command was meant for is not in the current
3207 * set of available screens, don't save it
3209 if(screen >= smGD.numSavedScreens)
3215 * Check to see if this buffer has been malloc'd before - if it hasn't
3216 * malloc it. If it has - check to make sure it's big enough to hold the
3219 if(maxSize[screen] == 0)
3221 remoteBuf[screen] = (unsigned char *)
3222 SM_MALLOC(remoteBufSize * sizeof(char));
3223 if(remoteBuf[screen] == NULL)
3225 actSize[screen] = 0;
3226 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3229 maxSize[screen] = remoteBufSize * sizeof(char);
3233 if((actSize[screen] + strlen((char *)newCmd) +
3234 strlen((char *)hostName) +
3235 strlen((char *)displayName) +
3236 strlen("-display ") + 5) >= maxSize[screen])
3238 remoteBuf[screen] = (unsigned char *)
3239 SM_REALLOC((char *)remoteBuf[screen],
3241 (remoteBufSize * sizeof(char)));
3242 if(remoteBuf[screen] == NULL)
3244 actSize[screen] = 0;
3245 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3248 maxSize[screen] = maxSize[screen] + (remoteBufSize * sizeof(char));
3252 if(actSize[screen] == 0)
3255 * If the buffer is empty fill it with the initial contents
3257 strcpy((char *)remoteBuf[screen], (char *)hostName);
3258 strcat((char *)remoteBuf[screen], " ");
3263 * if this buffer is not emtpy
3264 * add the new command BEFORE the last null terminator
3265 * Commands for remote executions are separated by newlines
3267 strcat((char *)remoteBuf[screen], "\n");
3268 strcat((char *)remoteBuf[screen], (char *)hostName);
3272 * Copy the command in - quote it
3274 strcat((char *)remoteBuf[screen], " \"");
3275 string = GetSmartString(&newCmd);
3276 strcat((char *)remoteBuf[screen], (char *)string);
3277 strcat((char *)remoteBuf[screen], " ");
3280 * Once display name has been put in place - concatenate the
3281 * rest of the command
3283 while((string = GetSmartString(&newCmd)) != NULL )
3285 strcat((char *)remoteBuf[screen], " ");
3286 strcat((char *)remoteBuf[screen], (char *)string);
3290 * Now close off the command with a quote
3292 strcat((char *)remoteBuf[screen], "\"");
3294 actSize[screen] = strlen((char *)remoteBuf[screen]);
3297 * Bump the remote command counter
3305 /*************************************<->*************************************
3307 * CreateExecString(execString)
3312 * Create a string that can be fed to a fork and exec by breaking it up
3313 * into argc and argv
3318 * execString = whole command
3322 * smExecArray = global modified to contain pointers to argc and argv
3328 *************************************<->***********************************/
3336 static int iSizeArgv = ARG_AMT;
3341 if (smExecArray == NULL)
3343 smExecArray = (char **) XtMalloc (ARG_AMT * sizeof(char *));
3345 string = (char *) GetSmartString((unsigned char **) &execString);
3346 while(string != NULL)
3348 smExecArray[argc] = string;
3350 if (argc >= iSizeArgv)
3352 iSizeArgv += ARG_AMT;
3353 smExecArray = (char **)
3354 XtRealloc ((char *)smExecArray, (iSizeArgv * sizeof(char *)));
3356 string = (char *) GetSmartString((unsigned char **) &execString);
3360 * If the last string is a background character
3365 if(!strcmp((char *)smExecArray[argc - 1], "&"))
3367 smExecArray[argc - 1] = '\0';
3371 smExecArray[argc] = '\0';
3373 } /* END OF FUNCTION CreateExecString */
3377 * SetTemporaryDisplay - does a putenv of the current value of the
3378 * DISPLAY environment variable but with the given screen number.
3384 SetTemporaryDisplay (
3387 static char * tmpDisplay = NULL;
3388 static int lastScreen = -1;
3391 if (screenNum == -1)
3394 if (!savedDisplay) {
3397 if ((dispEnv = getenv (DISPLAY_NAME)) == NULL)
3399 savedDisplay = XtMalloc (strlen (DISPLAY_NAME_EQUAL) +
3400 strlen (dispEnv) + 2);
3403 sprintf (savedDisplay, "%s%s", DISPLAY_NAME_EQUAL, dispEnv);
3406 if (lastScreen == screenNum && tmpDisplay != NULL) {
3407 putenv (tmpDisplay);
3410 lastScreen = screenNum;
3415 tmpDisplay = XtMalloc (strlen (savedDisplay) + 4);
3418 strcpy (tmpDisplay, savedDisplay);
3421 if (pch = strrchr (tmpDisplay, ':')) {
3424 if (pch2 = strchr (pch, '.'))
3426 pch3 = XtMalloc (strlen (tmpDisplay) + 4);
3429 sprintf (pch3, "%s.%d", tmpDisplay, screenNum);
3430 strcpy (tmpDisplay, pch3);
3431 XtFree ((char *) pch3);
3433 putenv (tmpDisplay);
3439 * RestoreDisplay - does a putenv of the global variable savedDisplay
3445 if (screenNum != -1 && savedDisplay)
3446 putenv (savedDisplay);
3450 /*************************************<->*************************************
3452 * StartClient - calls StartLocalClient or StartRemoteClient depending
3453 * on the value of hostName.
3457 * Starts a local or remote application
3461 * program = execArray[0]
3462 * execArray = command to fork and exec
3463 * hostName = the name of the host where program should be executed
3464 * cwd = directory to chdir to before doing the exec
3465 * envp = the envrironment variables to add to the child processes env
3466 * checkCwd = if True and cwd is NULL, a message will be logged; if
3467 * False, cwd will not be checked and the cwd will be set to $HOME
3468 * useIgnoreEnvironmentResource = if True, the variables listed in the
3469 * IgnoreEnvironment resource will be removed from 'environ' before
3470 * execArray is exec'd
3471 * screen = if set to -1, it will be ignored; otherwise, the screen
3472 * number will be used to define DISPLAY for the duration of this
3473 * function - DISPLAY will be reset before the function returns.
3477 * Returns True if the command is successfully executed; False otherwise.
3481 * localHost - is modified
3483 *************************************<->***********************************/
3492 Boolean useIgnoreEnvironmentResource,
3495 static char * defaultCwd = NULL;
3496 Boolean cwdNull = False;
3497 Boolean startStatus;
3499 SetTemporaryDisplay (screen);
3501 if (!ignoreEnvPtr && useIgnoreEnvironmentResource) {
3502 if (smRes.ignoreEnvironment)
3503 ignoreEnvPtr = _DtVectorizeInPlace (
3504 smRes.ignoreEnvironment, ',');
3509 char *tstr = getenv("HOME");
3512 int slen = strlen(tstr) + 1;
3513 defaultCwd = XtCalloc(1, slen);
3514 strncpy(defaultCwd, tstr, slen - 1);
3517 defaultCwd = getcwd (NULL, MAXPATHLEN + 1);
3519 (void) gethostname (localHost, MAXHOSTNAMELEN);
3527 if (!hostName || (_DtIsSameHost (localHost, hostName)))
3528 startStatus = StartLocalClient (program, execArray,
3529 cwd, envp, checkCwd,
3530 useIgnoreEnvironmentResource);
3532 startStatus = StartRemoteClient (program, execArray, hostName,
3534 useIgnoreEnvironmentResource);
3536 RestoreDisplay (screen);
3538 return (startStatus);
3541 /*************************************<->*************************************
3547 * Starts a local application.
3550 * Returns True if the command is successfully executed; False otherwise.
3552 *************************************<->***********************************/
3560 Boolean useIgnoreEnvironmentResource)
3564 char clientMessage[MAXPATHLEN + 30];
3565 char **tmpEnv, **ppchar;
3568 * Fork and exec the client process
3570 clientFork = vfork();
3573 * If the fork fails - Send out an error and return
3577 PrintErrnoError(DtError, smNLS.cantForkClientString);
3582 * Fork succeeded - now do the exec
3586 SetSIGPIPEToDefault ();
3589 * Log a warning if the given cwd is not valid
3593 if ((chdir (cwd)) == -1)
3597 tmpCwd = getcwd (NULL, MAXPATHLEN + 1);
3599 LogCWDMessage (cwd, program, tmpCwd);
3604 * Add envp to the client's environ if the variable
3605 * is not in the ignoreEnvironment list
3607 if (useIgnoreEnvironmentResource && envp) {
3610 tmpEnv = RemoveEnvironmentVars (envp);
3614 for (ppchar = tmpEnv; ppchar && *ppchar; ppchar++)
3615 putenv (strdup (*ppchar));
3620 * Set the gid of the process back from bin
3623 setregid(smGD.runningGID, smGD.runningGID);
3625 setgid(smGD.runningGID);
3626 setegid(smGD.runningGID);
3630 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
3632 #if defined(__osf__) || defined(CSRG_BASED)
3636 #endif /* __osf__ */
3638 MarkFileDescriptors (3, F_SETFD, 1);
3640 execStatus = execvp(program, execArray);
3643 sprintf(clientMessage, ((char *)GETMESSAGE(16, 3, "Unable to exec %s.")), execArray[0]);
3644 PrintErrnoError(DtError, clientMessage);
3652 /*************************************<->*************************************
3658 * Starts a remote application.
3661 * Returns True if the command is successfully executed; False otherwise.
3663 *************************************<->***********************************/
3671 Boolean useIgnoreEnvironmentResource)
3674 SPC_Channel_Ptr channel;
3676 char errorMessage[1024];
3678 static Boolean cmdInvokerInitialized = False;
3679 char ** tmpEnv = envp;
3681 ioMode = SPCIO_NOIO | SPCIO_FORCE_CONTEXT;
3683 if (!cmdInvokerInitialized) {
3684 _DtInitializeCommandInvoker(smGD.display,
3688 cmdInvokerInitialized = True;
3691 (void) strcpy (errorMessage, "");
3693 channel = (SPC_Channel_Ptr) _DtSPCOpen (hostName, ioMode, errorMessage);
3694 if (channel == SPC_ERROR) {
3695 message = strdup ((char *) GETMESSAGE (40, 13,
3696 "The following application cannot be started on host '%s'\nbecause this host cannot be reached from host '%s':\n\n %s"));
3699 DtMsgLogMessage (smGD.programName, DtMsgLogError,
3700 message, hostName, localHost, program);
3706 netfile = tt_host_file_netfile (hostName, cwd);
3707 if (tt_pointer_error (netfile) != TT_OK) {
3709 message = strdup ((char *) GETMESSAGE (40, 14,
3710 "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]"));
3713 DtMsgLogMessage (smGD.programName, DtMsgLogError,
3714 message, program, hostName, cwd,
3715 tt_status_message (tt_pointer_error (
3723 * Add envp to the client's environ if the variable
3724 * is not in the ignoreEnvironment list
3726 if (useIgnoreEnvironmentResource && ignoreEnvPtr && envp)
3727 tmpEnv = RemoveEnvironmentVars (envp);
3729 if ((_DtSPCSpawn (program, netfile, execArray, tmpEnv, channel,
3730 hostName, NULL, cwd, errorMessage)) == SPC_ERROR) {
3731 DtMsgLogMessage (smGD.programName, DtMsgLogError, errorMessage);
3733 XtFree ((char *) tmpEnv);
3739 XtFree ((char *) tmpEnv);
3745 /*************************************<->*************************************
3752 * Fork and exec the default window manager
3765 *************************************<->***********************************/
3774 * These lines were added to support the builtin
3779 char *displayName,*dpy;
3781 hostName = SM_MALLOC(MAXPATHSM);
3782 displayName = SM_MALLOC(MAXPATHSM);
3784 if( gethostname(hostName, (sizeof(hostName) - 1) ) == 0)
3786 hostName[MAXPATHSM - 1] = '\0';
3787 dpy = getenv(DISPLAY_NAME);
3788 homeDir = getenv("HOME");
3791 strcpy(displayName, dpy);
3792 dpy = strchr(displayName, ':');
3797 sprintf(tmpExecWmFile, "%s/.dt/bin/%s/%s/dtwm", homeDir,
3798 hostName,displayName);
3799 if (access(tmpExecWmFile,X_OK) != 0)
3801 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3805 localWmLaunched = True;
3806 if (!smGD.userSetWaitWmTimeout)
3808 smRes.waitWmTimeout = 60000;
3814 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3819 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3823 SM_FREE(displayName);
3825 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
3826 * End of lines were added to support the builtin
3830 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3835 * Fork and exec the client process
3837 clientFork = vfork();
3840 * If the fork fails - Send out an error and return
3844 PrintErrnoError(DtError, smNLS.cantForkClientString);
3849 * Fork succeeded - now do the exec
3853 SetSIGPIPEToDefault ();
3857 * Set the gid of the process back from bin
3860 setregid(smGD.runningGID, smGD.runningGID);
3862 setgid(smGD.runningGID);
3863 setegid(smGD.runningGID);
3866 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
3868 #if defined(__osf__) || defined(CSRG_BASED)
3872 #endif /* __osf__ */
3874 MarkFileDescriptors (3, F_SETFD, 1);
3877 * These lines were added to support the builtin
3880 * execStatus = execlp(".../dt/bin/dtwm", "dtwm", (char *) 0);
3883 execStatus = execlp(tmpExecWmFile, "dtwm", (char *) 0);
3886 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
3887 * End of lines were added to support the builtin
3891 if(execStatus != 0 && (!localWmLaunched))
3893 PrintErrnoError(DtError, GETMESSAGE(16, 4, "Unable to exec process /usr/dt/bin/dtwm. No window manager will be started."));
3900 /*************************************<->*************************************
3907 * Fork a copy of ourselves and kill the parent off so that scripts starting
3908 * up the session manager can continue.
3920 *************************************<->***********************************/
3928 * Fork and exec the client process
3930 clientFork = fork();
3933 * If the fork fails - We have to exit so that the rest of the
3934 * script can continue
3938 PrintErrnoError(DtError, smNLS.cantForkClientString);
3943 * Fork succeeded - now kill the parent
3951 * Disassociate from parent
3953 #if defined(__osf__) || defined(CSRG_BASED)
3957 #endif /* __osf__ */
3962 /*************************************<->*************************************
3969 * This routine waits for the window manager to start. It uses a
3970 * resource (waitWmTimeout) with a dynamic default to determine how many
3971 * seconds to wait for WM start and then starts clients.
3976 * appContext = application context for the window
3977 * window = window id for the
3986 *************************************<->***********************************/
3991 XtIntervalId wmTimerId;
3993 XtAddEventHandler(smGD.topLevelWid,
3996 (XtEventHandler)HandleWMClientMessage,
4000 * Set a timer which stops the block on waiting for the
4001 * window manager to start
4004 wmTimerId = XtAppAddTimeOut(smGD.appCon,
4005 smRes.waitWmTimeout,
4006 WaitWMTimeout, NULL);
4008 while((smGD.dtwmRunning == False) && (wmTimeout == False))
4010 XtAppProcessEvent(smGD.appCon, XtIMAll);
4013 XtRemoveTimeOut(wmTimerId);
4014 XtRemoveEventHandler(smGD.topLevelWid,
4017 (XtEventHandler)HandleWMClientMessage,
4021 } /* END OF FUNCTION WaitForWM */
4024 /*************************************<->*************************************
4031 * Timeout procedure the WaitForCommand routine. It stops a loop waiting
4032 * for the window manager to get started.
4041 * wmTimeout = (global) flag that stops the loop
4046 *************************************<->***********************************/
4049 XtPointer client_data,
4054 } /* END OF FUNCTION WaitWMTimeout */
4058 /*************************************<->*************************************
4060 * HandleWMClientMessage
4065 * This is the event handler registered to recieve the client message
4066 * from dtwm when dtwm is ready for business
4069 *************************************<->***********************************/
4071 HandleWMClientMessage( Widget smWidget,
4075 if (event->type == ClientMessage)
4077 ProcessClientMessage(event);
4080 } /* END OF FUNCTION HandleWMClientMessage */
4085 /*************************************<->*************************************
4087 * FixEnvironmentData
4092 * If DISPLAY variable exists in the environment - remove it
4101 * wmTimeout = (global) flag that stops the loop
4106 *************************************<->***********************************/
4108 FixEnvironmentData( void )
4112 extern char **environ; /* MODIFIED - DISPLAY is remove if found. */
4114 for (i=0, ppchar = environ; *ppchar; ppchar++, i++)
4116 if ((strncmp (*ppchar, DISPLAY_NAME_EQUAL, strlen(DISPLAY_NAME_EQUAL))) == 0)
4119 * Change the DISPLAY environment variable.
4121 for (; *ppchar; ppchar++, i++)
4123 environ[i]=environ[i+1];
4132 /*************************************<->*************************************
4139 * After one screen is finished - set up the info for the next
4144 * cmdBuf - Buffer that holds all the invocation information
4145 * screen - Pointer to the screen number that we're currently working on
4146 * env - used to set up the environment for changing the display var
4147 * displayName - name of the current display
4151 * cmdBuf - old buffers are freed
4152 * screen - updated to point to the new screen info
4153 * done - tells whether the clients are done being exec'd
4154 * linec - *GLOBAL* sets line being read from
4160 *************************************<->***********************************/
4162 ResetScreenInfo(unsigned char **cmdBuf,
4164 unsigned int *cmdSize,
4169 SM_FREE((char *) cmdBuf[*screen]);
4171 while((cmdSize[*screen] == 0) && (*screen < smGD.numSavedScreens))
4176 if(*screen >= smGD.numSavedScreens)
4182 sprintf((char *)env,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, *screen);
4186 parseP = cmdBuf[*screen];
4192 /*************************************<->*************************************
4194 * RemoteRequestFailed ()
4199 * If a request to the command invoker fails, this callback will be called.
4200 * It will then try to execute the command by performing a remsh on it.
4213 *************************************<->***********************************/
4215 RemoteRequestFailed(char *message,
4218 static char *cmdBuf = NULL;
4219 static char *tmpCmdBuf = NULL;
4220 char *errorString = NULL;
4223 static int cmdBufSize = 0;
4226 RemoteReq *tmpReq = (RemoteReq *) client_data;
4229 * If the memory for the buffer has not been malloced - do so
4233 cmdBuf = SM_MALLOC((200 * sizeof(char)) + 1 );
4236 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4239 cmdBufSize = 200 + 1;
4241 tmpCmdBuf = SM_MALLOC((200 * sizeof(char)) + 1 );
4242 if(tmpCmdBuf == NULL)
4244 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4249 * Copy in the host and command field and execute the command
4252 tmpSize = (strlen(REMOTE_CMD_STRING) +
4253 strlen((char *) tmpReq->hostPtr) +
4254 strlen((char *) tmpReq->cmdPtr) + 1);
4256 if(tmpSize >= cmdBufSize)
4258 cmdBuf = SM_REALLOC(cmdBuf, (tmpSize) * sizeof(char));
4262 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4266 cmdBufSize = tmpSize;
4268 if(tmpCmdBuf != NULL)
4270 tmpCmdBuf = SM_REALLOC(tmpCmdBuf, (tmpSize) * sizeof(char));
4271 if(tmpCmdBuf == NULL)
4273 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4278 sprintf(cmdBuf, REMOTE_CMD_STRING, tmpReq->hostPtr, tmpReq->cmdPtr);
4281 * save cmdBuf for error message, cmdBuf is changed
4282 * by CreateExecString
4284 if (tmpCmdBuf != NULL)
4286 strcpy(tmpCmdBuf,cmdBuf);
4289 CreateExecString(cmdBuf);
4290 if(smExecArray[0] != NULL)
4292 (void) StartClient(smExecArray[0], smExecArray, NULL, NULL,
4293 NULL, False, False, -1);
4295 if (tmpCmdBuf != NULL)
4297 tmpString = GETMESSAGE(16, 8,
4298 "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");
4301 (char *)SM_MALLOC((strlen(tmpString) +
4302 strlen((char *)tmpReq->hostPtr) +
4303 strlen((char *)tmpReq->cmdPtr) +
4304 strlen(tmpCmdBuf) + 1 ) *
4307 if(errorString == NULL)
4309 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4313 sprintf(errorString, tmpString, tmpReq->hostPtr,
4314 tmpReq->cmdPtr, tmpCmdBuf );
4315 PrintError(DtError, errorString);
4316 SM_FREE(errorString);
4321 * Now check to make sure that this isn't the last remote request.
4322 * If so, free the data
4326 if(numRemoteExecs == 0)
4328 for(i = 0;i < smGD.numSavedScreens;i++)
4330 if(actRemoteSize[i] > 0)
4332 SM_FREE((char *) remoteBuf[i]);
4342 /*************************************<->*************************************
4344 * RemoteRequestSucceeded ()
4349 * If a request to the command invoker succeeds, this callback will be called.
4350 * It decrements the remote execution counter, and frees the info if
4351 * remote executions are finished
4364 *************************************<->***********************************/
4366 RemoteRequestSucceeded(char *message,
4373 if(numRemoteExecs == 0)
4375 for(i = 0;i < smGD.numSavedScreens;i++)
4377 if(actRemoteSize[i] > 0)
4379 SM_FREE((char *) remoteBuf[i]);
4385 /**************************************************************************
4389 **************************************************************************/
4393 char * databaseName)
4396 XSMPClientDBRecPtr pXSMPRec;
4397 ProxyClientDBRecPtr pProxyRec;
4402 if ((inputDB = OpenInputClientDB (databaseName,
4404 &smXSMP.dbSessionId)) == NULL) {
4405 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogError, 1);
4409 if (!smXSMP.dbVersion) {
4410 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogWarning, 2);
4411 smXSMP.dbVersion = SM_VENDOR_NAME;
4414 if (!smXSMP.dbSessionId) {
4415 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogWarning, 3);
4416 smXSMP.dbSessionId = SM_RELEASE_NAME;
4420 * First start the XSMP clients
4424 if ((pXSMPRec = GetXSMPClientDBRec (inputDB)) == NULL)
4427 if (!CheckRequiredProperties (pXSMPRec, databaseName)) {
4428 FreeXSMPClientDBRec (pXSMPRec);
4432 if (StartXSMPClient (pXSMPRec, databaseName)) {
4434 XSMPClientDBRecPtr tmpRecPtr;
4436 pXSMPRec->next = NULL;
4438 if (!smXSMP.xsmpDbList) {
4439 smXSMP.xsmpDbList = pXSMPRec;
4444 * Find the end of the list
4446 for (tmpRecPtr = smXSMP.xsmpDbList;
4447 tmpRecPtr && tmpRecPtr->next != NULL;
4448 tmpRecPtr = tmpRecPtr->next);
4450 tmpRecPtr->next = pXSMPRec;
4453 FreeXSMPClientDBRec (pXSMPRec);
4457 * Now start the Proxy clients
4459 for (i = 0; ; i++) {
4461 if ((pProxyRec = GetProxyClientDBRec (inputDB)) == NULL)
4464 if (!CheckRequiredFields (pProxyRec, databaseName, i)) {
4465 FreeProxyClientDBRec (pProxyRec);
4469 (void) StartProxyClient (pProxyRec);
4471 FreeProxyClientDBRec (pProxyRec);
4474 (void) CloseClientDB (inputDB, False);
4482 XSMPClientDBRecPtr pDbRec,
4483 char * databaseName)
4485 return (StartClient (pDbRec->restartCommand[0],
4486 pDbRec->restartCommand,
4489 pDbRec->environment,
4492 pDbRec->screenNum));
4498 ProxyClientDBRecPtr pDbRec)
4500 return (StartClient (pDbRec->command[0],
4507 pDbRec->screenNum));
4512 ExecuteCommandProperty (
4514 ClientRecPtr pClientRec)
4517 char ** envp = NULL;
4519 PropertyRecPtr pPropRec;
4523 if ((pPropRec = GetPropertyRec (pClientRec, commandName)) == NULL)
4526 argv = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
4531 for (i = 0; i < pPropRec->prop.num_vals; i++)
4532 argv[i] = pPropRec->prop.vals[i].value;
4533 argv[pPropRec->prop.num_vals] = NULL;
4535 cwd = GetArrayPropertyValue (pClientRec, SmCurrentDirectory);
4538 if ((pPropRec = GetPropertyRec (pClientRec, SmEnvironment)) != NULL) {
4539 envp = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
4544 for (i = 0; i < pPropRec->prop.num_vals; i++)
4545 envp[i] = pPropRec->prop.vals[i].value;
4546 envp[pPropRec->prop.num_vals] = NULL;
4549 retValue = StartClient (argv[0], argv,
4550 pClientRec->clientHost,
4553 pClientRec->screenNum);
4555 XtFree ((char *) argv);
4557 XtFree ((char *) envp);
4563 /*************************************<->*************************************
4565 * ExecuteDiscardCommands -
4567 * Description: Executes all of the DiscardCommand properties in the
4568 * given client database
4572 *************************************<->***********************************/
4574 ExecuteDiscardCommands (
4578 XSMPClientDBRecPtr pXSMPRec;
4579 char * version = NULL;
4583 if ((inputDB = OpenInputClientDB (db, &version, &id )) == NULL) {
4584 str = strdup ((char *) GETMESSAGE (40, 26,
4585 "The following client database cannot be opened:\n\n %s\n\nThe 'DiscardCommand' properties cannot be run."));
4588 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, str, db);
4594 XtFree ((char *) version);
4596 XtFree ((char *) id);
4599 if ((pXSMPRec = GetXSMPClientDBRec (inputDB)) == NULL)
4602 if (!pXSMPRec->discardCommand)
4605 if (!StartClient (pXSMPRec->discardCommand[0],
4606 pXSMPRec->discardCommand,
4607 pXSMPRec->clientHost,
4609 pXSMPRec->environment,
4612 pXSMPRec->screenNum)) {
4613 str = strdup ((char *) GETMESSAGE (40, 27,
4614 "An attempt to execute the 'DiscardCommand' property for\napplication '%s' failed."));
4617 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, str,
4622 FreeXSMPClientDBRec (pXSMPRec);
4625 (void) CloseClientDB (inputDB, False);
4630 CheckRequiredProperties (
4631 XSMPClientDBRecPtr pDbRec,
4632 char * databaseName)
4634 Boolean propsOK = True;
4636 if (!pDbRec->program) {
4637 LogMissingPropertyMessage (pDbRec, SmProgram,
4638 databaseName, DtMsgLogError);
4642 if (!pDbRec->restartCommand) {
4643 LogMissingPropertyMessage (pDbRec, SmRestartCommand,
4644 databaseName, DtMsgLogError);
4653 CheckRequiredFields (
4654 ProxyClientDBRecPtr pDbRec,
4655 char * databaseName,
4660 if (!pDbRec->command) {
4662 message = strdup ((char *) GETMESSAGE (40, 11,
4663 "The required resource '%s' is missing for client '%d'\nin the file '%s'."));
4668 DtMsgLogMessage (smGD.programName, DtMsgLogError, message,
4669 SmProgram, clientNum, databaseName);
4681 LogXSMPOpenDatabaseFailure (
4682 char * databaseName,
4683 DtMsgLogType msgType,
4686 char * message = NULL;
4691 case 1: data = databaseName;
4693 message = strdup ((char *) GETMESSAGE (40, msgNum,
4694 "The following session database could not be opened:\n\n '%s'"));
4697 case 2: data = versionStr;
4699 message = strdup ((char *) GETMESSAGE (40, msgNum,
4700 "The following session database does not contain\nthe required resource '%s':\n\n %s"));
4703 case 3: data = dtsessionIDStr;
4705 message = strdup ((char *) GETMESSAGE (40, msgNum,
4706 "The following session database does not contain\nthe required resource '%s':\n\n %s"));
4714 DtMsgLogMessage (smGD.programName, msgType, message, data);
4716 DtMsgLogMessage (smGD.programName, msgType, message,
4717 data, databaseName);
4724 LogMissingPropertyMessage (
4725 XSMPClientDBRecPtr pDbRec,
4727 char * databaseName,
4728 DtMsgLogType msgType)
4732 message = strdup ((char *) GETMESSAGE (40, 10,
4733 "The required property '%s' is missing for client\n\n %s\n\nin the file '%s'."));
4738 DtMsgLogMessage (smGD.programName, msgType, message,
4739 propName, pDbRec->clientId, databaseName);
4753 message = strdup ((char *) GETMESSAGE (40, 12,
4754 "The directory '%s'\nis not available for application '%s'.\n\nThe following directory will be used:\n\n %s"));
4759 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, message,
4760 badDir, appName, goodDir);
4767 char ** RemoveEnvironmentVars (
4771 char ** retEnv = NULL;
4772 char **ppchar, **ppchar2;
4779 for (count = 0, ppchar = envp; ppchar && *ppchar; count++, ppchar++) ;
4781 retEnv = (char **) XtMalloc ((count + 1) * sizeof (char *));
4785 if (!ignoreEnvPtr) {
4786 for (count = 0, ppchar = envp; ppchar && *ppchar;
4787 count++, ppchar++) {
4788 retEnv[count] = *ppchar;
4790 retEnv[count] = NULL;
4795 for (count = 0, ppchar = envp; ppchar && *ppchar; ppchar++) {
4799 for (ppchar2 = ignoreEnvPtr; ppchar2 && *ppchar2; ppchar2++) {
4801 if ((!strncmp (*ppchar, *ppchar2, strlen (*ppchar2))) &&
4802 (((*ppchar)[strlen(*ppchar2)]) == '=')) {
4808 retEnv[count] = *ppchar;
4812 retEnv[count] = NULL;
4818 * MarkFileDescriptors - mark file descriptiors start_fd through open_max
4819 * with the given "cmd" and "data".
4821 * The code for calculating open_max was taken from DtSvc/DtUtil1/CmdMain.c
4824 MarkFileDescriptors (
4832 open_max = sysconf(_SC_OPEN_MAX);
4834 if (open_max == -1) {
4838 #if defined(USL) || defined(__uxp__) || defined(_AIX)
4839 open_max = FOPEN_MAX;
4841 open_max = FD_SETSIZE;
4843 #endif /* _SUN_OS */
4846 for (i = start_fd; i < open_max; i++)
4847 (void) fcntl (i, cmd, data);