2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: SmRestore.c /main/26 1998/12/14 20:13:07 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
30 /*************************************<+>*************************************
31 *****************************************************************************
35 ** Project: HP DT Session Manager (dtsession)
39 ** This file contains functions that are in charge of restoring state.
40 ** When the session manager is first started, it restores the state that
41 ** was either last saved (home state), or last exited (current state). The
42 ** state restored depends on values the user has configured.
46 *******************************************************************
47 ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
48 ** reserved. Copying or other reproduction of this program
49 ** except for archival purposes is prohibited without prior
50 ** written consent of Hewlett-Packard Company.
51 ********************************************************************
55 *****************************************************************************
56 *************************************<+>*************************************/
61 #ifdef _SUN_OS /* to get the define for NOFILE */
62 #include <sys/param.h>
64 #include <sys/types.h>
67 #include <X11/apollosys.h> /* for pid_t struct in hp-ux sys/types.h */
69 #include <sys/socket.h>
71 #include <netinet/in.h>
76 #include <X11/Intrinsic.h>
77 #include <X11/Xutil.h>
78 #include <X11/Xatom.h>
79 #include <X11/StringDefs.h>
80 #include <X11/keysymdef.h>
81 #include <X11/SM/SMlib.h>
85 # define Va_start(a,b) va_start(a,b)
88 #include <Dt/Message.h>
89 #include <Dt/CommandM.h>
90 #include <Dt/Connect.h>
93 #include <Dt/UserMsg.h>
94 #include <Dt/SessionM.h>
95 #include <Dt/EnvControlP.h>
96 #include <Dt/Utility.h>
97 #include <Dt/MsgLog.h>
99 #include <Dt/CmdInv.h>
100 #include <Dt/ActionUtilP.h>
103 #include "SmResource.h"
105 #include "SmCommun.h"
106 #include "SmRestore.h"
107 #include "SmProtocol.h"
108 #include "SmConMgmt.h"
111 #include "SmGlobals.h"
117 #include <X11/Xlibint.h>
123 static const char * DISPLAY_NAME_EQUAL = "DISPLAY=";
124 static const char * DISPLAY_NAME = "DISPLAY";
125 static char * savedDisplay = NULL;
131 #define MAXPATHSM 1023
132 #define MAX_QUOTE_DEPTH 10
134 #define SM_MAX_ARGS MAXLINE
136 #if defined (SVR4) || defined (__osf__)
137 #define REMOTE_CMD_STRING "rsh %s -n %s &"
139 #define REMOTE_CMD_STRING "remsh %s -n %s &"
148 unsigned char *hostPtr;
149 unsigned char *cmdPtr;
153 * Variables global to this module only
155 static XtResource settingsResources[] =
157 {SmNaccelNum, SmCaccelNum, XtRInt, sizeof(int),
158 XtOffset(SessionSettingsPtr, accelNum),
159 XtRImmediate, (XtPointer) -1},
160 {SmNaccelDenom, SmCaccelDenom, XtRInt, sizeof(int),
161 XtOffset(SessionSettingsPtr, accelDenom),
162 XtRImmediate, (XtPointer) -1},
163 {SmNthreshold, SmCthreshold, XtRInt, sizeof(int),
164 XtOffset(SessionSettingsPtr, threshold),
165 XtRImmediate, (XtPointer) -1},
167 {SmNtimeout, SmCtimeout, XtRInt, sizeof(int),
168 XtOffset(SessionSettingsPtr, timeout),
169 XtRImmediate, (XtPointer) -1},
170 {SmNinterval, SmCinterval, XtRInt, sizeof(int),
171 XtOffset(SessionSettingsPtr, interval),
172 XtRImmediate, (XtPointer) -1},
173 {SmNpreferBlank, SmCpreferBlank, XtRInt, sizeof(int),
174 XtOffset(SessionSettingsPtr, preferBlank),
175 XtRImmediate, (XtPointer) 0},
176 {SmNallowExp, SmCallowExp, XtRInt, sizeof(int),
177 XtOffset(SessionSettingsPtr, allowExp),
178 XtRImmediate, (XtPointer) 0},
180 {SmNfontPath, SmCfontPath, XtRString, sizeof(String),
181 XtOffset(SessionSettingsPtr, fontDirs), XtRString, (XtPointer) ""},
183 {SmNkeyClick, SmCkeyClick, XtRInt, sizeof(int),
184 XtOffset(SessionSettingsPtr, kbdState.key_click_percent),
185 XtRImmediate, (XtPointer) -1},
186 {SmNbellPercent, SmCbellPercent, XtRInt, sizeof(int),
187 XtOffset(SessionSettingsPtr, kbdState.bell_percent),
188 XtRImmediate, (XtPointer) -1},
189 {SmNbellPitch, SmCbellPitch, XtRInt, sizeof(int),
190 XtOffset(SessionSettingsPtr, kbdState.bell_pitch),
191 XtRImmediate, (XtPointer) -1},
192 {SmNbellDuration, SmCbellDuration, XtRInt, sizeof(int),
193 XtOffset(SessionSettingsPtr, kbdState.bell_duration),
194 XtRImmediate, (XtPointer) -1},
195 {SmNledMask, SmCledMask, XtRInt, sizeof(int),
196 XtOffset(SessionSettingsPtr, kbdState.led_mask),
197 XtRImmediate, (XtPointer) 0},
198 {SmNglobalRepeats, SmCglobalRepeats, XtRInt, sizeof(int),
199 XtOffset(SessionSettingsPtr, kbdState.global_auto_repeat),
200 XtRImmediate, (XtPointer) 2},
201 {SmNautoRepeats, SmCautoRepeats, XtRString, sizeof(String),
202 XtOffset(SessionSettingsPtr, autoRepeats), XtRString, (XtPointer) ""},
204 {SmNbuttonMap, SmCbuttonMap, XtRString, sizeof(String),
205 XtOffset(SessionSettingsPtr, buttonMap), XtRString, (XtPointer) ""},
207 {SmNnumKeyCode, SmCnumKeyCode, XtRInt, sizeof(int),
208 XtOffset(SessionSettingsPtr, numKeyCode), XtRImmediate, (XtPointer) 0},
209 {SmNkeySymsPerKey, SmCkeySymsPerKey, XtRInt, sizeof(int),
210 XtOffset(SessionSettingsPtr, keySymPerCode),
211 XtRImmediate, (XtPointer) 0},
212 {SmNkeySyms, SmCkeySyms, XtRString, sizeof(String),
213 XtOffset(SessionSettingsPtr, keySyms), XtRString, (XtPointer) ""},
215 {SmNmaxKeyPerMod, SmCmaxKeyPerMod, XtRInt, sizeof(int),
216 XtOffset(SessionSettingsPtr, maxKeyPerMod),
217 XtRImmediate, (XtPointer) 0},
218 {SmNmodMap, SmCmodMap, XtRString, sizeof(String),
219 XtOffset(SessionSettingsPtr, modSyms),
220 XtRString, (XtPointer) ""},
222 {SmNdidQuerySettings, SmCdidQuerySettings, XtRBoolean, sizeof(Boolean),
223 XtOffset(SessionSettingsPtr, didQuery),
224 XtRImmediate, (XtPointer) False},
225 {SmNshutDownState, SmCshutDownState, XtRInt, sizeof(int),
226 XtOffset(SessionSettingsPtr, confirmMode),
227 XtRImmediate, (XtPointer) 1},
228 {SmNshutDownMode, SmCshutDownMode, XtRInt, sizeof(int),
229 XtOffset(SessionSettingsPtr, startState),
230 XtRImmediate, (XtPointer) 4},
234 * Variables used for parsing code
237 static unsigned char fallBackLine[MAXLINE+2]; /* line buffer */
238 static unsigned char *line; /* line buffer */
239 static FILE *cfileP = NULL; /* fopen'ed configuration file or NULL */
240 static int linec = 0; /* line counter for parser */
241 static unsigned char *parseP = NULL; /* pointer to parse string */
242 static int fileSize = 0;
243 char **smExecArray = NULL;
246 * Variables used for remote execution
248 static int numRemoteExecs = 0;
249 unsigned char *remoteBuf[MAX_SCREENS_SAVED];
250 unsigned int actRemoteSize[MAX_SCREENS_SAVED];
251 RemoteReq remoteBufPtr[MAX_REMOTE_CLIENTS];
252 static char localHost[MAXHOSTNAMELEN];
253 static char ** ignoreEnvPtr = NULL;
256 * Timeout for workspace manager handshake
258 static Boolean wmTimeout;
261 * These lines were added to support the builtin
265 char tmpExecWmFile[MAXPATHSM+1];
266 static Boolean localWmLaunched = False;
269 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
270 * End of lines were added to support the builtin
285 "*XmTextField*FontList",
286 "*DtEditor*textFontList",
291 static char *fontclass[] = {
299 "*XmTextField*FontList",
300 "*DtEditor*textFontList",
309 static int RestoreSettings( void ) ;
310 static int RestoreClients( void ) ;
311 static unsigned char * GetNextLine( void ) ;
312 static unsigned int PeekAhead( unsigned char *, unsigned int ) ;
313 static unsigned char * GetSmartString( unsigned char **) ;
314 static void ForkWM( void ) ;
315 static int FillCmdBuf( unsigned char *, unsigned char **,
316 unsigned int *, unsigned int *,
317 unsigned int, unsigned int *) ;
318 static int FillRemoteBuf( unsigned char *, unsigned char *,
319 unsigned char *, unsigned char **,
320 unsigned int *, unsigned int *, unsigned int) ;
321 static int FillHintBuf(unsigned char *, unsigned char **,
322 unsigned int *, unsigned int *,
323 unsigned int, unsigned int *);
324 static void WaitForWM( void ) ;
325 static void HandleWMClientMessage(Widget smWidget, XtPointer dummy,
327 static void WaitWMTimeout( XtPointer , XtIntervalId *) ;
328 static void FixEnvironmentData( void ) ;
329 static void ResetScreenInfo(unsigned char **,
330 int *, unsigned int *,
333 static void RemoteRequestFailed(char *, void *);
334 static void RemoteRequestSucceeded(char *, void *);
336 static void SetTemporaryDisplay (
339 int RestorePreferences(char *filename);
341 static void RestoreDisplay (
344 static Boolean StartLocalClient (
350 Boolean useIgnoreEnvResource);
352 static Boolean StartRemoteClient (
358 Boolean useIgnoreEnvResource);
360 static Boolean CheckRequiredProperties (
361 XSMPClientDBRecPtr pDbRec,
362 char * databaseName);
364 static Boolean CheckRequiredFields (
365 ProxyClientDBRecPtr pDbRec,
369 static void LogXSMPOpenDatabaseFailure (
371 DtMsgLogType msgType,
374 static void LogMissingPropertyMessage (
375 XSMPClientDBRecPtr pDbRec,
378 DtMsgLogType msgType);
380 static void LogCWDMessage (
385 static char ** RemoveEnvironmentVars (
388 static void MarkFileDescriptors (
394 /*************************************<->*************************************
401 * Sets _DT_SM_STATE_INFO for dtstyle indicating compatibility mode
414 * The only thing dtstyle should be looking at is the compatMode
416 *************************************<->***********************************/
418 SetCompatState( void )
423 * BEFORE any clients are started
424 * set a property on the top level window
425 * which lets the style manager know what state the sm is in
427 state.flags = SM_STATE_ALL;
428 state.smStartState = 0;
429 state.smConfirmMode = 0;
430 state.smCompatMode = True;
431 state.smSendSettings = False;
432 state.smCoverScreen = True;
433 state.smLockOnTimeoutStatus = smGD.lockOnTimeoutStatus;
434 state.smCycleTimeout = 0;
435 state.smLockTimeout = 0;
436 state.smSaverTimeout = 0;
438 state.smDisplaySpecific = smGD.displaySpecific;
440 _DtSetSmState(smGD.display, smGD.topLevelWindow, &state);
442 XFlush(smGD.display);
446 } /* END OF FUNCTION SetCompatState */
449 /*************************************<->*************************************
456 * This function fiddles with our signal handling and calls the
457 * system() function to invoke a unix command.
462 * pchCmd = string with the command we want to exec.
470 * The system() command is touchy about the SIGCLD behavior. Restore
471 * the default SIGCLD handler during the time we run system().
473 *************************************<->***********************************/
476 SystemCmd (char *pchCmd)
478 void (*signalHandler) ();
480 signalHandler = (void (*)())signal (SIGCHLD, SIG_DFL);
484 signal (SIGCHLD, signalHandler);
485 } /* END OF FUNTION SystemCmd */
489 /*************************************<->*************************************
505 * When this routine is finished, all settings and resources will be restored.
506 * Clients may not be, as they are actually restored by different processes.
508 *************************************<->***********************************/
514 char convertCommand[MAXPATHSM+1];
516 Boolean fixedBuffer = False;
519 Boolean useXrmDB = False;
522 * Restore all the X settings which were active at the time of shutdown
526 if (smGD.sessionType == HOME_SESSION)
527 smSettings.startState = DtSM_HOME_STATE;
529 smSettings.startState = DtSM_CURRENT_STATE;
532 * BEFORE any clients are started
533 * set a property on the top level window
534 * which lets the style manager know what state the sm is in
536 state.flags = SM_STATE_ALL;
537 state.smStartState = smSettings.startState;
538 state.smConfirmMode = smSettings.confirmMode;
539 state.smCompatMode = smGD.compatMode;
540 state.smSendSettings = !smRes.querySettings;
541 state.smLockOnTimeoutStatus = smGD.lockOnTimeoutStatus;
542 state.smCycleTimeout = smSaverRes.cycleTimeout;
543 state.smLockTimeout = smSaverRes.lockTimeout;
544 state.smSaverTimeout = smSaverRes.saverTimeout;
545 state.smRandom = smSaverRes.random;
546 state.smDisplaySpecific = smGD.displaySpecific;
548 _DtSetSmState(smGD.display, smGD.topLevelWindow, &state);
550 saver.saverList = smGD.saverList;
551 _DtSetSmSaver(smGD.display, smGD.topLevelWindow, &saver);
554 * Set up the Property telling all applications what session is being
557 XaSmRestoreMode = XInternAtom(smGD.display, _XA_DT_RESTORE_MODE, False);
558 XChangeProperty(smGD.display, RootWindow(smGD.display, 0),
559 XaSmRestoreMode, XA_STRING, 8, PropModeReplace,
560 (unsigned char *)smGD.restoreSession, strlen(smGD.restoreSession));
561 XFlush(smGD.display);
564 * Check the session database and either parse it as an
565 * Xrm-database or the CDE1.0 format
567 if ((pchar = strrchr (smGD.clientPath, '/')) != NULL)
570 if ((*pchar != '\0') && (!strcmp (pchar, SM_CLIENT_FILE2)))
576 return (StartXSMPSession (smGD.clientPath));
580 * Malloc line for parsing.
582 status = stat(smGD.clientPath, &buf);
585 fileSize = buf.st_size;
588 if (fileSize < MAXLINE + 1)
590 fileSize = MAXLINE + 1;
593 line = (unsigned char *) malloc ((fileSize + 1) * sizeof(char *));
597 fileSize = MAXLINE + 1;
600 cfileP = fopen(smGD.clientPath, "r");
603 PrintErrnoError(DtError, smNLS.cantOpenFileString);
604 if (!fixedBuffer && line)
606 SM_FREE((char *)line);
613 if (!fixedBuffer && line)
615 SM_FREE((char *)line);
624 /*************************************<->*************************************
631 * Start up the window manager. The default is to start dtmwm unless
632 * another one is specified in a resource.
645 * When this routine is finished, all settings and resources will be restored.
646 * Clients may not be, as they are actually restored by different processes.
648 *************************************<->***********************************/
652 char wmStartupErrorString[(2 * MAXPATHSM) + 1];
653 char localWmErrorString[(2 * MAXPATHSM) + 1];
654 Boolean goodWmStartup = True;
657 if((smGD.wmStartup == NULL) || (*smGD.wmStartup == 0))
663 CreateExecString(smGD.wmStartup);
666 * check to see if the wmStartup string exists and is
669 status = access(smExecArray[0], F_OK | X_OK);
672 goodWmStartup = False;
673 CreateExecString(CDE_INSTALLATION_TOP "/bin/dtwm");
676 if(smExecArray[0] != NULL)
678 (void) StartClient(smExecArray[0], smExecArray, NULL, NULL,
679 NULL, False, False, -1);
684 * We used to start the message server before the window
685 * manager and then if the message server did not start
686 * we would exit. Now we start the window manager, then
687 * start the message server and then wait for the window
688 * manager. This seems to improve performance.
693 if (goodWmStartup == False)
695 sprintf(wmStartupErrorString, GETMESSAGE(16, 7,
696 "The wmStartupCommand resource is set to:\n\n"
698 "This file does not exist or is not executable.\n"
699 CDE_INSTALLATION_TOP "/bin/dtwm will be started "
702 PrintError(DtError, wmStartupErrorString);
708 * These lines were added to support the builtin
712 if (localWmLaunched && wmTimeout)
714 if (!smGD.userSetWaitWmTimeout)
716 smRes.waitWmTimeout = smGD.savedWaitWmTimeout;
719 localWmLaunched = False;
721 * A special version of a built-in Xterminal dtwm
722 * was attempted and failed.
723 * Try to launch .../dt/bin/dtwm instead
726 CreateExecString(CDE_INSTALLATION_TOP "/bin/dtwm");
727 if(smExecArray[0] != NULL)
729 (void) StartClient(smExecArray[0], smExecArray, NULL,
730 NULL, NULL, False, False, -1);
733 sprintf(localWmErrorString, GETMESSAGE(16, 9,
734 "The following window manager did not start:\n\n"
736 "This message indicates you tried to start a\n"
737 "window manager that is built into an X terminal.\n"
738 "This will only work with X terminals that support this protocol.\n"
739 CDE_INSTALLATION_TOP "/bin/dtwm will be started instead.\n"),
741 PrintError(DtError, localWmErrorString);
744 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
745 * End of lines were added to support the builtin
754 /*************************************<->*************************************
761 * Reloads RESOURCE_MANAGER during running session
773 *************************************<->***********************************/
776 ReloadResources(void)
779 * Load sys.resources and .Xdefaults
781 RestoreResources(True,
788 * Merge _DT_SM_PREFERENCES
790 RestorePreferences(NULL);
796 /*************************************<->*************************************
798 * RestoreResources (errorHandlerInstalled, options ... )
803 * Calls routines responsible for restoring resources.
804 * Resources are restored by a fork and exec of dtsession_res.
817 * When this routine is finished, all settings and resources will be restored.
818 * Clients may not be, as they are actually restored by different processes.
820 *************************************<->***********************************/
823 RestoreResources( Boolean errorHandlerInstalled, ... )
826 int childStatus, execStatus, i;
832 * Check for alternate resource loader.
834 if ((pgrm = getenv("DTLOADRESOURCES")) == NULL)
836 pgrm = CDE_INSTALLATION_TOP "/bin/dtsession_res";
840 * By convention, exec() wants arg0 to be the program name. Ex: if pgrm
841 * is /usr/dt/bin/dtsession_res, the program name is dtsession_res.
842 * If all else fails, use pgrm.
844 argv[0] = (p = strrchr(pgrm, '/')) != NULL && *(p+1) != '\0' ? p+1 : pgrm;
847 Va_start(args,errorHandlerInstalled);
851 argv[i] = va_arg(args, char *);
857 * if an error handler is installed - remove it
859 if(errorHandlerInstalled)
861 sigaction(SIGCHLD, &smGD.defvec, (struct sigaction *) NULL);
865 * Fork and exec the xrdb process to load in the file created by
866 * writing out the resource manager string generated by the last
867 * session termination.
870 for(i = 0;(i < 10) && ((forkrc = vfork()) < 0);i++)
881 PrintErrnoError(DtError, smNLS.cantForkClientString);
886 * Fork succeeded - now do the exec
890 SetSIGPIPEToDefault ();
894 * Set the gid of the process back from bin
897 setregid(smGD.runningGID, smGD.runningGID);
899 setgid(smGD.runningGID);
900 setegid(smGD.runningGID);
903 #if defined(__osf__) || defined(CSRG_BASED)
909 MarkFileDescriptors (3, F_SETFD, 1);
911 execStatus = execv(pgrm, argv);
915 char clientMessage[MAXPATHLEN + 256];
917 sprintf(clientMessage, ((char *)GETMESSAGE(16, 1, "Unable to exec process %s. No session resources will be restored.")), pgrm);
918 PrintErrnoError(DtError, clientMessage);
923 while(wait(&childStatus) != forkrc);
926 * if an error handler is installed - remove it
928 if(errorHandlerInstalled)
930 sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
937 /*************************************<->*************************************
939 * RestorePreferences ( filename)
945 * This routine has two roles:
947 * 1) If 'filename' specified, the content of filename is read, and
948 * _DT_SM_PREFERENCES is populated with its content. This is used
949 * at session startup to set the initial state of _DT_SM_PREFERENCES.
951 * 2) If 'filename' is NULL, the content of _DT_SM_PREFERENCES is
952 * merged into RESOURCE_MANAGER. This is used when resources are
953 * reloaded at user request during a session.
966 *************************************<->***********************************/
978 struct stat statinfo;
980 if(access(filename,R_OK) != 0)
986 * Determine size of file.
988 if (stat(filename, &statinfo) == -1)
996 if ((data = (char *)SM_MALLOC(statinfo.st_size + 1)) == NULL)
1002 * Read file into memory.
1004 if ((fp = fopen(filename, "r")) == NULL)
1010 size = fread(data, 1, statinfo.st_size, fp);
1012 if (size == statinfo.st_size)
1015 * Merge .Xdefaults string into RESOURCE_MANAGER database, and
1016 * also convert to Xrm database form for later subtraction.
1019 _DtAddResString(smGD.display, data, _DT_ATR_PREFS);
1027 * Read string from _DT_SM_PREFERENCES
1029 data = _DtGetResString(smGD.display, _DT_ATR_PREFS);
1032 * Merge string into RESOURCE_MANAGER
1034 _DtAddResString(smGD.display, data, _DT_ATR_RESMGR);
1043 /*************************************<->*************************************
1045 * RestoreSettings ()
1050 * In charge of restoring all settings. Settings are stored in resource
1051 * format so it gets the values by getting the resource values stored in
1052 * a resource file that was created by the session manager.
1057 * smGD.settingPath = path that points to the settings resource file.
1066 * This routine messes with the actual strings returned by the resource
1067 * manager by tokenizing them, so these session settings resources should
1068 * not be accessed again.
1070 *************************************<->***********************************/
1072 RestoreSettings( void )
1074 XrmDatabase smBase = NULL;
1075 XKeyboardControl kbdControl;
1077 char **restorePtrArray, **tmpRestore;
1078 char *restoreCharArray;
1079 int numArgs, ptrSize, charSize;
1082 KeySym *tmpSyms, codeSym;
1085 XModifierKeymap restoreMod;
1089 restorePtrArray = (char **) SM_MALLOC (ptrSize * sizeof(char *));
1090 restoreCharArray = (char *) SM_MALLOC (charSize * sizeof(char));
1091 if((restorePtrArray == NULL) || (restoreCharArray == NULL))
1093 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1095 if(restorePtrArray != NULL)
1097 SM_FREE((char *) restorePtrArray);
1101 if(restoreCharArray != NULL)
1103 SM_FREE(restoreCharArray);
1110 * Load the resources from the SM database file
1112 if (smGD.settingPath[0] != 0)
1114 smBase = XrmGetFileDatabase(smGD.settingPath);
1118 PrintError(DtError, GETMESSAGE(16, 2, "Invalid client settings file. No settings restored."));
1123 XrmMergeDatabases(smBase, &(smGD.display->db));
1128 * Retrieve the session settings file from the database
1130 XtGetApplicationResources(smGD.topLevelWid, (XtPointer) &smSettings,
1131 settingsResources, XtNumber(settingsResources),
1135 * Copy any string resources since they may be overwritten in
1138 smGD.fontDirs = SmNewString(smSettings.fontDirs);
1139 smGD.autoRepeats = SmNewString(smSettings.autoRepeats);
1140 smGD.buttonMap = SmNewString(smSettings.buttonMap);
1141 smGD.keySyms = SmNewString(smSettings.keySyms);
1142 smGD.modSyms = SmNewString(smSettings.modSyms);
1146 * This is provided for backward compatibility sake. The values that
1147 * confirmMode can take have changed
1149 if(smSettings.confirmMode == DtSM_ASK_STATE)
1151 smSettings.confirmMode = DtSM_VERBOSE_MODE;
1155 * If the user has previously used the "query" method, and now wishes
1156 * to use "only what I've customized" method, then we have to start
1157 * from scratch. So don't set anything until customizer tells me to
1159 if((smSettings.didQuery == True) && (smRes.querySettings == False))
1161 SM_FREE((char *) restorePtrArray);
1162 SM_FREE(restoreCharArray);
1167 * Restore pointer control settings
1169 if((smSettings.accelNum > -1 ) || (smSettings.threshold > -1))
1171 XChangePointerControl(smGD.display, True, True,
1172 smSettings.accelNum,
1173 smSettings.accelDenom,
1174 smSettings.threshold);
1175 smToSet.pointerChange = True;
1179 smToSet.pointerChange = False;
1183 * Restore screen saver settings if any are set to non-default
1186 if ((smSettings.timeout > -1) || (smSettings.interval > -1) ||
1187 (smSaverRes.saverTimeout > -1) || (smSaverRes.lockTimeout > -1) ||
1188 (smSaverRes.cycleTimeout > -1))
1192 * For the time between Screen Savers, use the cycleTimeout
1193 * if the user has set this value. Otherwise, use the interval
1194 * value that was set when the session was saved.
1196 if (smSaverRes.cycleTimeout < 0)
1198 screenSaverVals.smInterval = smSettings.interval;
1202 screenSaverVals.smInterval = smSaverRes.cycleTimeout;
1206 * For the screen saver time, use the minimum of the values set for
1207 * saverTimeout or lockTimeout if the user has set one of these
1210 * Otherwise, use the Timeout value that was set when the
1211 * session was saved.
1213 * If it is not set, then use the minimum of the values set for
1214 * saverTimeout or lockTimeout. Set timeout to the Timeout value
1217 if ((smSaverRes.saverTimeout > -1) ||
1218 (smSaverRes.lockTimeout > -1))
1220 if (smSaverRes.saverTimeout > -1)
1222 if ((smSaverRes.lockTimeout > -1) &&
1223 (smSaverRes.lockTimeout < smSaverRes.saverTimeout))
1225 screenSaverVals.smTimeout = smSaverRes.lockTimeout;
1229 screenSaverVals.smTimeout = smSaverRes.saverTimeout;
1234 screenSaverVals.smTimeout = smSaverRes.lockTimeout;
1239 screenSaverVals.smTimeout = smSettings.timeout;
1241 screenSaverVals.smPreferBlank = smSettings.preferBlank;
1242 screenSaverVals.smAllowExp = smSettings.allowExp;
1244 /* Notify X of the new screen saver values */
1245 XSetScreenSaver(smGD.display, screenSaverVals.smTimeout,
1246 screenSaverVals.smInterval,
1247 screenSaverVals.smPreferBlank,
1248 screenSaverVals.smAllowExp);
1251 * If using timeout or interval values that were
1252 * previously saved, then set flag to indicate that they
1253 * should be saved again when the state for the session
1256 if ((smSettings.timeout > -1) || (smSettings.interval > -1))
1258 smToSet.screenSavChange = True;
1262 smToSet.screenSavChange = False;
1268 smToSet.screenSavChange = False;
1272 * Get the font path. Then set it.
1274 tmpRestore = restorePtrArray;
1276 *tmpRestore = strtok(smGD.fontDirs, ",");
1278 while(*tmpRestore != NULL)
1280 numArgs++; tmpRestore++;
1281 *tmpRestore = strtok(NULL, ",");
1282 if((numArgs >= ptrSize) && (*tmpRestore != NULL))
1285 restorePtrArray = (char **)SM_REALLOC((char *)
1286 restorePtrArray, ptrSize *
1288 if(restorePtrArray == NULL)
1290 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1291 SM_FREE(restoreCharArray);
1299 XSetFontPath(smGD.display, restorePtrArray, numArgs);
1303 * Restore the keyboard control information. In order for it
1304 * to be restored it has to be changed from a XKeyboardState
1305 * format to an XKeyboardControl format.
1307 if((smSettings.kbdState.key_click_percent > -1) ||
1308 (smSettings.kbdState.bell_percent > -1) ||
1309 (smSettings.kbdState.bell_pitch > -1) ||
1310 (smSettings.kbdState.bell_duration > -1))
1314 if((smSettings.kbdState.bell_percent > -1) ||
1315 (smSettings.kbdState.bell_pitch > -1) ||
1316 (smSettings.kbdState.bell_duration > -1))
1318 kbdControl.bell_percent = smSettings.kbdState.bell_percent;
1319 kbdControl.bell_pitch = smSettings.kbdState.bell_pitch;
1320 kbdControl.bell_duration = smSettings.kbdState.bell_duration;
1321 kbdControlMask |= (KBBellPercent | KBBellPitch | KBBellDuration);
1322 smToSet.audioChange = True;
1323 audioVals.smBellPercent = smSettings.kbdState.bell_percent;
1324 audioVals.smBellPitch = smSettings.kbdState.bell_pitch;
1325 audioVals.smBellDuration = smSettings.kbdState.bell_duration;
1329 smToSet.audioChange = False;
1332 if((smSettings.kbdState.key_click_percent > -1) ||
1333 (smSettings.kbdState.global_auto_repeat != AutoRepeatModeOn))
1335 kbdControl.key_click_percent =
1336 smSettings.kbdState.key_click_percent;
1337 kbdControlMask |= KBKeyClickPercent;
1338 smToSet.keyboardChange = True;
1339 keyboardVals.smKeyClickPercent = kbdControl.key_click_percent;
1343 smToSet.keyboardChange = False;
1348 * NOTICE THAT THE LED'S DON'T GET RESET. THIS IS BECAUSE LED STUFF
1349 * IS MACHINE DEPENDENT.
1352 * Set the auto repeat stuff
1354 tmpKey = strtok(smGD.autoRepeats, ",");
1355 if((tmpKey == NULL) &&
1356 ((smSettings.kbdState.global_auto_repeat == AutoRepeatModeOff) ||
1357 (smSettings.kbdState.global_auto_repeat == AutoRepeatModeOn)))
1359 smToSet.keyboardChange = True;
1360 kbdControl.auto_repeat_mode =
1361 smSettings.kbdState.global_auto_repeat;
1362 kbdControlMask |= KBAutoRepeatMode;
1363 XChangeKeyboardControl(smGD.display, kbdControlMask, &kbdControl);
1364 keyboardVals.smGlobalAutoRepeat =
1365 smSettings.kbdState.global_auto_repeat;
1371 smToSet.keyboardChange = True;
1372 kbdControl.auto_repeat_mode = smSettings.kbdState.global_auto_repeat;
1373 kbdControlMask |= KBAutoRepeatMode;
1374 XChangeKeyboardControl(smGD.display,
1375 kbdControlMask, &kbdControl);
1376 kbdControl.auto_repeat_mode = AutoRepeatModeOn;
1377 kbdControlMask = KBAutoRepeatMode | KBKey;
1379 * This is only involked when there is auto repeats set for
1380 * specific keys only. It is VERY SLOW code so unless you
1381 * have to save off auto repeats for single keys - DONT
1383 while(tmpKey != NULL)
1385 kbdControl.key = atoi(tmpKey);
1386 XChangeKeyboardControl(smGD.display,
1387 kbdControlMask, &kbdControl);
1388 tmpKey = strtok(NULL, ",");
1393 if(kbdControlMask != 0)
1395 XChangeKeyboardControl(smGD.display,
1396 kbdControlMask, &kbdControl);
1403 smToSet.audioChange = False;
1404 smToSet.keyboardChange = False;
1408 * Restore the button mappings
1411 tmpKey = strtok(smGD.buttonMap, ",");
1415 smToSet.pointerMapChange = True;
1419 smToSet.pointerMapChange = False;
1422 while(tmpKey != NULL)
1424 restoreCharArray[numArgs] = (char) atoi(tmpKey);
1426 tmpKey = strtok(NULL, ",");
1427 if((numArgs >= charSize) && (tmpKey != NULL))
1430 restoreCharArray = (char *) SM_REALLOC(restoreCharArray,
1431 charSize * sizeof(char));
1432 if(restoreCharArray == NULL)
1434 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1435 SM_FREE((char *)restorePtrArray);
1443 XSetPointerMapping(smGD.display, (unsigned char *)restoreCharArray, numArgs);
1446 * Copy the pointer map into the saved map for logout
1448 smToSet.numButton = ((numArgs > 5) ? 5 : numArgs);
1449 for(i = 0; i < smToSet.numButton;i++)
1451 smToSet.pointerMap[i] = restoreCharArray[i];
1456 * Restore the key mappings
1458 if(smSettings.numKeyCode > 0)
1460 tmpSyms = (KeySym *) restoreCharArray;
1461 symSize = (charSize * sizeof(char)) / sizeof(KeySym);
1462 tmpKey = strtok(smGD.keySyms, ",");
1463 for(i = 0;tmpKey != NULL;i++)
1465 tmpSyms[i] = (KeySym) atol(tmpKey);
1466 tmpKey = strtok(NULL, ",");
1468 if((numArgs >= symSize) && (tmpKey != NULL))
1471 symSize = (charSize * sizeof(char))/sizeof(KeySym);
1472 restoreCharArray = (char *) SM_REALLOC(restoreCharArray,
1473 (charSize * sizeof(char)));
1474 if(restoreCharArray == NULL)
1476 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
1477 SM_FREE((char *) restorePtrArray);
1480 tmpSyms = (KeySym *) restoreCharArray;
1483 numArgs /= smSettings.keySymPerCode;
1484 XChangeKeyboardMapping(smGD.display, (KeyCode)
1485 smGD.display->min_keycode,
1486 smSettings.keySymPerCode, tmpSyms,
1491 * Restore the modifier mappings
1493 tmpCode = (KeyCode *) restoreCharArray;
1494 tmpKey = strtok(smGD.modSyms, ",");
1497 for(i = 0;i < (8 * smSettings.maxKeyPerMod);i++)
1501 codeSym = (KeySym) atol(tmpKey);
1504 tmpCode[i] = XKeysymToKeycode(smGD.display, codeSym);
1508 tmpCode[i] = (KeyCode) 0;
1513 tmpCode[i] = (KeyCode) 0;
1515 tmpKey = strtok(NULL, ",");
1517 restoreMod.max_keypermod = smSettings.maxKeyPerMod;
1518 restoreMod.modifiermap = tmpCode;
1519 XSetModifierMapping(smGD.display, &restoreMod);
1522 SM_FREE((char *) restorePtrArray);
1523 SM_FREE(restoreCharArray);
1530 /*************************************<->*************************************
1532 * RestoreIndependentResources ()
1537 * In charge of restoring the resources that help make the session more
1538 * resolution and language independent - only restored if they are
1539 * necessary (lang || resolution has changed) and exist
1544 * smResources = global pointer to the resources to be restored by the SM
1554 *************************************<->***********************************/
1556 RestoreIndependentResources( void )
1560 unsigned long nitems, leftover;
1561 unsigned char *data = NULL;
1563 XrmValue fontResourceReturn;
1564 char *currentLangPtr, *resValRet, *sessionType;
1566 int intYRes[2], status,i;
1569 Boolean resIndep = False, resRet;
1572 if(((smGD.sessionLang == NULL) || (*smGD.sessionLang == 0)) &&
1573 (smRes.displayResolution == 0))
1576 * No saved info to draw from - nothing new is added
1581 currentLangPtr = getenv("LANG");
1583 fltYRes = ((float) DisplayHeight(smGD.display, 0) /
1584 (float) DisplayHeightMM(smGD.display, 0)) * 1000;
1586 if(fltYRes < MED_RES_Y_RES)
1588 intYRes[0] = LOW_RES_Y_RES;
1589 sessionRes = SM_LOW_RES_EXT;
1593 if(fltYRes >= HIGH_RES_Y_RES)
1595 intYRes[0] = HIGH_RES_Y_RES;
1596 sessionRes = SM_HIGH_RES_EXT;
1600 intYRes[0] = MED_RES_Y_RES;
1601 sessionRes = SM_MED_RES_EXT;
1605 if(smRes.displayResolution < MED_RES_Y_RES)
1607 intYRes[1] = LOW_RES_Y_RES;
1611 if(smRes.displayResolution >= HIGH_RES_Y_RES)
1613 intYRes[1] = HIGH_RES_Y_RES;
1617 intYRes[1] = MED_RES_Y_RES;
1622 * If the resolution or the language has changed -
1623 * load the language/resolution independent fonts if
1624 * they exist in the users home directory or in the system
1626 if((strcmp(currentLangPtr, smGD.sessionLang)) ||
1627 (intYRes[0] != intYRes[1]))
1629 char *fontPath = SM_MALLOC(MAXPATHLEN + 1);
1631 if(smGD.sessionType == HOME_SESSION)
1633 sessionType = SM_HOME_FONT_DIRECTORY;
1637 sessionType = SM_CURRENT_FONT_DIRECTORY;
1640 sprintf(fontPath, "%s/%s/%s/%s.%s", smGD.savePath, sessionType,
1641 currentLangPtr, SM_FONT_FILE, sessionRes);
1642 status = stat(fontPath, &buf);
1646 * User has nothing there - look in the system defaults
1647 * first in the language dep -then in lang independent
1651 if((currentLangPtr != NULL) && (*currentLangPtr != 0))
1653 strcat(fontPath, "/");
1654 strcat(fontPath, currentLangPtr);
1657 strcat(fontPath, "/");
1658 strcat(fontPath, SM_SYSTEM_FONT_FILE);
1662 status = stat(fontPath, &buf);
1665 if((currentLangPtr != NULL) && (*currentLangPtr != 0) &&
1666 (strcmp(currentLangPtr, "C")))
1668 strcpy(fontPath, "/C/");
1669 strcat(fontPath, SM_SYSTEM_FONT_FILE);
1673 status = stat(fontPath, &buf);
1690 strncpy(smGD.fontPath, fontPath, MAXPATHLEN);
1692 if(resIndep == True)
1696 * add the auxillary resources onto the root window
1698 RestoreResources(True, "-merge", "-file", smGD.fontPath, NULL);
1701 * Load the resources from the RESOURCE_MANAGER
1702 * property on the root window
1704 if(XGetWindowProperty(smGD.display, RootWindow(smGD.display, 0),
1705 XA_RESOURCE_MANAGER,0L,
1706 100000000L,False,XA_STRING,&actualType,
1707 &actualFormat,&nitems,&leftover,
1708 (unsigned char**) &data) == Success)
1710 smBase = XrmGetStringDatabase((char *)data);
1719 PrintError(DtError, GETMESSAGE(16, 6, "Invalid display/language independent resource file. No display/language independent resources will be restored."));
1720 SM_FREE((char *)data);
1726 * Get the new fontlist from the resources and
1727 * Put it on the application shell. Then add
1728 * the auxillary resources into the display struct
1730 resRet = XrmGetResource(smBase, "*fontList", "*FontList",
1731 &resValRet, &fontResourceReturn);
1734 XtSetArg(uiArgs[i], XmNdefaultFontList,
1735 (XmFontList) fontResourceReturn.addr);i++;
1736 XtSetValues(smGD.topLevelWid, uiArgs, i);
1739 * Overwrite the old font preferences, otherwise,
1740 * they'll come back to haunt us if the user logs in again
1741 * under the current language. We need to get the font
1742 * resources which have just been loaded, then overlay
1743 * them onto the _DT_SM_PREFERENCES root property to make
1744 * sure we get them back when we login again.
1746 for (i = 0; i < XtNumber(fonttype); i++)
1748 resRet = XrmGetResource(smBase, fonttype[i], fontclass[i],
1749 &resValRet, &fontResourceReturn);
1753 (char *)SM_MALLOC(fontResourceReturn.size + 30);
1754 bzero(resdata, fontResourceReturn.size + 30);
1755 strcat(resdata, fonttype[i]);
1756 strcat(resdata, ": ");
1757 strcat(resdata, fontResourceReturn.addr);
1758 strcat(resdata, "\n");
1759 _DtAddResString(smGD.display, resdata, _DT_ATR_PREFS);
1764 XrmMergeDatabases(smBase, &(smGD.display->db));
1765 SM_FREE((char *)data);
1769 SM_FREE((char*) fontPath);
1776 /*************************************<->*************************************
1783 * Reads through the client file and restores its contents. A client file
1784 * consists of hints for the workspace manager, actual client commands, and
1785 * remote execution commands. All commands are processed accordingly.
1786 * If this is the first DT 3.0 session for a DT 2.0 user then we will
1787 * also launch the helpviewer. If this is the first DT 3.0 session for a
1788 * DT 2.0 user then we will also run convertVS.sh to change all
1789 * occurances of /usr/bin/X11/hpterm to .../dt/bin/hpterm,
1790 * /usr/bin/X11/xterm to .../dt/bin/xterm and
1791 * /usr/bin/X11/xload to .../dt/bin/xload.
1802 * Any information read from the client file will be mucked with during
1803 * processing, and should not try to be mucked with again.
1805 * WARNING: This routine closes cfileP - not the calling routine
1806 * DOUBLE-WARNING: This routine starts the window manager
1808 *************************************<->***********************************/
1810 RestoreClients( void )
1812 unsigned char *lineP, *string;
1813 char *pch, *dispPtr;
1814 char *dispEnv, *dispSav, *dispEnvHelpview, *dispSavHelpview;
1815 unsigned char *hostPtr=NULL, *cmdPtr=NULL, *hintPtr = NULL;
1816 unsigned char *remoteDisplay;
1819 unsigned char tmpChar[35];
1820 int screenNum = 0, i, j, chlen, numClientsExec;
1821 int numRemoteDone = 0;
1823 Boolean clientsDone = False, wmHandshake = False, cmdInvInit = False;
1824 XClientMessageEvent smToWmMessage;
1827 * These variables are needed to buffer up the commands and then
1828 * execute them (also buffer up hints then put them on the root window
1830 unsigned char *hintsBuf[MAX_SCREENS_SAVED];
1831 unsigned char *cmdBuf[MAX_SCREENS_SAVED];
1832 unsigned int maxHintsSize[MAX_SCREENS_SAVED];
1833 unsigned int actHintsSize[MAX_SCREENS_SAVED];
1834 unsigned int numHints[MAX_SCREENS_SAVED];
1835 unsigned int maxCmdSize[MAX_SCREENS_SAVED];
1836 unsigned int actCmdSize[MAX_SCREENS_SAVED];
1837 unsigned int numCmd[MAX_SCREENS_SAVED];
1838 unsigned int maxRemoteSize[MAX_SCREENS_SAVED];
1841 * Initialize the buffers and their sizes to null and 0. Because of
1842 * all possible combinations - buffers aren't malloc'd until they're
1845 for(i = 0;i<smGD.numSavedScreens;i++)
1849 remoteBuf[i] = NULL;
1850 maxHintsSize[i] = 0;
1851 actHintsSize[i] = 0;
1856 maxRemoteSize[i] = 0;
1857 actRemoteSize[i] = 0;
1861 * Save the contents of the DISPLAY environment variable so that it
1862 * can be restored when we're through
1864 dispEnv = getenv(DISPLAY_NAME);
1867 dispSav = (char *) SM_MALLOC(((strlen(dispEnv) +
1868 strlen(DISPLAY_NAME_EQUAL)) * sizeof(char) + 1));
1869 sprintf(dispSav, "%s%s", DISPLAY_NAME_EQUAL, dispEnv);
1877 displayName = strdup(smGD.display->display_name);
1878 remoteDisplay = (unsigned char *)
1879 SM_MALLOC(sizeof(unsigned char) * (strlen(displayName) + 101));
1882 * Create the display name for locally executing clients
1908 * Create the display name for remotely executing clients.
1909 * These two may or may not be the same
1911 DtGetShortHostname((char *)remoteDisplay, 100);
1914 * Add the display qualifications to the host name
1915 * screen is added at execution time
1917 strcat((char *)remoteDisplay, (char *)dispPtr);
1920 * Intern the atom needed to put the hints on the root window
1921 * This has to be done here because InitProtocol has not been called yet
1923 XaWmDtHints = XInternAtom(smGD.display, _XA_DT_SESSION_HINTS, False);
1925 while(GetNextLine() != NULL)
1928 string = GetSmartString(&lineP);
1929 if( string != NULL && !strcmp((char *)string, "dtsmcmd"))
1931 while((string = GetSmartString(&lineP)) != NULL )
1933 if(!strcmp((char *)string, "-host"))
1936 * Extract a host pointer - host pointers
1937 * only exist on remote executions
1939 string = GetSmartString(&lineP);
1944 if(!strcmp((char *)string, "-cmd"))
1947 * Extract the command pointer from the
1950 string = GetSmartString(&lineP);
1955 if(!strcmp((char *)string, "-screen"))
1958 * Extract the screen number from the command
1960 string = GetSmartString(&lineP);
1961 screenNum = atoi((char *)string);
1966 if(!strcmp((char *)string, "-hints"))
1969 * Extract the hints string
1971 string = GetSmartString(&lineP);
1980 * Now put our information in buffers and reinitialize the pointers
1984 if(FillHintBuf(hintPtr, hintsBuf, maxHintsSize,
1985 actHintsSize, screenNum, numHints) != 0)
1988 * Free all malloc'd buffers and exit
1990 for(i = 0;i < smGD.numSavedScreens;i++)
1992 if(actHintsSize[i] > 0)
1994 SM_FREE((char *) hintsBuf[i]);
1996 if(actCmdSize[i] > 0)
1998 SM_FREE((char *) cmdBuf[i]);
2000 if(actRemoteSize[i] > 0)
2002 SM_FREE((char *) remoteBuf[i]);
2010 if((cmdPtr != NULL) && (hostPtr == NULL))
2012 if(FillCmdBuf(cmdPtr, cmdBuf, maxCmdSize,
2013 actCmdSize,screenNum, &numCmd[screenNum]) != 0)
2016 * Free all malloc'd buffers and exit
2018 for(i = 0;i < smGD.numSavedScreens;i++)
2020 if(actHintsSize[i] > 0)
2022 SM_FREE((char *) hintsBuf[i]);
2024 if(actCmdSize[i] > 0)
2026 SM_FREE((char *) cmdBuf[i]);
2028 if(actRemoteSize[i] > 0)
2030 SM_FREE((char *) remoteBuf[i]);
2039 if((cmdPtr != NULL) && (hostPtr != NULL))
2041 if(FillRemoteBuf(cmdPtr, hostPtr, remoteDisplay,
2042 remoteBuf, maxRemoteSize,
2043 actRemoteSize, screenNum) != 0)
2046 * Free all malloc'd buffers and exit
2048 for(i = 0;i < smGD.numSavedScreens;i++)
2050 if(actHintsSize[i] > 0)
2052 SM_FREE((char *) hintsBuf[i]);
2054 if(actCmdSize[i] > 0)
2056 SM_FREE((char *) cmdBuf[i]);
2058 if(actRemoteSize[i] > 0)
2060 SM_FREE((char *) remoteBuf[i]);
2069 screenNum = XDefaultScreen(smGD.display);
2074 * All done with file so close it off and set descriptor to NULL -
2075 * This is done so that parsing routines can be used with a buffer later
2081 * Now execute all the buffers, put all hints on the root windows
2082 * Do all remote executions
2084 for(i = 0;i < smGD.numSavedScreens;i++)
2087 * Put the root window property on each root window
2089 if(actHintsSize[i] > 0)
2092 * Append number of hints to front of buffer
2094 sprintf((char *)tmpChar, "%d", numHints[i]);
2095 strncpy((char *)hintsBuf[i], (char *)tmpChar,
2096 strlen((char *)tmpChar));
2097 XChangeProperty(smGD.display, RootWindow(smGD.display, i),
2098 XaWmDtHints, XA_STRING, 8, PropModeReplace,
2099 hintsBuf[i], actHintsSize[i]);
2100 SM_FREE((char *) hintsBuf[i]);
2101 XSync(smGD.display, 0);
2109 * Now exec on the local clients - we're doing contention management
2110 * to make sure the system doesn't get swamped
2114 while((actCmdSize[i] == 0) && (i < smGD.numSavedScreens))
2119 envVal = SM_MALLOC(BUFSIZ);
2120 if(i >= smGD.numSavedScreens)
2126 sprintf(envVal,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, i);
2134 * Keep forking one client after the other until the
2135 * memory utilization gets beyond the threshold -
2136 * (but only if the capability exists) Then go to
2137 * window manager handshaking
2139 #ifdef DEBUG_CONT_MANAGEMENT
2140 if(smRes.contManagement & SM_CM_SYSTEM)
2142 fprintf(stderr, "SM_CM_SYSTEM flag set in smRes.contManagement\n");
2144 if(smRes.contManagement & SM_CM_HANDSHAKE)
2146 fprintf(stderr, "SM_CM_HANDSHAKE flag set in smRes.contManagement\n");
2148 #endif /* DEBUG_CONT */
2150 if((smRes.contManagement & SM_CM_SYSTEM) &&
2151 ((GetMemoryUtilization() != MEM_NOT_AVAILABLE) &&
2152 (clientsDone == False)))
2154 while((GetMemoryUtilization() == MEM_NOT_FULL) &&
2155 (clientsDone == False))
2159 CreateExecString((char *) lineP);
2160 if(smExecArray[0] != NULL)
2162 (void) StartClient(smExecArray[0], (char **)smExecArray, NULL,
2163 NULL, NULL, False, False, -1);
2168 * When all the clients have been exec'd for this screen
2171 if(numClientsExec >= numCmd[i])
2173 ResetScreenInfo(cmdBuf, &i, actCmdSize, &clientsDone,
2174 envVal, displayName);
2181 * After we've checked memory utilization - finish up
2182 * by handshaking with the worksapce manager - if it's there
2184 if(clientsDone == False)
2186 if((smGD.dtwmRunning) && (smRes.contManagement & SM_CM_HANDSHAKE))
2189 * Get the window id of the workspace manager and tell it
2190 * to start messaging
2192 _DtGetMwmWindow(smGD.display, RootWindow(smGD.display, 0),
2194 smToWmMessage.type = ClientMessage;
2195 smToWmMessage.window = dtwmWin;
2196 smToWmMessage.message_type = XaSmWmProtocol;
2197 smToWmMessage.format = 32;
2198 smToWmMessage.data.l[0] = XaSmStartAckWindow;
2199 smToWmMessage.data.l[1] = CurrentTime;
2200 if (XSendEvent(smGD.display, dtwmWin,False,NoEventMask,
2201 (XEvent *) &smToWmMessage) != 0)
2204 XSync(smGD.display, 0);
2210 * Start a client - and wait for the workspace manager to
2211 * map a window to start a new client
2213 while(clientsDone == False)
2217 CreateExecString((char *) lineP);
2218 if(smExecArray[0] != NULL)
2220 (void) StartClient(smExecArray[0], smExecArray,
2221 NULL, NULL, NULL, False, False, -1);
2225 * If we're handshaking with the workspace manager
2226 * wait for the client to be mapped before starting
2229 if(wmHandshake == True)
2237 * When all the clients have been exec'd for this screen
2240 if(numClientsExec >= numCmd[i])
2242 ResetScreenInfo(cmdBuf, &i, actCmdSize, &clientsDone,
2243 envVal, displayName);
2248 if(wmHandshake == True)
2251 * If we are handshaking - tell the workspace manager to
2254 smToWmMessage.type = ClientMessage;
2255 smToWmMessage.window = dtwmWin;
2256 smToWmMessage.message_type = XaSmWmProtocol;
2257 smToWmMessage.format = 32;
2258 smToWmMessage.data.l[0] = XaSmStopAckWindow;
2259 smToWmMessage.data.l[0] = CurrentTime;
2260 XSendEvent(smGD.display, dtwmWin,False,NoEventMask,
2261 (XEvent *) &smToWmMessage);
2266 for(i = 0;i < smGD.numSavedScreens;i++)
2268 if(numRemoteDone == MAX_REMOTE_CLIENTS)
2274 * Send out all the remote execution commands for the screen to
2275 * the command invoker. On failure - do a remsh instead
2277 if(actRemoteSize[i] > 0)
2280 * Initialize the command invoker - if not done
2282 if(cmdInvInit == False)
2284 _DtInitializeCommandInvoker(smGD.display,
2292 * Set up the display environment variable so that the
2293 * application comes back to the right screen
2295 sprintf(envVal,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, i);
2299 parseP = remoteBuf[i];
2300 while(numRemoteExecs > 0 && GetNextLine() != NULL)
2303 * Get the host and the command and send them off
2304 * On failure of the command invoker do a remsh
2307 string = GetSmartString(&lineP);
2309 string = GetSmartString(&lineP);
2312 remoteBufPtr[numRemoteDone].cmdPtr = cmdPtr;
2313 remoteBufPtr[numRemoteDone].hostPtr = hostPtr;
2315 _DtCommandInvokerExecute(DtSTART_SESSION, NULL, NULL, NULL,
2316 "-", (char *) hostPtr, (char *) cmdPtr,
2317 RemoteRequestSucceeded, NULL,
2318 RemoteRequestFailed,
2319 &remoteBufPtr[numRemoteDone]);
2323 * If there is no more room in the remote client
2324 * array - quit exec'ing remote clients
2326 if(numRemoteDone == MAX_REMOTE_CLIENTS)
2328 PrintError(DtError, GETMESSAGE(16, 5, "You have reached the maximum allowed number of remote clients. No further remote clients will be restored."));
2338 * Now return the display variable back to the display that was
2339 * originally opened (the default display)
2347 FixEnvironmentData();
2352 } /* END OF FUNCTION RestoreClients */
2356 /*************************************<->*************************************
2358 * StartEtc ( exiting )
2363 * Call the StartClient routine to fork and exec either the sessionetc file
2364 * (if exiting==False) or the sessionexit file (if exiting==True).
2376 *************************************<->***********************************/
2378 StartEtc( Boolean exiting )
2385 execArray[0] = smGD.exitPath;
2386 execArray[1] = smExitFile;
2388 execArray[0] = smGD.etcPath;
2389 execArray[1] = smEtcFile;
2391 execArray[2] = '\0';
2393 if ((status=stat(execArray[0], &buf)) != -1)
2395 StartClient(execArray[0], execArray, NULL, NULL, NULL, False, False, -1);
2400 /*************************************<->*************************************
2407 * Returns the next line from an fopened configuration file or a newline-
2408 * embedded configuration string.
2413 * cfileP = (global) file pointer to fopened configuration file or NULL
2414 * line = (global) line buffer
2415 * linec = (global) line count
2416 * parseP = (global) parse string pointer if cfileP == NULL
2421 * line = (global) next line
2422 * linec = (global) line count incremented
2423 * parseP = (global) parse string pointer incremented
2424 * Return = line or NULL if file or string is exhausted.
2429 * If there are more than MAXLINE characters on a line in the file cfileP the
2430 * excess are truncated.
2431 * Assumes the line buffer is long enough for any parse string line.
2432 * Code stolen from dtmwm
2434 *************************************<->***********************************/
2435 static unsigned char *
2438 unsigned char *string;
2444 /* read fopened file */
2446 string = (unsigned char *) fgets((char *)line, fileSize, cfileP);
2448 else if ((parseP != NULL) && (*parseP != 0))
2449 /* read parse string */
2453 while ((*parseP != 0) &&
2454 ((chlen = mblen ((char *) parseP, MB_CUR_MAX)) > 0) &&
2456 /* copy all but NULL and newlines to line buffer */
2460 *(string++) = *(parseP++);
2464 while ((*parseP != NULL) && (*parseP != '\n'))
2465 /* copy all but NULL and newlines to line buffer */
2467 *(string++) = *(parseP++);
2471 if (*parseP == '\n')
2484 } /* END OF FUNCTION GetNextLine */
2488 /*************************************<->*************************************
2490 * PeekAhead (currentChar, currentLev)
2495 * Returns a new level value if this is a new nesting level of quoted string
2496 * Otherwise it returns a zero
2501 * currentChar = current position in the string
2502 * currentLev = current level of nesting
2507 * Returns either a new level of nesting or zero if the character is copied in
2513 *************************************<->***********************************/
2516 unsigned char *currentChar,
2517 unsigned int currentLev )
2519 Boolean done = False;
2520 unsigned int tmpLev = 1;
2524 while (((chlen = mblen ((char *) currentChar, MB_CUR_MAX)) > 0) &&
2525 (chlen == 1) && ((*currentChar == '"') || (*currentChar == '\\'))
2530 if(((chlen = mblen ((char *) currentChar, MB_CUR_MAX)) > 0) && (chlen == 1) &&
2531 ((*currentChar == '"') || (*currentChar == '\\')))
2534 if(*currentChar == '"')
2545 while((*currentChar != NULL) && (done == False) &&
2546 ((*currentChar == '"') || (*currentChar == '\\')))
2549 if((*currentChar != NULL) &&
2550 ((*currentChar == '"') || (*currentChar == '\\')))
2553 if(*currentChar == '"')
2563 #endif /*MULTIBYTE*/
2566 * Figure out if this is truly a new level of nesting - else ignore it
2567 * This section probably could do some error checking and return -1
2568 * If so, change type of routine from unsigned int to int
2582 /*************************************<->*************************************
2584 * GetSmartString (linePP)
2589 * Returns the next quoted or whitespace-terminated nonquoted string in the
2591 * Additional functionality added to GetString in that anything in a
2592 * quoted string is considered sacred and nothing will be stripped from
2593 * the middle of a quoted string.
2598 * linePP = pointer to current line buffer pointer.
2603 * linePP = pointer to revised line buffer pointer.
2609 * May alter the line buffer contents.
2610 * Handles quoted strings and characters, removing trailing whitespace from
2612 * Returns NULL string if the line is empty or is a comment.
2613 * Code stolen from dtmwm.
2615 *************************************<->***********************************/
2617 static unsigned char *
2619 unsigned char **linePP )
2621 unsigned char *lineP = *linePP;
2622 unsigned char *endP;
2623 unsigned char *curP;
2624 unsigned char *lnwsP;
2625 unsigned int level = 0, checkLev, i, quoteLevel[MAX_QUOTE_DEPTH];
2629 /* get rid of leading white space */
2630 ScanWhitespace (&lineP);
2633 * Return NULL if line is empty, whitespace, or begins with a comment.
2635 if((chlen = mblen ((char *) lineP, MB_CUR_MAX)) < 1)
2641 if ((chlen == 1) && (*lineP == '"'))
2644 quoteLevel[level] = 1;
2646 * Start beyond double quote and find the end of the quoted string.
2647 * '\' quotes the next character - but is not stripped out.
2648 * Otherwise, matching double quote or NULL terminates the string.
2650 * We use lnwsP to point to the last non-whitespace character in the
2651 * quoted string. When we have found the end of the quoted string,
2652 * increment lnwsP and if lnwsP < endP, write NULL into *lnwsP.
2653 * This removes any trailing whitespace without overwriting the
2654 * matching quote, needed later. If the quoted string was all
2655 * whitespace, then this will write a NULL at the beginning of the
2656 * string that will be returned -- OK.
2658 lnwsP = lineP++; /* lnwsP points to first '"' */
2659 curP = endP = lineP; /* other pointers point beyond */
2661 while ((*endP = *curP) &&
2662 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0) &&
2663 ((chlen > 1) || (*curP != '"')))
2664 /* Haven't found matching quote yet.
2665 * First byte of next character has been copied to endP.
2669 if ((chlen == 1) && (*endP == '\\') &&
2670 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0))
2673 * Check to see if this is a quoted quote - if it is
2674 * strip off a level - if not - it's sacred leave it alone
2676 checkLev = PeekAhead((curP - 1), quoteLevel[level]);
2679 if(quoteLevel[level] >= checkLev)
2681 if (level > 0) level--;
2683 else if (level < MAX_QUOTE_DEPTH)
2686 quoteLevel[level] = checkLev;
2689 for(i = 0;i < (checkLev - 2);i++)
2691 *endP++ = *curP++;curP++;
2698 /* Singlebyte character: character copy finished. */
2700 if (isspace (*endP))
2701 /* whitespace character: leave lnwsP unchanged. */
2706 /* non-whitespace character: point lnwsP to it. */
2712 /* Multibyte (nonwhitespace) character: point lnwsP to it.
2713 * Finish character byte copy.
2726 /* get rid of leading white space */
2727 ScanWhitespace (&lineP);
2729 /* Return NULL if line is empty, or whitespace */
2739 quoteLevel[level] = 1;
2741 * Start beyond double quote and find the end of the quoted string.
2742 * '\' quotes the next character.
2743 * Otherwise, matching double quote or NULL terminates the string.
2745 * We use lnwsP to point to the last non-whitespace character in the
2746 * quoted string. When we have found the end of the quoted string,
2747 * increment lnwsP and if lnwsP < endP, write NULL into *lnwsP.
2748 * This removes any trailing whitespace without overwriting the
2749 * matching quote, needed later. If the quoted string was all
2750 * whitespace, then this will write a NULL at the beginning of the
2751 * string that will be returned -- OK.
2753 lnwsP = lineP++; /* lnwsP points to first '"' */
2754 curP = endP = lineP; /* other pointers point beyond */
2756 while ((*endP = *curP) && (*endP != '"'))
2757 /* haven't found matching quote yet */
2759 /* point curP to next character */
2761 if ((*endP == '\\') && (*curP != NULL))
2762 /* shift quoted nonNULL character down and curP ahead */
2765 * Check to see if this is a quoted quote - if it is
2766 * strip off a level - if not - it's sacred leave it alone
2768 checkLev = PeekAhead((curP - 1), quoteLevel[level]);
2771 if(quoteLevel[level] >= checkLev)
2773 if (level > 0) level--;
2775 else if (level < MAX_QUOTE_DEPTH)
2778 quoteLevel[level] = checkLev;
2781 for(i = 0;i < (checkLev - 2);i++)
2783 *endP++ = *curP++;curP++;
2789 if (isspace (*endP))
2790 /* whitespace character: leave lnwsP unchanged. */
2795 /* non-whitespace character: point lnwsP to it. */
2803 * Found matching quote or NULL.
2804 * NULL out any trailing whitespace.
2815 /* Unquoted string */
2818 * Find the end of the nonquoted string.
2819 * '\' quotes the next character.
2820 * Otherwise, whitespace, NULL, terminates the string.
2822 curP = endP = lineP;
2825 while ((*endP = *curP) &&
2826 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0) &&
2827 ((chlen > 1) || (!isspace (*curP))))
2828 /* Haven't found whitespace yet.
2829 * First byte of next character has been copied to endP.
2833 if ((chlen == 1) && (*endP == '\\') &&
2834 ((chlen = mblen ((char *) curP, MB_CUR_MAX)) > 0))
2836 * copy first byte of quoted nonNULL character down.
2837 * point curP to next byte
2844 /* Multibyte character: finish character copy. */
2853 while ((*endP = *curP) && !isspace (*endP))
2855 /* point curP to next character */
2857 if ((*endP == '\\') && (*curP != NULL))
2858 /* shift quoted nonNULL character down and curP ahead */
2868 * Two cases for *endP:
2870 * matching quote -> write NULL over char and point beyond
2871 * NULL -> point to NULL
2876 *endP = 0; /* write NULL over terminator */
2877 *linePP = ++curP; /* point beyond terminator */
2883 return ((unsigned char *)lineP);
2885 } /* END OF FUNCTION GetString */
2890 /*************************************<->*************************************
2892 * ScanWhitespace(linePP)
2897 * Scan the string, skipping over all white space characters.
2902 * linePP = nonNULL pointer to current line buffer pointer
2907 * linePP = nonNULL pointer to revised line buffer pointer
2912 * Assumes linePP is nonNULL
2913 * Code Stolen from dtmwm
2915 *************************************<->***********************************/
2918 unsigned char **linePP )
2921 while (*linePP && (mblen ((char *) *linePP, MB_CUR_MAX) == 1) && isspace (**linePP))
2923 while (*linePP && isspace (**linePP))
2929 } /* END OF FUNCTION ScanWhitespace */
2933 /*************************************<->*************************************
2935 * FillHintBuf(newHint, hintBuf, maxSize, actSize, screen, numHints)
2940 * Put the new hint into the hint buffer. Each hint is separated by a
2946 * newHint = hint to add to the buffer
2947 * hintBuf = an array of buffers - one for each screen
2948 * maxSize = array of buffers of the current malloced size of each hintBuf
2949 * actSize = array of space currently used by each hintBuf
2950 * screen = screen number for this hint
2951 * numHints = array of the number of hints for each screen
2952 * smGD.numSavedScreens = (global) checked to make sure this hint should be
2957 * hintBuf[screen] = updated hint buf for this screen (newHint added)
2958 * maxSize[screen] = enlarged if not big enough or malloced if not done before
2959 * actSize[screen] = updated size of the hints buffer
2960 * numHints[screen] = updated by 1 if this hint is added
2966 *************************************<->***********************************/
2969 unsigned char *newHint,
2970 unsigned char **hintBuf,
2971 unsigned int *maxSize,
2972 unsigned int *actSize,
2973 unsigned int screen,
2974 unsigned int *numHints)
2976 static int hintBufSize = 5000;
2979 * If the screen that this hint was meant for is not in the current
2980 * set of available screens, don't save it
2982 if(screen >= smGD.numSavedScreens)
2988 * Check to see if this buffer has been malloc'd before - if it hasn't
2989 * malloc it. If it has - check to make sure it's big enough to hold the
2992 if(maxSize[screen] == 0)
2994 hintBuf[screen] = (unsigned char *) SM_MALLOC(hintBufSize * sizeof(char));
2995 if(hintBuf[screen] == NULL)
2997 actSize[screen] = 0;
2998 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3001 maxSize[screen] = hintBufSize * sizeof(char);
3004 * Now reserve 4 bytes for the length
3006 strcpy((char *)hintBuf[screen], " \n");
3010 if((actSize[screen] + strlen((char *)newHint) + 2) >= maxSize[screen])
3012 hintBuf[screen] = (unsigned char *)
3013 SM_REALLOC((char *) hintBuf[screen],
3017 if(hintBuf[screen] == NULL)
3019 actSize[screen] = 0;
3020 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3023 maxSize[screen] = maxSize[screen] + (hintBufSize * sizeof(char));
3028 * add the new hint AFTER the last newline
3030 strcat((char *)hintBuf[screen], (char *)newHint);
3031 strcat((char *)hintBuf[screen], "\n");
3032 actSize[screen] = strlen((char *)hintBuf[screen]);
3033 numHints[screen] += 1;
3040 /*************************************<->*************************************
3042 * FillCmdBuf(newCmd, cmdBuf, maxSize, actSize, screen)
3047 * Put a new command into the command buffer. The command buffer is just
3048 * one big long string of stuff to be executed.
3053 * newCmd = command to add to the buffer
3054 * cmdBuf = an array of buffers - one for each screen
3055 * maxSize = array of buffers of the current malloced size of each cmdBuf
3056 * actSize = array of space currently used by each cmdBuf
3057 * screen = screen number for this command
3058 * smGD.numSavedScreens = (global) checked to make sure this hint should be
3063 * cmdBuf[screen] = updated command buf for this screen (newCmd added)
3064 * maxSize[screen] = enlarged if not big enough or malloced if not done before
3065 * actSize[screen] = updated size of the command buffer
3071 *************************************<->***********************************/
3074 unsigned char *newCmd,
3075 unsigned char **cmdBuf,
3076 unsigned int *maxSize,
3077 unsigned int *actSize,
3078 unsigned int screen,
3079 unsigned int *numCmd )
3081 static int cmdBufSize = 5000;
3084 * If the screen that this command was meant for is not in the current
3085 * set of available screens, don't save it
3087 if(screen >= smGD.numSavedScreens)
3093 * Check to see if this buffer has been malloc'd before - if it hasn't
3094 * malloc it. If it has - check to make sure it's big enough to hold the
3097 if(maxSize[screen] == 0)
3099 cmdBuf[screen] = (unsigned char *) SM_MALLOC(cmdBufSize * sizeof(char));
3100 if(cmdBuf[screen] == NULL)
3102 actSize[screen] = 0;
3103 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3106 maxSize[screen] = cmdBufSize * sizeof(char);
3110 if((actSize[screen] + strlen((char *)newCmd)) >= maxSize[screen])
3112 cmdBuf[screen] = (unsigned char *) SM_REALLOC((char *)cmdBuf[screen],
3116 if(cmdBuf[screen] == NULL)
3118 actSize[screen] = 0;
3119 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3122 maxSize[screen] = maxSize[screen] + (cmdBufSize * sizeof(char));
3126 if(actSize[screen] == 0)
3128 strcpy((char *)cmdBuf[screen], (char *)newCmd);
3132 strcat((char *)cmdBuf[screen], (char *)newCmd);
3135 *numCmd = *numCmd + 1;
3136 strcat((char *)cmdBuf[screen], "\n");
3137 actSize[screen] = strlen((char *)cmdBuf[screen]);
3144 /*************************************<->*************************************
3146 * FillRemoteBuf(newCmd, hostName, displayName, remoteBuf,
3147 * maxSize, actSize, screen)
3152 * Put a new command into the remote execution buffer. The command buffer is
3153 * just one big long string of stuff to be executed.
3158 * newCmd = command to add to the buffer
3159 * hostName = host where command is to be executed from
3160 * displayName = display where host is to be executed to
3161 * remoteBuf = an array of buffers - one for each screen
3162 * maxSize = array of buffers of the current malloced size of each cmdBuf
3163 * actSize = array of space currently used by each cmdBuf
3164 * screen = screen number for this command
3165 * smGD.numSavedScreens = (global) checked to make sure this hint should be
3170 * cmdBuf[screen] = updated command buf for this screen (newCmd added)
3171 * in remote format (host name and display name)
3172 * maxSize[screen] = enlarged if not big enough or malloced if not done before
3173 * actSize[screen] = updated size of the command buffer
3179 *************************************<->***********************************/
3182 unsigned char *newCmd,
3183 unsigned char *hostName,
3184 unsigned char *displayName,
3185 unsigned char *remoteBuf[] ,
3186 unsigned int *maxSize ,
3187 unsigned int *actSize ,
3188 unsigned int screen )
3190 unsigned char *string;
3191 static int remoteBufSize = 5000;
3194 * If the screen that this command was meant for is not in the current
3195 * set of available screens, don't save it
3197 if(screen >= smGD.numSavedScreens)
3203 * Check to see if this buffer has been malloc'd before - if it hasn't
3204 * malloc it. If it has - check to make sure it's big enough to hold the
3207 if(maxSize[screen] == 0)
3209 remoteBuf[screen] = (unsigned char *)
3210 SM_MALLOC(remoteBufSize * sizeof(char));
3211 if(remoteBuf[screen] == NULL)
3213 actSize[screen] = 0;
3214 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3217 maxSize[screen] = remoteBufSize * sizeof(char);
3221 if((actSize[screen] + strlen((char *)newCmd) +
3222 strlen((char *)hostName) +
3223 strlen((char *)displayName) +
3224 strlen("-display ") + 5) >= maxSize[screen])
3226 remoteBuf[screen] = (unsigned char *)
3227 SM_REALLOC((char *)remoteBuf[screen],
3229 (remoteBufSize * sizeof(char)));
3230 if(remoteBuf[screen] == NULL)
3232 actSize[screen] = 0;
3233 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
3236 maxSize[screen] = maxSize[screen] + (remoteBufSize * sizeof(char));
3240 if(actSize[screen] == 0)
3243 * If the buffer is empty fill it with the initial contents
3245 strcpy((char *)remoteBuf[screen], (char *)hostName);
3246 strcat((char *)remoteBuf[screen], " ");
3251 * if this buffer is not emtpy
3252 * add the new command BEFORE the last null terminator
3253 * Commands for remote executions are separated by newlines
3255 strcat((char *)remoteBuf[screen], "\n");
3256 strcat((char *)remoteBuf[screen], (char *)hostName);
3260 * Copy the command in - quote it
3262 strcat((char *)remoteBuf[screen], " \"");
3263 string = GetSmartString(&newCmd);
3264 strcat((char *)remoteBuf[screen], (char *)string);
3265 strcat((char *)remoteBuf[screen], " ");
3268 * Once display name has been put in place - concatenate the
3269 * rest of the command
3271 while((string = GetSmartString(&newCmd)) != NULL )
3273 strcat((char *)remoteBuf[screen], " ");
3274 strcat((char *)remoteBuf[screen], (char *)string);
3278 * Now close off the command with a quote
3280 strcat((char *)remoteBuf[screen], "\"");
3282 actSize[screen] = strlen((char *)remoteBuf[screen]);
3285 * Bump the remote command counter
3293 /*************************************<->*************************************
3295 * CreateExecString(execString)
3300 * Create a string that can be fed to a fork and exec by breaking it up
3301 * into argc and argv
3306 * execString = whole command
3310 * smExecArray = global modified to contain pointers to argc and argv
3316 *************************************<->***********************************/
3324 static int iSizeArgv = ARG_AMT;
3329 if (smExecArray == NULL)
3331 smExecArray = (char **) XtMalloc (ARG_AMT * sizeof(char *));
3333 string = (char *) GetSmartString((unsigned char **) &execString);
3334 while(string != NULL)
3336 smExecArray[argc] = string;
3338 if (argc >= iSizeArgv)
3340 iSizeArgv += ARG_AMT;
3341 smExecArray = (char **)
3342 XtRealloc ((char *)smExecArray, (iSizeArgv * sizeof(char *)));
3344 string = (char *) GetSmartString((unsigned char **) &execString);
3348 * If the last string is a background character
3353 if(!strcmp((char *)smExecArray[argc - 1], "&"))
3355 smExecArray[argc - 1] = '\0';
3359 smExecArray[argc] = '\0';
3361 } /* END OF FUNCTION CreateExecString */
3365 * SetTemporaryDisplay - does a putenv of the current value of the
3366 * DISPLAY environment variable but with the given screen number.
3372 SetTemporaryDisplay (
3375 static char * tmpDisplay = NULL;
3376 static int lastScreen = -1;
3379 if (screenNum == -1)
3382 if (!savedDisplay) {
3385 if ((dispEnv = getenv (DISPLAY_NAME)) == NULL)
3387 savedDisplay = XtMalloc (strlen (DISPLAY_NAME_EQUAL) +
3388 strlen (dispEnv) + 2);
3391 sprintf (savedDisplay, "%s%s", DISPLAY_NAME_EQUAL, dispEnv);
3394 if (lastScreen == screenNum && tmpDisplay != NULL) {
3395 putenv (tmpDisplay);
3398 lastScreen = screenNum;
3403 tmpDisplay = XtMalloc (strlen (savedDisplay) + 4);
3406 strcpy (tmpDisplay, savedDisplay);
3409 if (pch = strrchr (tmpDisplay, ':')) {
3412 if (pch2 = strchr (pch, '.'))
3414 pch3 = XtMalloc (strlen (tmpDisplay) + 4);
3417 sprintf (pch3, "%s.%d", tmpDisplay, screenNum);
3418 strcpy (tmpDisplay, pch3);
3419 XtFree ((char *) pch3);
3421 putenv (tmpDisplay);
3427 * RestoreDisplay - does a putenv of the global variable savedDisplay
3433 if (screenNum != -1 && savedDisplay)
3434 putenv (savedDisplay);
3438 /*************************************<->*************************************
3440 * StartClient - calls StartLocalClient or StartRemoteClient depending
3441 * on the value of hostName.
3445 * Starts a local or remote application
3449 * program = execArray[0]
3450 * execArray = command to fork and exec
3451 * hostName = the name of the host where program should be executed
3452 * cwd = directory to chdir to before doing the exec
3453 * envp = the envrironment variables to add to the child processes env
3454 * checkCwd = if True and cwd is NULL, a message will be logged; if
3455 * False, cwd will not be checked and the cwd will be set to $HOME
3456 * useIgnoreEnvironmentResource = if True, the variables listed in the
3457 * IgnoreEnvironment resource will be removed from 'environ' before
3458 * execArray is exec'd
3459 * screen = if set to -1, it will be ignored; otherwise, the screen
3460 * number will be used to define DISPLAY for the duration of this
3461 * function - DISPLAY will be reset before the function returns.
3465 * Returns True if the command is successfully executed; False otherwise.
3469 * localHost - is modified
3471 *************************************<->***********************************/
3480 Boolean useIgnoreEnvironmentResource,
3483 static char * defaultCwd = NULL;
3484 Boolean cwdNull = False;
3485 Boolean startStatus;
3487 SetTemporaryDisplay (screen);
3489 if (!ignoreEnvPtr && useIgnoreEnvironmentResource) {
3490 if (smRes.ignoreEnvironment)
3491 ignoreEnvPtr = _DtVectorizeInPlace (
3492 smRes.ignoreEnvironment, ',');
3496 if (getenv ("HOME"))
3497 defaultCwd = strdup (getenv ("HOME"));
3499 defaultCwd = getcwd (NULL, MAXPATHLEN + 1);
3501 (void) gethostname (localHost, MAXHOSTNAMELEN);
3509 if (!hostName || (_DtIsSameHost (localHost, hostName)))
3510 startStatus = StartLocalClient (program, execArray,
3511 cwd, envp, checkCwd,
3512 useIgnoreEnvironmentResource);
3514 startStatus = StartRemoteClient (program, execArray, hostName,
3516 useIgnoreEnvironmentResource);
3518 RestoreDisplay (screen);
3520 return (startStatus);
3523 /*************************************<->*************************************
3529 * Starts a local application.
3532 * Returns True if the command is successfully executed; False otherwise.
3534 *************************************<->***********************************/
3542 Boolean useIgnoreEnvironmentResource)
3546 char clientMessage[MAXPATHLEN + 30];
3547 char **tmpEnv, **ppchar;
3550 * Fork and exec the client process
3552 clientFork = vfork();
3555 * If the fork fails - Send out an error and return
3559 PrintErrnoError(DtError, smNLS.cantForkClientString);
3564 * Fork succeeded - now do the exec
3568 SetSIGPIPEToDefault ();
3571 * Log a warning if the given cwd is not valid
3575 if ((chdir (cwd)) == -1)
3579 tmpCwd = getcwd (NULL, MAXPATHLEN + 1);
3581 LogCWDMessage (cwd, program, tmpCwd);
3586 * Add envp to the client's environ if the variable
3587 * is not in the ignoreEnvironment list
3589 if (useIgnoreEnvironmentResource && envp) {
3592 tmpEnv = RemoveEnvironmentVars (envp);
3596 for (ppchar = tmpEnv; ppchar && *ppchar; ppchar++)
3597 putenv (strdup (*ppchar));
3602 * Set the gid of the process back from bin
3605 setregid(smGD.runningGID, smGD.runningGID);
3607 setgid(smGD.runningGID);
3608 setegid(smGD.runningGID);
3612 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
3614 #if defined(__osf__) || defined(CSRG_BASED)
3618 #endif /* __osf__ */
3620 MarkFileDescriptors (3, F_SETFD, 1);
3622 execStatus = execvp(program, execArray);
3625 sprintf(clientMessage, ((char *)GETMESSAGE(16, 3, "Unable to exec %s.")), execArray[0]);
3626 PrintErrnoError(DtError, clientMessage);
3634 /*************************************<->*************************************
3640 * Starts a remote application.
3643 * Returns True if the command is successfully executed; False otherwise.
3645 *************************************<->***********************************/
3653 Boolean useIgnoreEnvironmentResource)
3656 SPC_Channel_Ptr channel;
3658 char errorMessage[1024];
3660 static Boolean cmdInvokerInitialized = False;
3661 char ** tmpEnv = envp;
3663 ioMode = SPCIO_NOIO | SPCIO_FORCE_CONTEXT;
3665 if (!cmdInvokerInitialized) {
3666 _DtInitializeCommandInvoker(smGD.display,
3670 cmdInvokerInitialized = True;
3673 (void) strcpy (errorMessage, "");
3675 channel = (SPC_Channel_Ptr) _DtSPCOpen (hostName, ioMode, errorMessage);
3676 if (channel == SPC_ERROR) {
3677 message = strdup ((char *) GETMESSAGE (40, 13,
3678 "The following application cannot be started on host '%s'\nbecause this host cannot be reached from host '%s':\n\n %s"));
3681 DtMsgLogMessage (smGD.programName, DtMsgLogError,
3682 message, hostName, localHost, program);
3688 netfile = tt_host_file_netfile (hostName, cwd);
3689 if (tt_pointer_error (netfile) != TT_OK) {
3691 message = strdup ((char *) GETMESSAGE (40, 14,
3692 "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]"));
3695 DtMsgLogMessage (smGD.programName, DtMsgLogError,
3696 message, program, hostName, cwd,
3697 tt_status_message (tt_pointer_error (
3705 * Add envp to the client's environ if the variable
3706 * is not in the ignoreEnvironment list
3708 if (useIgnoreEnvironmentResource && ignoreEnvPtr && envp)
3709 tmpEnv = RemoveEnvironmentVars (envp);
3711 if ((_DtSPCSpawn (program, netfile, execArray, tmpEnv, channel,
3712 hostName, NULL, cwd, errorMessage)) == SPC_ERROR) {
3713 DtMsgLogMessage (smGD.programName, DtMsgLogError, errorMessage);
3715 XtFree ((char *) tmpEnv);
3721 XtFree ((char *) tmpEnv);
3727 /*************************************<->*************************************
3734 * Fork and exec the default window manager
3747 *************************************<->***********************************/
3756 * These lines were added to support the builtin
3761 char *displayName,*dpy;
3763 hostName = SM_MALLOC(MAXPATHSM);
3764 displayName = SM_MALLOC(MAXPATHSM);
3766 if( gethostname(hostName, (sizeof(hostName) - 1) ) == 0)
3768 hostName[MAXPATHSM - 1] = '\0';
3769 dpy = getenv(DISPLAY_NAME);
3770 homeDir = getenv("HOME");
3773 strcpy(displayName, dpy);
3774 dpy = strchr(displayName, ':');
3779 sprintf(tmpExecWmFile, "%s/.dt/bin/%s/%s/dtwm", homeDir,
3780 hostName,displayName);
3781 if (access(tmpExecWmFile,X_OK) != 0)
3783 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3787 localWmLaunched = True;
3788 if (!smGD.userSetWaitWmTimeout)
3790 smRes.waitWmTimeout = 60000;
3796 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3801 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3805 SM_FREE(displayName);
3807 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
3808 * End of lines were added to support the builtin
3812 strcpy(tmpExecWmFile,CDE_INSTALLATION_TOP "/bin/dtwm");
3817 * Fork and exec the client process
3819 clientFork = vfork();
3822 * If the fork fails - Send out an error and return
3826 PrintErrnoError(DtError, smNLS.cantForkClientString);
3831 * Fork succeeded - now do the exec
3835 SetSIGPIPEToDefault ();
3839 * Set the gid of the process back from bin
3842 setregid(smGD.runningGID, smGD.runningGID);
3844 setgid(smGD.runningGID);
3845 setegid(smGD.runningGID);
3848 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
3850 #if defined(__osf__) || defined(CSRG_BASED)
3854 #endif /* __osf__ */
3856 MarkFileDescriptors (3, F_SETFD, 1);
3859 * These lines were added to support the builtin
3862 * execStatus = execlp(".../dt/bin/dtwm", "dtwm", (char *) 0);
3865 execStatus = execlp(tmpExecWmFile, "dtwm", (char *) 0);
3868 * ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^ ^^^^^
3869 * End of lines were added to support the builtin
3873 if(execStatus != 0 && (!localWmLaunched))
3875 PrintErrnoError(DtError, GETMESSAGE(16, 4, "Unable to exec process /usr/dt/bin/dtwm. No window manager will be started."));
3882 /*************************************<->*************************************
3889 * Fork a copy of ourselves and kill the parent off so that scripts starting
3890 * up the session manager can continue.
3902 *************************************<->***********************************/
3910 * Fork and exec the client process
3912 clientFork = fork();
3915 * If the fork fails - We have to exit so that the rest of the
3916 * script can continue
3920 PrintErrnoError(DtError, smNLS.cantForkClientString);
3925 * Fork succeeded - now kill the parent
3933 * Disassociate from parent
3935 #if defined(__osf__) || defined(CSRG_BASED)
3939 #endif /* __osf__ */
3944 /*************************************<->*************************************
3951 * This routine waits for the window manager to start. It uses a
3952 * resource (waitWmTimeout) with a dynamic default to determine how many
3953 * seconds to wait for WM start and then starts clients.
3958 * appContext = application context for the window
3959 * window = window id for the
3968 *************************************<->***********************************/
3973 XtIntervalId wmTimerId;
3975 XtAddEventHandler(smGD.topLevelWid,
3978 (XtEventHandler)HandleWMClientMessage,
3982 * Set a timer which stops the block on waiting for the
3983 * window manager to start
3986 wmTimerId = XtAppAddTimeOut(smGD.appCon,
3987 smRes.waitWmTimeout,
3988 WaitWMTimeout, NULL);
3990 while((smGD.dtwmRunning == False) && (wmTimeout == False))
3992 XtAppProcessEvent(smGD.appCon, XtIMAll);
3995 XtRemoveTimeOut(wmTimerId);
3996 XtRemoveEventHandler(smGD.topLevelWid,
3999 (XtEventHandler)HandleWMClientMessage,
4003 } /* END OF FUNCTION WaitForWM */
4006 /*************************************<->*************************************
4013 * Timeout procedure the WaitForCommand routine. It stops a loop waiting
4014 * for the window manager to get started.
4023 * wmTimeout = (global) flag that stops the loop
4028 *************************************<->***********************************/
4031 XtPointer client_data,
4036 } /* END OF FUNCTION WaitWMTimeout */
4040 /*************************************<->*************************************
4042 * HandleWMClientMessage
4047 * This is the event handler registered to recieve the client message
4048 * from dtwm when dtwm is ready for business
4051 *************************************<->***********************************/
4053 HandleWMClientMessage( Widget smWidget,
4057 if (event->type == ClientMessage)
4059 ProcessClientMessage(event);
4062 } /* END OF FUNCTION HandleWMClientMessage */
4067 /*************************************<->*************************************
4069 * FixEnvironmentData
4074 * If DISPLAY variable exists in the environment - remove it
4083 * wmTimeout = (global) flag that stops the loop
4088 *************************************<->***********************************/
4090 FixEnvironmentData( void )
4094 extern char **environ; /* MODIFIED - DISPLAY is remove if found. */
4096 for (i=0, ppchar = environ; *ppchar; ppchar++, i++)
4098 if ((strncmp (*ppchar, DISPLAY_NAME_EQUAL, strlen(DISPLAY_NAME_EQUAL))) == 0)
4101 * Change the DISPLAY environment variable.
4103 for (; *ppchar; ppchar++, i++)
4105 environ[i]=environ[i+1];
4114 /*************************************<->*************************************
4121 * After one screen is finished - set up the info for the next
4126 * cmdBuf - Buffer that holds all the invocation information
4127 * screen - Pointer to the screen number that we're currently working on
4128 * env - used to set up the environment for changing the display var
4129 * displayName - name of the current display
4133 * cmdBuf - old buffers are freed
4134 * screen - updated to point to the new screen info
4135 * done - tells whether the clients are done being exec'd
4136 * linec - *GLOBAL* sets line being read from
4142 *************************************<->***********************************/
4144 ResetScreenInfo(unsigned char **cmdBuf,
4146 unsigned int *cmdSize,
4151 SM_FREE((char *) cmdBuf[*screen]);
4153 while((cmdSize[*screen] == 0) && (*screen < smGD.numSavedScreens))
4158 if(*screen >= smGD.numSavedScreens)
4164 sprintf((char *)env,"%s%s%d", DISPLAY_NAME_EQUAL, displayName, *screen);
4168 parseP = cmdBuf[*screen];
4174 /*************************************<->*************************************
4176 * RemoteRequestFailed ()
4181 * If a request to the command invoker fails, this callback will be called.
4182 * It will then try to execute the command by performing a remsh on it.
4195 *************************************<->***********************************/
4197 RemoteRequestFailed(char *message,
4200 static char *cmdBuf = NULL;
4201 static char *tmpCmdBuf = NULL;
4202 char *errorString = NULL;
4205 static int cmdBufSize = 0;
4208 RemoteReq *tmpReq = (RemoteReq *) client_data;
4211 * If the memory for the buffer has not been malloced - do so
4215 cmdBuf = SM_MALLOC((200 * sizeof(char)) + 1 );
4218 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4221 cmdBufSize = 200 + 1;
4223 tmpCmdBuf = SM_MALLOC((200 * sizeof(char)) + 1 );
4224 if(tmpCmdBuf == NULL)
4226 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4231 * Copy in the host and command field and execute the command
4234 tmpSize = (strlen(REMOTE_CMD_STRING) +
4235 strlen((char *) tmpReq->hostPtr) +
4236 strlen((char *) tmpReq->cmdPtr) + 1);
4238 if(tmpSize >= cmdBufSize)
4240 cmdBuf = SM_REALLOC(cmdBuf, (tmpSize) * sizeof(char));
4244 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4248 cmdBufSize = tmpSize;
4250 if(tmpCmdBuf != NULL)
4252 tmpCmdBuf = SM_REALLOC(tmpCmdBuf, (tmpSize) * sizeof(char));
4253 if(tmpCmdBuf == NULL)
4255 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4260 sprintf(cmdBuf, REMOTE_CMD_STRING, tmpReq->hostPtr, tmpReq->cmdPtr);
4263 * save cmdBuf for error message, cmdBuf is changed
4264 * by CreateExecString
4266 if (tmpCmdBuf != NULL)
4268 strcpy(tmpCmdBuf,cmdBuf);
4271 CreateExecString(cmdBuf);
4272 if(smExecArray[0] != NULL)
4274 (void) StartClient(smExecArray[0], smExecArray, NULL, NULL,
4275 NULL, False, False, -1);
4277 if (tmpCmdBuf != NULL)
4279 tmpString = GETMESSAGE(16, 8,
4280 "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");
4283 (char *)SM_MALLOC((strlen(tmpString) +
4284 strlen((char *)tmpReq->hostPtr) +
4285 strlen((char *)tmpReq->cmdPtr) +
4286 strlen(tmpCmdBuf) + 1 ) *
4289 if(errorString == NULL)
4291 PrintErrnoError(DtError, smNLS.cantMallocErrorString);
4295 sprintf(errorString, tmpString, tmpReq->hostPtr,
4296 tmpReq->cmdPtr, tmpCmdBuf );
4297 PrintError(DtError, errorString);
4298 SM_FREE(errorString);
4303 * Now check to make sure that this isn't the last remote request.
4304 * If so, free the data
4308 if(numRemoteExecs == 0)
4310 for(i = 0;i < smGD.numSavedScreens;i++)
4312 if(actRemoteSize[i] > 0)
4314 SM_FREE((char *) remoteBuf[i]);
4324 /*************************************<->*************************************
4326 * RemoteRequestSucceeded ()
4331 * If a request to the command invoker succeeds, this callback will be called.
4332 * It decrements the remote execution counter, and frees the info if
4333 * remote executions are finished
4346 *************************************<->***********************************/
4348 RemoteRequestSucceeded(char *message,
4355 if(numRemoteExecs == 0)
4357 for(i = 0;i < smGD.numSavedScreens;i++)
4359 if(actRemoteSize[i] > 0)
4361 SM_FREE((char *) remoteBuf[i]);
4367 /**************************************************************************
4371 **************************************************************************/
4375 char * databaseName)
4378 XSMPClientDBRecPtr pXSMPRec;
4379 ProxyClientDBRecPtr pProxyRec;
4384 if ((inputDB = OpenInputClientDB (databaseName,
4386 &smXSMP.dbSessionId)) == NULL) {
4387 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogError, 1);
4391 if (!smXSMP.dbVersion) {
4392 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogWarning, 2);
4393 smXSMP.dbVersion = SM_VENDOR_NAME;
4396 if (!smXSMP.dbSessionId) {
4397 LogXSMPOpenDatabaseFailure (databaseName, DtMsgLogWarning, 3);
4398 smXSMP.dbSessionId = SM_RELEASE_NAME;
4402 * First start the XSMP clients
4406 if ((pXSMPRec = GetXSMPClientDBRec (inputDB)) == NULL)
4409 if (!CheckRequiredProperties (pXSMPRec, databaseName)) {
4410 FreeXSMPClientDBRec (pXSMPRec);
4414 if (StartXSMPClient (pXSMPRec, databaseName)) {
4416 XSMPClientDBRecPtr tmpRecPtr;
4418 pXSMPRec->next = NULL;
4420 if (!smXSMP.xsmpDbList) {
4421 smXSMP.xsmpDbList = pXSMPRec;
4426 * Find the end of the list
4428 for (tmpRecPtr = smXSMP.xsmpDbList;
4429 tmpRecPtr && tmpRecPtr->next != NULL;
4430 tmpRecPtr = tmpRecPtr->next);
4432 tmpRecPtr->next = pXSMPRec;
4435 FreeXSMPClientDBRec (pXSMPRec);
4439 * Now start the Proxy clients
4441 for (i = 0; ; i++) {
4443 if ((pProxyRec = GetProxyClientDBRec (inputDB)) == NULL)
4446 if (!CheckRequiredFields (pProxyRec, databaseName, i)) {
4447 FreeProxyClientDBRec (pProxyRec);
4451 (void) StartProxyClient (pProxyRec);
4453 FreeProxyClientDBRec (pProxyRec);
4456 (void) CloseClientDB (inputDB, False);
4464 XSMPClientDBRecPtr pDbRec,
4465 char * databaseName)
4467 return (StartClient (pDbRec->restartCommand[0],
4468 pDbRec->restartCommand,
4471 pDbRec->environment,
4474 pDbRec->screenNum));
4480 ProxyClientDBRecPtr pDbRec)
4482 return (StartClient (pDbRec->command[0],
4489 pDbRec->screenNum));
4494 ExecuteCommandProperty (
4496 ClientRecPtr pClientRec)
4499 char ** envp = NULL;
4501 PropertyRecPtr pPropRec;
4505 if ((pPropRec = GetPropertyRec (pClientRec, commandName)) == NULL)
4508 argv = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
4513 for (i = 0; i < pPropRec->prop.num_vals; i++)
4514 argv[i] = pPropRec->prop.vals[i].value;
4515 argv[pPropRec->prop.num_vals] = NULL;
4517 cwd = GetArrayPropertyValue (pClientRec, SmCurrentDirectory);
4520 if ((pPropRec = GetPropertyRec (pClientRec, SmEnvironment)) != NULL) {
4521 envp = (char **) XtMalloc ((pPropRec->prop.num_vals + 1) *
4526 for (i = 0; i < pPropRec->prop.num_vals; i++)
4527 envp[i] = pPropRec->prop.vals[i].value;
4528 envp[pPropRec->prop.num_vals] = NULL;
4531 retValue = StartClient (argv[0], argv,
4532 pClientRec->clientHost,
4535 pClientRec->screenNum);
4537 XtFree ((char *) argv);
4539 XtFree ((char *) envp);
4545 /*************************************<->*************************************
4547 * ExecuteDiscardCommands -
4549 * Description: Executes all of the DiscardCommand properties in the
4550 * given client database
4554 *************************************<->***********************************/
4556 ExecuteDiscardCommands (
4560 XSMPClientDBRecPtr pXSMPRec;
4561 char * version = NULL;
4565 if ((inputDB = OpenInputClientDB (db, &version, &id )) == NULL) {
4566 str = strdup ((char *) GETMESSAGE (40, 26,
4567 "The following client database cannot be opened:\n\n %s\n\nThe 'DiscardCommand' properties cannot be run."));
4570 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, str, db);
4576 XtFree ((char *) version);
4578 XtFree ((char *) id);
4581 if ((pXSMPRec = GetXSMPClientDBRec (inputDB)) == NULL)
4584 if (!pXSMPRec->discardCommand)
4587 if (!StartClient (pXSMPRec->discardCommand[0],
4588 pXSMPRec->discardCommand,
4589 pXSMPRec->clientHost,
4591 pXSMPRec->environment,
4594 pXSMPRec->screenNum)) {
4595 str = strdup ((char *) GETMESSAGE (40, 27,
4596 "An attempt to execute the 'DiscardCommand' property for\napplication '%s' failed."));
4599 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, str,
4604 FreeXSMPClientDBRec (pXSMPRec);
4607 (void) CloseClientDB (inputDB, False);
4612 CheckRequiredProperties (
4613 XSMPClientDBRecPtr pDbRec,
4614 char * databaseName)
4616 Boolean propsOK = True;
4618 if (!pDbRec->program) {
4619 LogMissingPropertyMessage (pDbRec, SmProgram,
4620 databaseName, DtMsgLogError);
4624 if (!pDbRec->restartCommand) {
4625 LogMissingPropertyMessage (pDbRec, SmRestartCommand,
4626 databaseName, DtMsgLogError);
4635 CheckRequiredFields (
4636 ProxyClientDBRecPtr pDbRec,
4637 char * databaseName,
4642 if (!pDbRec->command) {
4644 message = strdup ((char *) GETMESSAGE (40, 11,
4645 "The required resource '%s' is missing for client '%d'\nin the file '%s'."));
4650 DtMsgLogMessage (smGD.programName, DtMsgLogError, message,
4651 SmProgram, clientNum, databaseName);
4663 LogXSMPOpenDatabaseFailure (
4664 char * databaseName,
4665 DtMsgLogType msgType,
4668 char * message = NULL;
4673 case 1: data = databaseName;
4675 message = strdup ((char *) GETMESSAGE (40, msgNum,
4676 "The following session database could not be opened:\n\n '%s'"));
4679 case 2: data = versionStr;
4681 message = strdup ((char *) GETMESSAGE (40, msgNum,
4682 "The following session database does not contain\nthe required resource '%s':\n\n %s"));
4685 case 3: data = dtsessionIDStr;
4687 message = strdup ((char *) GETMESSAGE (40, msgNum,
4688 "The following session database does not contain\nthe required resource '%s':\n\n %s"));
4696 DtMsgLogMessage (smGD.programName, msgType, message, data);
4698 DtMsgLogMessage (smGD.programName, msgType, message,
4699 data, databaseName);
4706 LogMissingPropertyMessage (
4707 XSMPClientDBRecPtr pDbRec,
4709 char * databaseName,
4710 DtMsgLogType msgType)
4714 message = strdup ((char *) GETMESSAGE (40, 10,
4715 "The required property '%s' is missing for client\n\n %s\n\nin the file '%s'."));
4720 DtMsgLogMessage (smGD.programName, msgType, message,
4721 propName, pDbRec->clientId, databaseName);
4735 message = strdup ((char *) GETMESSAGE (40, 12,
4736 "The directory '%s'\nis not available for application '%s'.\n\nThe following directory will be used:\n\n %s"));
4741 DtMsgLogMessage (smGD.programName, DtMsgLogWarning, message,
4742 badDir, appName, goodDir);
4749 char ** RemoveEnvironmentVars (
4753 char ** retEnv = NULL;
4754 char **ppchar, **ppchar2;
4761 for (count = 0, ppchar = envp; ppchar && *ppchar; count++, ppchar++) ;
4763 retEnv = (char **) XtMalloc ((count + 1) * sizeof (char *));
4767 if (!ignoreEnvPtr) {
4768 for (count = 0, ppchar = envp; ppchar && *ppchar;
4769 count++, ppchar++) {
4770 retEnv[count] = *ppchar;
4772 retEnv[count] = NULL;
4777 for (count = 0, ppchar = envp; ppchar && *ppchar; ppchar++) {
4781 for (ppchar2 = ignoreEnvPtr; ppchar2 && *ppchar2; ppchar2++) {
4783 if ((!strncmp (*ppchar, *ppchar2, strlen (*ppchar2))) &&
4784 (((*ppchar)[strlen(*ppchar2)]) == '=')) {
4790 retEnv[count] = *ppchar;
4794 retEnv[count] = NULL;
4800 * MarkFileDescriptors - mark file descriptiors start_fd through open_max
4801 * with the given "cmd" and "data".
4803 * The code for calculating open_max was taken from DtSvc/DtUtil1/CmdMain.c
4806 MarkFileDescriptors (
4814 open_max = sysconf(_SC_OPEN_MAX);
4816 if (open_max == -1) {
4820 #if defined(USL) || defined(__uxp__) || defined(_AIX)
4821 open_max = FOPEN_MAX;
4823 open_max = FD_SETSIZE;
4825 #endif /* _SUN_OS */
4828 for (i = start_fd; i < open_max; i++)
4829 (void) fcntl (i, cmd, data);