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: SmGlobals.c /main/37 1998/10/26 17:21:18 mgreess $ */
25 * (c) Copyright 1995 Digital Equipment Corporation.
26 * (c) Copyright 1993, 1994, 1995 Hewlett-Packard Company
27 * (c) Copyright 1993, 1994, 1995 International Business Machines Corp.
28 * (c) Copyright 1993, 1994, 1995 Sun Microsystems, Inc.
29 * (c) Copyright 1993, 1994, 1995 Novell, Inc.
30 * (c) Copyright 1995 FUJITSU LIMITED.
31 * (c) Copyright 1995 Hitachi.
33 /*************************************<+>*************************************
34 *****************************************************************************
38 ** Project: HP DT Session Manager (dtsession)
42 ** This file contains all routines in charge of managing all global
43 ** variables used by the session manager. These variables include
44 ** mostly state and setting information.
48 *******************************************************************
49 ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
50 ** reserved. Copying or other reproduction of this program
51 ** except for archival purposes is prohibited without prior
52 ** written consent of Hewlett-Packard Company.
53 ********************************************************************
57 *****************************************************************************
58 *************************************<+>*************************************/
62 #include <sys/types.h>
63 #include <sys/utsname.h>
66 #include <X11/apollosys.h> /* for pid_t, in hp-ux sys/types.h */
69 #include <sys/param.h>
70 #include <X11/Intrinsic.h>
71 #include <X11/Xutil.h>
72 #include <X11/StringDefs.h>
75 #include <Dt/SessionP.h>
78 #include <Dt/UserMsg.h>
79 #include <Dt/HourGlass.h>
80 #include <Dt/SessionM.h>
81 #include <Dt/EnvControlP.h>
82 #include <Dt/Qualify.h>
83 #include <Dt/MsgLog.h>
85 #include "SmResource.h"
88 #include "SmGlobals.h"
90 #include "SmRestore.h"
91 #include "SmProtocol.h"
95 * Internal Variable Declaraions
97 static char savedDir [MAXPATHLEN];
98 static char savedOldDir [MAXPATHLEN];
99 static char savedTmpDir [MAXPATHLEN];
102 * Internal Function Declaraions
105 static int SetSysDefaults( void ) ;
106 static int SetResSet( void ) ;
107 static void RemoveFiles( char *) ;
108 static void TrimErrorlog(void);
110 static void _SmWaitClientTimeoutDefault (
115 static void _SmWaitWmTimeoutDefault (
120 void SmCvtStringToContManagement (
126 unsigned char *_DtNextToken (
127 unsigned char *pchIn,
129 unsigned char **ppchNext);
131 Boolean _DtWmStringsAreEqual (
136 static Boolean InitializeSpecificSession (
142 static void InitializeGenericSession (
145 static void InitializePaths (
146 char *session_option,
149 static Boolean SetAlternateSession (
159 * These are the global structures used throughout dtsession
160 * They are defined in Sm.h
162 SessionResources smRes;
163 SaverResources smSaverRes;
166 SessionSettings smSettings;
168 char SM_SCREEN_SAVER_LOC [MAXPATHLEN + 1];
171 * Internal Global Data
173 static char tmpDisplayName[MAXPATHLEN + 1];
176 static XtResource sessionResources[]=
178 {SmNwmStartup, SmCwmStartup, XtRString, sizeof(String),
179 XtOffset(SessionResourcesPtr, wmStartup),
180 XtRImmediate, (XtPointer) NULL},
181 {SmNquerySettings, SmCquerySettings, XtRBoolean, sizeof(Boolean),
182 XtOffset(SessionResourcesPtr, querySettings),
183 XtRImmediate, (XtPointer) False},
184 {SmNkeys, SmCkeys, XtRString, sizeof(String),
185 XtOffset(SessionResourcesPtr, keyholders), XtRString, NULL},
186 {SmNalarmTime, SmCalarmTime, XtRInt, sizeof(int),
187 XtOffset(SessionResourcesPtr, alarmTime),
188 XtRImmediate, (XtPointer) 10},
189 {SmNmemThreshold, SmCmemThreshold, XtRInt, sizeof(int),
190 XtOffset(SessionResourcesPtr, memThreshold),
191 XtRImmediate, (XtPointer) 100},
192 {SmNsessionVersion, SmCsessionVersion, XtRString, sizeof(String),
193 XtOffset(SessionResourcesPtr, sessionVersion),
194 XtRImmediate, (XtPointer) NULL},
195 {SmNdisplayResolution, SmCdisplayResolution, XtRInt, sizeof(int),
196 XtOffset(SessionResourcesPtr, displayResolution),
197 XtRImmediate, (XtPointer) 0},
198 {SmNsessionLang, SmCsessionLang, XtRString, sizeof(String),
199 XtOffset(SessionResourcesPtr, sessionLang),
200 XtRImmediate, (XtPointer) ""},
201 {SmNcontManagement, SmCContManagement, SmRContManagement, sizeof(long),
202 XtOffset(SessionResourcesPtr, contManagement),
203 XtRImmediate, (XtPointer) (SM_CM_DEFAULT)},
204 {SmNwaitClientTimeout, SmCWaitClientTimeout, XtRInt, sizeof(int),
205 XtOffset(SessionResourcesPtr, waitClientTimeout),
206 XtRCallProc, (XtPointer)_SmWaitClientTimeoutDefault },
207 {SmNwaitWmTimeout, SmCWaitWmTimeout, XtRInt, sizeof(int),
208 XtOffset(SessionResourcesPtr, waitWmTimeout),
209 XtRCallProc, (XtPointer)_SmWaitWmTimeoutDefault },
210 {SmNuseMessaging, SmCUseMessaging, XtRBoolean, sizeof(Boolean),
211 XtOffset(SessionResourcesPtr, useBMS),
212 XtRImmediate, (XtPointer) True},
213 {SmNsaveFontPath, SmCsaveFontPath, XtRBoolean, sizeof(Boolean),
214 XtOffset(SessionResourcesPtr, saveFontPath),
215 XtRImmediate, (XtPointer) False},
216 {SmNsaveYourselfTimeout, SmCsaveYourselfTimeout, XtRInt, sizeof(int),
217 XtOffset(SessionResourcesPtr, saveYourselfTimeout),
218 XtRImmediate, (XtPointer) 5},
219 {SmNnumSessionsBackedup, SmCnumSessionsBackedup, XtRInt, sizeof(int),
220 XtOffset(SessionResourcesPtr, numSessionsBackedup),
221 XtRImmediate, (XtPointer) DEFAULT_NUM_SESSIONS_BACKED_UP},
222 {SmNignoreEnvironment, SmCignoreEnvironment, XtRString, sizeof(String),
223 XtOffset(SessionResourcesPtr, ignoreEnvironment),
224 XtRImmediate, (XtPointer) NULL},
229 static XtResource saverResources[]=
231 {SmNcycleTimeout, SmCcycleTimeout, XtRInt, sizeof(int),
232 XtOffset(SaverResourcesPtr, cycleTimeout),
233 XtRImmediate, (XtPointer) -1},
234 {SmNlockTimeout, SmClockTimeout, XtRInt, sizeof(int),
235 XtOffset(SaverResourcesPtr, lockTimeout),
236 XtRImmediate, (XtPointer) -1},
237 {SmNsaverTimeout, SmCsaverTimeout, XtRInt, sizeof(int),
238 XtOffset(SaverResourcesPtr, saverTimeout),
239 XtRImmediate, (XtPointer) -1},
240 {SmNrandom, SmCrandom, XtRBoolean, sizeof(Boolean),
241 XtOffset(SaverResourcesPtr, random),
242 XtRImmediate, (XtPointer) False},
243 {SmNsaverList, SmCsaverList, XtRString, sizeof(String),
244 XtOffset(SaverResourcesPtr, saverList),
245 XtRImmediate, (XtPointer) ""},
253 * Machine specific defaults.
263 { 0, 20, 60}, /* Machine independent default */
265 {300, 10, 60}, /* HP s300 */
266 {400, 10, 60}, /* HP s400 */
267 {600, 5, 60}, /* HP s600 */
268 {700, 5, 60}, /* HP s700 */
269 {800, 5, 60}, /* HP s800 */
272 #define MACHINEDEFAULTS (sizeof(machineDefault) / sizeof(machineDefault[0]))
275 /*************************************<->*************************************
277 * _SmWaitClientTimeoutDefault (widget, offset, value)
282 * This function generates a default value for the waitClientTimeout resource.
283 * We dynamically default to 10 seconds for s400/s300 and to
284 * 5 seconds for s700/s800.
288 * widget = this is not used
290 * offset = this is the resource offset
292 * value = this is a pointer to a XrmValue in which to store the result
296 * value = default resource value and size
298 *************************************<->***********************************/
301 _SmWaitClientTimeoutDefault (Widget widget, int offset, XrmValue *value)
305 for (i = 0; i < MACHINEDEFAULTS; i++)
307 if (machineDefault[i].machineType == machineType)
313 if (i == MACHINEDEFAULTS)
318 value->addr = (char *)&machineDefault[i].clientTimeout;
319 value->size = sizeof (int);
321 } /* END OF FUNCTION _SmWaitClientTimeoutDefault */
325 /*************************************<->*************************************
327 * _SmWaitWmTimeoutDefault (widget, offset, value)
332 * This function generates a default value for the waitWmTimeout resource.
333 * We dynamically default to 60 seconds for s400/s300 and to
334 * 60 seconds for s700/s800. This could change if we get feedback indicating
335 * the need for a new default.
339 * widget = this is not used
341 * offset = this is the resource offset
343 * value = this is a pointer to a XrmValue in which to store the result
347 * value = default resource value and size
349 *************************************<->***********************************/
352 _SmWaitWmTimeoutDefault (Widget widget, int offset, XrmValue *value)
356 smGD.userSetWaitWmTimeout = False; /* if we are here, it is not user set */
358 for (i = 0; i < MACHINEDEFAULTS; i++)
360 if (machineDefault[i].machineType == machineType)
366 if (i == MACHINEDEFAULTS)
371 value->addr = (char *)&machineDefault[i].wmTimeout;
372 value->size = sizeof (int);
374 } /* END OF FUNCTION _SmWaitWmTimeoutDefault */
378 /*************************************<->*************************************
385 * Sets SM global resources and global settings to a starting value.
390 * buttonForm = form widget for button that allows cursor to get colors
391 * smRes(global) = structure that holds session resources.
392 * smToSet(global) = structure that holds "which settings to set and how" info
393 * smGD(global) = structure that holds general data info
397 * smRes(global) = structure that holds session resources.
398 * smToSet(global) = structure that holds "which settings to set and how" info
399 * smGD(global) = structure that holds general data info
403 * Resources are set to an initial value by the resource manager. The
404 * rest are set in the routine.
406 *************************************<->***********************************/
408 InitSMGlobals( void )
411 PropDtSmWindowInfo property;
412 struct utsname nameRec;
416 smGD.userSetWaitWmTimeout = True; /* assume it is */
419 if (uname(&nameRec) == 0)
421 keyNum = nameRec.machine;
422 if (firstSlash = strchr(keyNum, '/'))
424 keyNum = ++firstSlash;
426 if ( keyNum[0] == '3')
430 else if (keyNum[0] == '4')
434 else if (keyNum[0] == '6')
438 else if (keyNum[0] == '7')
442 else if (keyNum[0] == '8')
451 * Get application specific resource values
453 XtAppAddConverter (smGD.appCon, XtRString, SmRContManagement,
454 (XtConverter)SmCvtStringToContManagement, NULL, 0);
455 XtGetApplicationResources(smGD.topLevelWid, (XtPointer) &smRes,
457 XtNumber(sessionResources), NULL, 0);
459 if (smGD.lockOnTimeoutStatus == True)
462 * Pull screen saver resources from Dtsession*extension.<name>.
464 smGD.SmNextension = "extension";
465 smGD.SmCextension = "Extension";
466 smGD.extensionSpec = "extension.";
471 * Pull screen saver resources from Dtsession*<name>.
473 smGD.SmNextension = smGD.SmNextension = smGD.extensionSpec = "";
476 XtGetSubresources(smGD.topLevelWid, (XtPointer) &smSaverRes,
477 smGD.SmNextension, smGD.SmCextension,
479 XtNumber(saverResources), NULL, 0);
481 smGD.wmStartup = SmNewString(smRes.wmStartup);
482 smGD.keyholders = SmNewString(smRes.keyholders);
483 smGD.sessionLang = SmNewString(smRes.sessionLang);
484 smGD.saverList = SmNewString(smSaverRes.saverList);
487 * Initialize general data used by apps not initialized by
488 * XtInitialize or DtInitialize
490 smGD.topLevelWindow = XtWindow(smGD.topLevelWid);
491 smGD.numSavedScreens = (ScreenCount(smGD.display) > MAX_SCREENS_SAVED)
492 ? MAX_SCREENS_SAVED : ScreenCount(smGD.display);
493 smGD.dtwmRunning = False;
494 smSettings.confirmMode = DtSM_VERBOSE_MODE;
495 if (smGD.sessionType == CURRENT_SESSION ||
496 smGD.sessionType == DEFAULT_SESSION)
497 smSettings.startState = DtSM_CURRENT_STATE;
499 smSettings.startState = DtSM_HOME_STATE;
500 smGD.homeSave = False;
501 smGD.saverListParse = NULL;
503 smGD.loggingOut = False;
506 * Sanity check on timeouts for negative numbers
508 if (smRes.waitClientTimeout < 0)
510 smRes.waitClientTimeout = -smRes.waitClientTimeout;
512 if (smRes.waitWmTimeout < 0)
514 smRes.waitWmTimeout = -smRes.waitWmTimeout;
516 if (smRes.saveYourselfTimeout < 0)
518 smRes.saveYourselfTimeout = -smRes.saveYourselfTimeout;
523 * Now convert users view of seconds in to XtAppAddTimout's
524 * need for milliseconds.
526 smRes.waitClientTimeout = 1000 * smRes.waitClientTimeout;
527 smRes.waitWmTimeout = 1000 * smRes.waitWmTimeout;
528 smRes.saveYourselfTimeout = 1000 * smRes.saveYourselfTimeout;
529 smGD.savedWaitWmTimeout = smRes.waitWmTimeout;
532 * Initialize lock data
534 smGD.screen = XDefaultScreen(smGD.display);
535 smGD.blackPixel = XBlackPixel(smGD.display, smGD.screen);
536 smGD.whitePixel = XWhitePixel(smGD.display, smGD.screen);
537 smDD.lockDialog = NULL;
538 smDD.lockCoverDialog = NULL;
539 for(i = 0;i < smGD.numSavedScreens;i++)
541 smDD.coverDialog[i] = NULL;
542 smDD.coverDrawing[i] = NULL;
544 smGD.lockedState = UNLOCKED;
547 * Sanity check screen saver resource values.
549 if (smRes.alarmTime < 0) smRes.alarmTime = 0;
551 #define SMBOUND(A) (A < 0 ? 0 : A)
553 smSaverRes.lockTimeout = SMBOUND(smSaverRes.lockTimeout) * 60;
554 smSaverRes.saverTimeout = SMBOUND(smSaverRes.saverTimeout) * 60;
555 smSaverRes.cycleTimeout = SMBOUND(smSaverRes.cycleTimeout) * 60;
558 smGD.waitCursor = _DtGetHourGlassCursor(smGD.display);
561 * Initialize other global data related to dialogs
563 smDD.confExit = NULL;
565 smDD.compatExit = NULL;
567 smDD.saveSession = NULL; /* Error dialog for Save_Session */
569 if (!smDD.smHelpDialog)
571 * Don't wipe it out if it is already created
573 smDD.smHelpDialog = NULL;
576 * Intern all the atoms needed for the WSM communication
579 enum { XA_DT_SM_WINDOW_INFO, XA_DT_SM_WM_PROTOCOL,
580 XA_DT_SM_START_ACK_WINDOWS, XA_DT_SM_STOP_ACK_WINDOWS,
581 XA_DT_WM_WINDOW_ACK, XA_DT_WM_EXIT_SESSION,
582 XA_DT_WM_LOCK_DISPLAY, XA_DT_WM_READY, NUM_ATOMS };
583 static char *atom_names[] = {
584 _XA_DT_SM_WINDOW_INFO, _XA_DT_SM_WM_PROTOCOL,
585 _XA_DT_SM_START_ACK_WINDOWS, _XA_DT_SM_STOP_ACK_WINDOWS,
586 _XA_DT_WM_WINDOW_ACK, _XA_DT_WM_EXIT_SESSION,
587 _XA_DT_WM_LOCK_DISPLAY, _XA_DT_WM_READY };
589 Atom atoms[XtNumber(atom_names)];
591 XInternAtoms(smGD.display, atom_names, XtNumber(atom_names),
594 XaVsmInfo = atoms[XA_DT_SM_WINDOW_INFO];
595 XaSmWmProtocol = atoms[XA_DT_SM_WM_PROTOCOL];
596 XaSmStartAckWindow = atoms[XA_DT_SM_START_ACK_WINDOWS];
597 XaSmStopAckWindow = atoms[XA_DT_SM_STOP_ACK_WINDOWS];
598 XaWmWindowAck = atoms[XA_DT_WM_WINDOW_ACK];
599 XaWmExitSession = atoms[XA_DT_WM_EXIT_SESSION];
600 XaWmLockDisplay = atoms[XA_DT_WM_LOCK_DISPLAY];
601 XaWmReady = atoms[XA_DT_WM_READY];
605 * Set the session manager window property on the root window
608 property.smWindow = (unsigned long) smGD.topLevelWindow;
609 XChangeProperty (smGD.display, RootWindow(smGD.display, 0),
610 XaVsmInfo, XaVsmInfo,
611 32, PropModeReplace, (unsigned char *)&property,
612 PROP_DT_SM_WINDOW_INFO_ELEMENTS);
615 * Set up the signal handler for forking and execing
617 sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
622 /*************************************<->*************************************
629 * Sets SM global resources and global settings to a starting value.
634 * smGD.display = display structure for session manager. Used to construct
635 * a display directory
639 * smGD.resourcePath(global) = Path where the resources to be restored are
641 * smGD.settingPath(global) = Path where the settings to be restored are
643 * smGD.clientPath(global) = Path where the clients to be restored are
645 * smGD.savePath(global) = Path where all save files are to be saved
653 * WARNING: This routine also determines whether dtsession is being started
654 * in compatibility mode. If so - no restore paths are set up and
655 * the routine is exited.
657 *************************************<->***********************************/
665 char *displayName = NULL;
666 char *session_option = NULL;
668 smGD.compatMode = False;
670 for(i = 0;i < argc;i++)
672 if(!strcmp(argv[i], "-display"))
674 displayName = argv[i + 1];
676 * If -display is used but DISPLAY is not set,
677 * put DISPLAY into the environment
679 if (getenv("DISPLAY") == 0)
681 sprintf(tmpDisplayName, "DISPLAY=%s", displayName);
682 putenv(tmpDisplayName);
686 if(!strcmp(argv[i], "-norestore"))
688 smGD.compatMode = True;
691 if(!strcmp(argv[i], "-session"))
698 pch = strdup ((char *) GETMESSAGE (40, 15,
699 " No session name was provided for the -session command line option."));
702 DtMsgLogMessage (argv[0], DtMsgLogWarning, pch);
707 session_option = argv[i];
712 * If we are in compatibility mode - no restore paths are set
713 * up and we just return
715 if(smGD.compatMode == True)
717 smGD.clientPath[0] = 0;
718 smGD.resourcePath[0] = 0;
719 smGD.settingPath[0] = 0;
720 smGD.sessionType = DEFAULT_SESSION;
721 smGD.restoreSession = NULL;
725 tmpDisplay = XOpenDisplay(displayName);
726 if(tmpDisplay == NULL)
728 PrintError(DtError, GETMESSAGE(4, 1, "Invalid display name - exiting."));
734 if (!InitializeSpecificSession (session_option, tmpDisplay, argc, argv))
735 InitializeGenericSession (tmpDisplay);
738 InitializeGenericSession (tmpDisplay);
741 * Need to know if the session is for a specific display
743 smGD.displaySpecific = True;
744 if (session_option = strrchr (smGD.savePath, '/'))
747 if (!strcmp (session_option, DtSM_SESSION_DIRECTORY))
748 smGD.displaySpecific = False;
752 XCloseDisplay(tmpDisplay);
755 ** User's session startup script:
756 ** $HOME/.dt/sessions/sessionetc
758 strcpy(smGD.etcPath, smGD.savePath);
759 strcat(smGD.etcPath, "/");
760 strcat(smGD.etcPath, smEtcFile);
763 ** User's session shutdown script:
764 ** $HOME/.dt/sessions/sessionexit
766 strcpy(smGD.exitPath, smGD.savePath);
767 strcat(smGD.exitPath, "/");
768 strcat(smGD.exitPath, smExitFile);
780 char * pathList = (char *)XtMalloc(strlen(SM_SYSTEM_PATH) +
781 strlen(":" CDE_INSTALLATION_TOP "/config") + 1);
783 strcpy(pathList,SM_SYSTEM_PATH);
784 strcat(pathList,":" CDE_INSTALLATION_TOP "/config");
786 tempPath = _DtQualifyWithFirst(the1stPath,pathList);
787 if (tempPath != NULL) {
788 strcpy(the1stPath,tempPath);
796 /*************************************<->*************************************
803 * Sets the path to restore the system default files. A convenience routine
808 * smGD.savePath = path that files are to be saved in (set up in
813 * smGD.resourcePath(global) = Path where the resources to be saved are
815 * smGD.settingPath(global) = Path where the settings to be saved are
817 * smGD.clientPath(global) = Path where the clients to be saved are
823 *************************************<->***********************************/
825 SetSysDefaults( void )
834 * No files exist for restoration - use the
837 strcpy(smGD.resourcePath, "");
838 strcpy(smGD.clientPath, "");
839 smGD.settingPath[0] = 0;
840 smGD.sessionType = DEFAULT_SESSION;
841 smGD.restoreSession = (char *) SM_SYSTEM_DIRECTORY;
843 langSpec = getenv("LANG");
844 if ((langSpec != NULL) && (*langSpec != 0))
846 strcat(smGD.clientPath, "/");
847 strncat(smGD.clientPath, langSpec, MAXPATHLEN-2);
848 smGD.clientPath[MAXPATHLEN-1] = 0;
851 strcat(smGD.clientPath, "/");
852 strcat(smGD.clientPath, SM_SYSTEM_CLIENT_FILE);
854 FixPath(smGD.clientPath);
857 * If the system files don't exist - we're in
858 * trouble - First try LANG location then default
860 status = stat(smGD.clientPath, &buf);
863 if((langSpec == NULL) || (*langSpec == 0))
865 PrintErrnoError(DtError, GETMESSAGE(4, 2,
866 "No defaults files exist. "
867 "No applications will be restarted."));
868 smGD.clientPath[0] = 0;
869 smGD.resourcePath[0] = 0;
873 strcpy(smGD.clientPath, "/C/");
874 strcat(smGD.clientPath, SM_SYSTEM_CLIENT_FILE);
876 FixPath(smGD.clientPath);
878 status = stat(smGD.clientPath, &buf);
881 PrintErrnoError(DtError, GETMESSAGE(4, 3,
882 "No defaults files exist. "
883 "No applications will be restarted."));
884 smGD.clientPath[0] = 0;
885 smGD.resourcePath[0] = 0;
895 /*************************************<->*************************************
902 * Sets the path to restore the settings and resource files.
903 * A convenience routine
908 * smGD.savePath = path that files are to be saved in (set up in
913 * smGD.resourcePath(global) = Path where the resources to be saved are
915 * smGD.settingPath(global) = Path where the settings to be saved are
917 * smGD.clientPath(global) = Path where the clients to be saved are
923 *************************************<->***********************************/
931 * If resource or settings file does not exist - just null out
932 * the path so these things will not get restored
934 status = stat(smGD.resourcePath, &buf);
937 smGD.resourcePath[0] = 0;
940 status = stat(smGD.settingPath, &buf);
943 smGD.settingPath[0] = 0;
949 /*************************************<->*************************************
951 * UndoSetSavePath () - Undoes the directory manipulations done by
952 * SetSavePath. This function is only called if a shutdown/save
955 *************************************<->***********************************/
961 if (strcmp ("", savedDir)) {
964 * Remove the directory where the save occurred, e.g.:
966 * ~/.dt/<session_dir>/current
967 * ~/.dt/<session_dir>/home
969 buf = XtMalloc (strlen (savedDir) + 9);
970 sprintf (buf, "rm -rf %s", savedDir);
974 if (strcmp ("", savedOldDir)) {
976 MoveDirectory (savedOldDir, savedDir, False);
978 if (strcmp ("", savedTmpDir)) {
979 MoveDirectory (savedTmpDir, savedOldDir, False);
986 /*************************************<->*************************************
988 * SetSavePath (saveToHome, mode)
993 * Sets up paths for files that need to be saved. Also removes any files
994 * that shouldn't be there after the save.
999 * smGD.display = display structure for session manager. Used to construct
1000 * a display directory
1001 * saveToHome = whether this is a save to home session or not
1002 * mode = whether we are resetting or restarting
1006 * smGD.resourcePath(global) = Path where the resources to be saved are
1008 * smGD.settingPath(global) = Path where the settings to be saved are
1010 * smGD.clientPath(global) = Path where the clients to be saved are
1016 *************************************<->***********************************/
1026 * These directory paths are needed in UndoSetSavePaths
1027 * if a shutdown/save is canceled.
1029 strcpy (savedDir, "");
1030 strcpy (savedOldDir, "");
1031 strcpy (savedTmpDir, "");
1034 * Make sure the user hasn't done something like delete the .dt
1035 * directories during the session. If so - recreate them
1037 SM_FREE(smGD.savePath);
1038 smGD.savePath = _DtCreateDtDirs(smGD.display);
1039 if(smGD.savePath == NULL)
1041 PrintErrnoError(DtError, smNLS.cantCreateDirsString);
1042 smGD.clientPath[0] = 0;
1043 smGD.settingPath[0] = 0;
1044 smGD.resourcePath[0] = 0;
1050 * Path for a save defaults to save the current session.
1051 * Otherwise just remove the directories
1053 strcpy(smGD.clientPath, smGD.savePath);
1054 strcpy(smGD.settingPath, smGD.savePath);
1055 strcpy(smGD.resourcePath, smGD.savePath);
1056 strcat(smGD.clientPath, "/");
1057 strcat(smGD.settingPath, "/");
1058 strcat(smGD.resourcePath, "/");
1060 if(saveToHome == False)
1062 strcat(smGD.clientPath, SM_CURRENT_DIRECTORY);
1063 strcat(smGD.resourcePath, SM_CURRENT_DIRECTORY);
1064 strcat(smGD.settingPath, SM_CURRENT_DIRECTORY);
1065 smGD.restoreSession = SM_CURRENT_DIRECTORY;
1069 strcat(smGD.clientPath, SM_HOME_DIRECTORY);
1070 strcat(smGD.resourcePath, SM_HOME_DIRECTORY);
1071 strcat(smGD.settingPath, SM_HOME_DIRECTORY);
1072 smGD.restoreSession = SM_HOME_DIRECTORY;
1075 if ((mode == DtSM_HOME_STATE) && (saveToHome == False) &&
1076 (smSettings.startState == DtSM_HOME_STATE))
1079 * The only time this should should be true is if the
1080 * current session is a Home session and the session
1081 * is being exited. The idea is that if a "current"
1082 * directory exits, it must be moved because when the
1083 * user next logs in, a Home session should be started
1084 * (if a session is not selected at the login screen)
1085 * and the Session Manager decides whether or not it
1086 * starts a Home or Current session based on if a
1087 * "current" directory exists. If a "current" directory
1088 * exists, a Current session will be started.
1090 status = stat(smGD.clientPath, &buf);
1094 * The "current" directory exists and must be moved to its
1095 * ".old" version. But first, if the ".old" version exists,
1096 * it must be moved to a temporary directory. This temporary
1097 * directory will eventually be pruned - when a user next
1098 * runs a Current session and saves the session.
1100 strcpy (savedDir, smGD.clientPath);
1101 sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
1102 status = stat(smGD.etcPath, &buf);
1108 strcpy (savedOldDir, smGD.etcPath);
1110 tmpName = (char *) XtMalloc (strlen (smGD.restoreSession) + 2);
1111 sprintf (tmpName, "%s.", smGD.restoreSession);
1112 if (strlen (tmpName) > 5) {
1114 tmpName[5] = '\000';
1116 tmpDir = (char *) tempnam (smGD.savePath, tmpName);
1117 MoveDirectory (smGD.etcPath, tmpDir, False);
1119 strcpy (savedTmpDir, tmpDir);
1121 XtFree ((char *) tmpName);
1123 MoveDirectory(smGD.clientPath, smGD.etcPath, False);
1126 smGD.clientPath[0] = 0;
1127 smGD.settingPath[0] = 0;
1128 smGD.resourcePath[0] = 0;
1132 strcpy (savedDir, smGD.clientPath);
1135 * If the desired directory doesn't exist, create it.
1137 status = stat(smGD.clientPath, &buf);
1140 status = mkdir(smGD.clientPath, 0000);
1143 PrintErrnoError(DtError, smNLS.cantCreateDirsString);
1144 smGD.clientPath[0] = 0;
1145 smGD.settingPath[0] = 0;
1146 smGD.resourcePath[0] = 0;
1149 chmod(smGD.clientPath, 0755);
1154 * The desired directory already exists so it must
1155 * be archived by moving it to its ".old" version. But
1156 * first, if its ".old" version already exists, it must
1157 * be moved to a temporary directory that will be removed
1158 * when the session directories are pruned - after the
1164 sprintf(smGD.etcPath, "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
1165 status = stat(smGD.etcPath, &buf);
1168 tmpName = (char *) XtMalloc (strlen (smGD.restoreSession) + 2);
1169 sprintf (tmpName, "%s.", smGD.restoreSession);
1170 strcpy (savedOldDir, smGD.etcPath);
1171 if (strlen (tmpName) > 5) {
1173 tmpName[5] = '\000';
1175 tmpDir = (char *) tempnam (smGD.savePath, tmpName);
1176 MoveDirectory (smGD.etcPath, tmpDir, False);
1178 strcpy (savedTmpDir, tmpDir);
1180 XtFree ((char *) tmpName);
1183 MoveDirectory(smGD.clientPath, smGD.etcPath, False);
1186 * Now re-make the directory
1188 status = mkdir(smGD.clientPath, 0000);
1191 PrintErrnoError(DtError, smNLS.cantCreateDirsString);
1192 smGD.clientPath[0] = 0;
1193 smGD.settingPath[0] = 0;
1194 smGD.resourcePath[0] = 0;
1197 chmod(smGD.clientPath, 0755);
1200 strcat(smGD.clientPath, "/");
1201 strcat(smGD.clientPath, SM_CLIENT_FILE2);
1202 strcat(smGD.settingPath, "/");
1203 strcat(smGD.settingPath, SM_SETTING_FILE);
1204 strcat(smGD.resourcePath, "/");
1205 strcat(smGD.resourcePath, SM_RESOURCE_FILE);
1212 /*************************************<->*************************************
1214 * SetFontSavePath (saveToHome, mode)
1219 * Sets up the save path for the auxillary directory.
1231 *************************************<->***********************************/
1233 SetFontSavePath(char *langPtr)
1241 * Set up the session font directory and see if it exists
1243 if(smGD.sessionType == CURRENT_SESSION)
1245 sessionSaved = SM_CURRENT_FONT_DIRECTORY;
1249 sessionSaved = SM_HOME_FONT_DIRECTORY;
1252 sprintf(smGD.fontPath, "%s/%s", smGD.savePath, sessionSaved);
1253 status = stat(smGD.fontPath, &buf);
1256 status = mkdir(smGD.fontPath, 0000);
1259 PrintErrnoError(DtError, smNLS.cantCreateDirsString);
1260 smGD.fontPath[0] = 0;
1263 chmod(smGD.fontPath, 0755);
1267 * Now add the lang subdirectory and see if it exists
1269 strcat(smGD.fontPath, "/");
1270 strcat(smGD.fontPath, langPtr);
1271 status = stat(smGD.fontPath, &buf);
1274 status = mkdir(smGD.fontPath, 0000);
1277 PrintErrnoError(DtError, smNLS.cantCreateDirsString);
1278 smGD.fontPath[0] = 0;
1281 chmod(smGD.fontPath, 0755);
1289 /*************************************<->*************************************
1296 * Remove the files that need to be removed
1309 *************************************<->***********************************/
1315 int execStatus, childStatus, i, statLoc;
1319 * Fork and exec the client process
1321 sigaction(SIGCHLD, &smGD.defvec, (struct sigaction *) NULL);
1323 clientFork = vfork();
1326 * If the fork fails - Send out an error and return
1330 PrintErrnoError(DtError, smNLS.cantForkClientString);
1335 * Fork succeeded - now do the exec
1339 SetSIGPIPEToDefault ();
1342 * Set the gid of the process back from bin
1346 setregid(smGD.runningGID, smGD.runningGID);
1348 setgid(smGD.runningGID);
1349 setegid(smGD.runningGID);
1353 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
1355 #if defined(__osf__) || defined(CSRG_BASED)
1359 #endif /* __osf__ */
1361 execStatus = execlp("rm","rm", "-rf", path, (char *) 0);
1364 tmpString = ((char *)GETMESSAGE(4, 4, "Unable to remove session directory. Make sure write permissions exist on $HOME/.dt directory. Invalid session files will not be removed.")) ;
1365 PrintErrnoError(DtError, tmpString);
1371 while(wait(&statLoc) != clientFork);
1373 sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
1377 /*************************************<->*************************************
1383 * Move the directory specified by pathFrom - to the directory specified
1388 * pathFrom = the directory to move from
1389 * pathTo = the directory to move to
1390 * removeDestDir = if True, directory pathTo is removed before the
1399 *************************************<->***********************************/
1404 Boolean removeDestDir)
1408 int status, execStatus, childStatus, i, statLoc;
1412 * If the pathTo directory exists - remove it
1416 status = stat(pathTo, &buf);
1419 RemoveFiles(pathTo);
1424 * Fork and exec the client process
1426 sigaction(SIGCHLD, &smGD.defvec, (struct sigaction *) NULL);
1428 clientFork = vfork();
1431 * If the fork fails - Send out an error and return
1435 PrintErrnoError(DtError, smNLS.cantForkClientString);
1440 * Fork succeeded - now do the exec
1444 SetSIGPIPEToDefault ();
1447 * Set the gid of the process back from bin
1451 setregid(smGD.runningGID, smGD.runningGID);
1453 setgid(smGD.runningGID);
1454 setegid(smGD.runningGID);
1458 _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
1460 #if defined(__osf__) || defined(CSRG_BASED)
1464 #endif /* __osf__ */
1466 execStatus = execlp("mv","mv", pathFrom, pathTo, (char *) 0);
1469 tmpString = ((char *)GETMESSAGE(4, 4, "Unable to remove session directory. Make sure write permissions exist on $HOME/.dt directory. Invalid session files will not be removed.")) ;
1470 PrintErrnoError(DtError, tmpString);
1476 while(wait(&statLoc) != clientFork);
1478 sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
1483 /*************************************<->*************************************
1490 * Initialize the NLS strings used in dtsession
1503 *************************************<->***********************************/
1505 InitNlsStrings( void )
1510 * Malloc failure error message - THIS MESSAGE MUST BE INITIALIZED FIRST
1512 smNLS.cantMallocErrorString = strdup (((char *)GETMESSAGE(4, 5, "Unable to malloc memory for operation.")));
1515 * Error message when dtsession cant lock the display
1517 smNLS.cantLockErrorString = strdup (((char *)GETMESSAGE(4, 6, "Unable to lock display. Another application may have the pointer or keyboard grabbed.")));
1520 * Error message when dtsession cant open files for reading or writing
1522 smNLS.cantOpenFileString = strdup (((char *)GETMESSAGE(4, 7, "Unable to open session file. No clients will be restarted.")));
1525 * Error message when dtsession cant fork client process
1527 smNLS.cantForkClientString = strdup (((char *)GETMESSAGE(4, 8, "Unable to fork client process.")));
1530 * Error message when dtsession cant create dt directories
1532 smNLS.cantCreateDirsString = strdup (((char *)GETMESSAGE(4, 9, "Unable to create DT directories. Check permissions on home directory.")));
1535 * Error message when trying to lock display on trusted system
1537 smNLS.trustedSystemErrorString = strdup (((char *)GETMESSAGE(4, 10, "Unable to lock display due to security restrictions")));
1542 /*************************************<->*************************************
1549 * When a SIGCHLD signal comes in, wait for all child processes to die.
1562 *************************************<->***********************************/
1565 WaitChildDeath( int i )
1571 * Wait on any children that have died since the last SIGCHLD we
1572 * received. Any child process death that occurs while we are
1573 * in WaitChildDeath() will not result in a SIGCHLD. Any
1574 * child proceses that die after our last call to waitpid() will
1575 * remain zombiefied until the next invocation of WaitChildDeath().
1577 while ((pid = waitpid(-1, &stat_loc, WNOHANG)) > 0)
1580 sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
1585 /*************************************<->*************************************
1592 * Trim the errorlog file using the following algorithm:
1593 * if(errorlog.old exists and is not empty) move it to errorlog.oldest
1594 * if(errorlog exists and is not empty) move it to errorlog.old
1607 *************************************<->***********************************/
1609 TrimErrorlog( void )
1611 char *savePath, /* common path element for all pathnames */
1619 * Allocate the strings needed
1621 savePath = (char *) SM_MALLOC(MAXPATHLEN + 1);
1622 checkPath1 = (char *) SM_MALLOC(MAXPATHLEN + 1);
1623 checkPath2 = (char *) SM_MALLOC(MAXPATHLEN + 1);
1624 if ((home=getenv("HOME")) == NULL)
1627 len = strlen(home) + strlen(DtPERSONAL_CONFIG_DIRECTORY) + 2;
1628 if (len > MAXPATHLEN) savePath = SM_REALLOC(savePath, len);
1629 sprintf(savePath, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY);
1632 * If errorlog.old exists and it is not empty, delete
1633 * errorlog.older and then move errolog.old to
1636 if (len + strlen(DtOLDER_ERRORLOG_FILE) > MAXPATHLEN)
1637 checkPath1 = SM_REALLOC(savePath, len + strlen(DtOLDER_ERRORLOG_FILE));
1638 sprintf(checkPath1, "%s/%s", savePath, DtOLDER_ERRORLOG_FILE);
1640 if (len + strlen(DtOLD_ERRORLOG_FILE) > MAXPATHLEN)
1641 checkPath2 = SM_REALLOC(savePath, len + strlen(DtOLD_ERRORLOG_FILE));
1642 sprintf(checkPath2, "%s/%s", savePath, DtOLD_ERRORLOG_FILE);
1644 status = stat(checkPath2, &buf);
1645 if((status != -1) && (buf.st_size > 0))
1647 (void) unlink(checkPath1);
1648 (void) link(checkPath2, checkPath1);
1649 (void) unlink(checkPath2);
1653 * If errorlog exists and it is not empty, move it to
1656 if (len + strlen(DtERRORLOG_FILE) > MAXPATHLEN)
1657 checkPath1 = SM_REALLOC(savePath, len + strlen(DtERRORLOG_FILE));
1658 sprintf(checkPath1, "%s/%s", savePath, DtERRORLOG_FILE);
1660 status = stat(checkPath1, &buf);
1661 if((status != -1) && (buf.st_size > 0))
1663 (void) link(checkPath1, checkPath2);
1664 (void) unlink(checkPath1);
1667 SM_FREE((char *) savePath);
1668 SM_FREE((char *) checkPath1);
1669 SM_FREE((char *) checkPath2);
1676 /*************************************<->*************************************
1683 * Do everything that needs to be done to get the system back into a
1684 * READY state. This includes checking to be sure that the BMS did not
1685 * die while we were in process
1698 *************************************<->***********************************/
1700 SetSystemReady( void )
1702 smGD.smState = READY;
1703 if(smGD.bmsDead == True)
1712 /*************************************<->*************************************
1714 * SmCvtStringToContManagement (args, numArgs, fromVal, toVal)
1719 * This function converts a string to a value for the
1720 * contention management flag set.
1725 * args = additional XrmValue arguments to the converter - NULL here
1727 * numArgs = number of XrmValue arguments - 0 here
1729 * fromVal = resource value to convert
1734 * toVal = descriptor to use to return converted value
1736 *************************************<->***********************************/
1738 void SmCvtStringToContManagement (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
1741 unsigned char *pch = (unsigned char *) (fromVal->addr);
1742 unsigned char *pchNext;
1745 Boolean fHit = False;
1746 Boolean fAddNext = True;
1749 * Names of contention management options
1752 #define CM_ALL_STR (unsigned char *)"all"
1753 #define CM_SYSTEM_STR (unsigned char *)"system"
1754 #define CM_HANDSHAKE_STR (unsigned char *)"handshake"
1755 #define CM_NONE_STR (unsigned char *)"none"
1758 * Check first token. If '-' we subtract from all options.
1759 * Otherwise, we start with no contention management and add things in.
1763 (_DtNextToken (pch, &len, &pchNext)) &&
1774 while (*pch && _DtNextToken (pch, &len, &pchNext))
1777 * Strip off "sign" if prepended to another token, and process
1778 * that token the next time through.
1790 else if (*pch == '-')
1799 if ((*pch == 'A') || (*pch == 'a'))
1801 if (_DtWmStringsAreEqual (pch, CM_ALL_STR, len))
1803 cval = fAddNext ? (cval | SM_CM_ALL) :
1804 (cval & ~SM_CM_ALL);
1809 else if ((*pch == 'S') || (*pch == 's'))
1811 if (_DtWmStringsAreEqual (pch, CM_SYSTEM_STR, len))
1813 cval = fAddNext ? (cval | SM_CM_SYSTEM) :
1814 (cval & ~SM_CM_SYSTEM);
1819 else if ((*pch == 'H') || (*pch == 'h'))
1821 if (_DtWmStringsAreEqual (pch, CM_HANDSHAKE_STR, len))
1823 cval = fAddNext ? (cval | SM_CM_HANDSHAKE) :
1824 (cval & ~SM_CM_HANDSHAKE);
1829 else if ((*pch == 'N') || (*pch == 'n'))
1831 if (_DtWmStringsAreEqual (pch, CM_NONE_STR, len))
1833 /* don't bother adding or subtracting nothing */
1844 * If we didn't match anything then set to default.
1848 cval = SM_CM_DEFAULT;
1852 (*toVal).size = sizeof (long);
1853 (*toVal).addr = (caddr_t) &cval;
1856 } /* END OF FUNCTION SmCvtStringToContManagement */
1859 /*************************************<->*************************************
1861 * _DtNextToken (pchIn, pLen, ppchNext)
1871 * pchIn = pointer to start of next token
1876 * pLen = pointer to integer containing number of characters in next token
1877 * ppchNext = address of pointer to following token
1879 * Return = next token or NULL
1886 *************************************<->***********************************/
1888 unsigned char *_DtNextToken (unsigned char *pchIn, int *pLen,
1889 unsigned char **ppchNext)
1891 unsigned char *pchR = pchIn;
1897 for (i = 0; ((chlen = mblen ((char *)pchIn, MB_CUR_MAX)) > 0); i++)
1898 /* find end of word: requires singlebyte whitespace terminator */
1900 if ((chlen == 1) && isspace (*pchIn))
1908 for (i = 0; *pchIn && !isspace (*pchIn); i++, pchIn++)
1909 /* find end of word */
1914 /* skip to next word */
1915 ScanWhitespace (&pchIn);
1928 } /* END OF FUNCTION _DtNextToken */
1932 /*************************************<->*************************************
1934 * _DtWmStringsAreEqual (pch1, pch2, len)
1951 * Return = (Boolean) True iff strings match (case insensitive)
1958 *************************************<->***********************************/
1960 Boolean _DtWmStringsAreEqual (unsigned char *pch1, unsigned char *pch2, int len)
1969 ((chlen1 = mbtowc (&wch1, (char *) pch1, 2)) > 0) &&
1970 ((chlen2 = mbtowc (&wch2, (char *) pch2, 2)) == chlen1) )
1973 /* singlebyte characters -- make case insensitive */
1975 if ((isupper (*pch1) ? tolower(*pch1) : *pch1) !=
1976 (isupper (*pch2) ? tolower(*pch2) : *pch2))
1982 /* multibyte characters */
1995 while (len && *pch1 && *pch2 &&
1996 ((isupper (*pch1) ? tolower(*pch1) : *pch1) ==
1997 (isupper (*pch2) ? tolower(*pch2) : *pch2)))
2007 } /* END OF _DtWmStringsAreEqual */
2009 /*************************************<->*************************************
2011 * InitializeGenericSession - set the smGD paths using the CDE 1.0
2012 * session starting algorithm.
2016 * Initializes several variables in smGD
2029 *************************************<->***********************************/
2031 InitializeGenericSession (
2032 Display *tmpDisplay)
2035 int session_needed = 1;
2037 char tmpPath[MAXPATHLEN];
2039 smGD.savePath = _DtCreateDtDirs(tmpDisplay);
2043 strcpy(smGD.clientPath, smGD.savePath);
2044 strcat(smGD.clientPath, "/");
2045 strcat(smGD.clientPath, SM_CURRENT_DIRECTORY);
2046 strcat(smGD.clientPath, "/");
2047 strcpy (tmpPath, smGD.clientPath);
2048 strcat(smGD.clientPath, SM_CLIENT_FILE2);
2050 status = stat(smGD.clientPath, &buf);
2053 strcpy (smGD.clientPath, tmpPath);
2054 strcat (smGD.clientPath, SM_CLIENT_FILE);
2055 status = stat(smGD.clientPath, &buf);
2061 * sessions/current/dt.settings exist, restore to 'current' session
2063 strcpy(smGD.resourcePath, smGD.savePath);
2064 strcat(smGD.resourcePath, "/");
2065 strcat(smGD.resourcePath, SM_CURRENT_DIRECTORY);
2066 strcat(smGD.resourcePath, "/");
2067 strcat(smGD.resourcePath, SM_RESOURCE_FILE);
2068 strcpy(smGD.settingPath, smGD.savePath);
2069 strcat(smGD.settingPath, "/");
2070 strcat(smGD.settingPath, SM_CURRENT_DIRECTORY);
2071 strcat(smGD.settingPath, "/");
2072 strcat(smGD.settingPath, SM_SETTING_FILE);
2074 smGD.sessionType = CURRENT_SESSION;
2075 smGD.restoreSession = (char *) SM_CURRENT_DIRECTORY;
2082 strcpy(smGD.clientPath, smGD.savePath);
2083 strcat(smGD.clientPath, "/");
2084 strcat(smGD.clientPath, SM_HOME_DIRECTORY);
2085 strcat(smGD.clientPath, "/");
2086 strcpy(tmpPath, smGD.clientPath);
2087 strcat(smGD.clientPath, SM_CLIENT_FILE2);
2089 status = stat(smGD.clientPath, &buf);
2092 strcpy (smGD.clientPath, tmpPath);
2093 strcat (smGD.clientPath, SM_CLIENT_FILE);
2094 status = stat(smGD.clientPath, &buf);
2100 * sessions/home/dt.settings exist, restore to 'home' session
2102 strcpy(smGD.resourcePath, smGD.savePath);
2103 strcat(smGD.resourcePath, "/");
2104 strcat(smGD.resourcePath, SM_HOME_DIRECTORY);
2105 strcat(smGD.resourcePath, "/");
2106 strcat(smGD.resourcePath, SM_RESOURCE_FILE);
2107 strcpy(smGD.settingPath, smGD.savePath);
2108 strcat(smGD.settingPath, "/");
2109 strcat(smGD.settingPath, SM_HOME_DIRECTORY);
2110 strcat(smGD.settingPath, "/");
2111 strcat(smGD.settingPath, SM_SETTING_FILE);
2113 smGD.sessionType = HOME_SESSION;
2114 smGD.restoreSession = (char *) SM_HOME_DIRECTORY;
2125 /*************************************<->*************************************
2127 * InternSessionDir - intern the session dir property and put it
2128 * on the root window
2130 * NOTE: - also checks the validity of the -session command line
2135 * session_option - as given in the command line
2140 * smGD.restoreSession - initialized
2144 *************************************<->***********************************/
2147 char *session_option,
2152 if (!strcmp (session_option, SM_CURRENT_DIRECTORY)) {
2153 pch = DtSM_SESSION_DIRECTORY;
2154 smGD.restoreSession = SM_CURRENT_DIRECTORY;
2156 else if (!strcmp (session_option, SM_HOME_DIRECTORY)) {
2157 pch = DtSM_SESSION_DIRECTORY;
2158 smGD.restoreSession = SM_HOME_DIRECTORY;
2160 else if (!strcmp (session_option, SM_DISPLAY_HOME)) {
2161 pch = DtSM_SESSION_DISPLAY_DIRECTORY;
2162 smGD.restoreSession = SM_HOME_DIRECTORY;
2164 else if (!strcmp (session_option, SM_DISPLAY_CURRENT)) {
2165 pch = DtSM_SESSION_DISPLAY_DIRECTORY;
2166 smGD.restoreSession = SM_CURRENT_DIRECTORY;
2170 * The session_option is not supported
2174 XaSmRestoreDir = XInternAtom(disp, _XA_DT_RESTORE_DIR, False);
2176 XChangeProperty(disp, RootWindow(disp, 0),
2177 XaSmRestoreDir, XA_STRING, 8, PropModeReplace,
2178 (unsigned char *)pch, strlen(pch));
2187 /*************************************<->*************************************
2189 * InitializeSpecificSession - set the smGD paths based on the session
2190 * name given on the command line.
2194 * Initializes several variables in smGD
2208 *************************************<->***********************************/
2210 InitializeSpecificSession (
2211 char *session_option,
2216 char *session_dir = (char *) XtMalloc(MAXPATHLEN);
2217 char *alt_dir = (char *) XtMalloc(MAXPATHLEN);
2221 if (!InternSessionDir (session_option, disp))
2224 InitializePaths (smGD.restoreSession, disp);
2226 if (!strcmp (session_option, SM_HOME_DIRECTORY)) {
2230 if (smGD.clientPath[0] == '\0') {
2231 if ((stat (smGD.savePath, &buf)) != 0) {
2232 if ((mkdir (smGD.savePath, 0000)) == 0)
2233 (void) chmod (smGD.savePath, 0755);
2235 PrintErrnoError(DtError,
2236 smNLS.cantCreateDirsString);
2240 smGD.sessionType = HOME_SESSION;
2241 smGD.restoreSession = SM_HOME_DIRECTORY;
2243 else if (!strcmp (session_option, SM_CURRENT_DIRECTORY)) {
2247 if (smGD.clientPath[0] == '\0') {
2249 * Fallback to the generic home session
2251 (void) sprintf (session_dir, "%s/%s",
2252 smGD.savePath, SM_CURRENT_DIRECTORY);
2253 (void) sprintf (alt_dir, "%s/%s",
2254 smGD.savePath, SM_HOME_DIRECTORY);
2256 if (!SetAlternateSession (session_dir, alt_dir, True))
2259 smGD.sessionType = CURRENT_SESSION;
2260 smGD.restoreSession = SM_CURRENT_DIRECTORY;
2262 else if (!strcmp (session_option, SM_DISPLAY_HOME)) {
2264 * Display-specific Home session
2266 (void) sprintf (session_dir, "%s/%s",
2267 smGD.savePath, SM_HOME_DIRECTORY);
2269 if ((stat(session_dir, &buf)) != 0){
2271 * The session does not exist, give the user a
2274 if (!ConfirmSessionCreation (HOME_SESSION, argc, argv))
2279 if (smGD.clientPath[0] == '\0') {
2281 * Fallback to the generic home session
2285 if ((home = getenv ("HOME")) == 0)
2288 /* JET - VU#497553 */
2289 len = strlen(home) +
2290 strlen(DtPERSONAL_CONFIG_DIRECTORY) +
2291 strlen(DtSM_SESSION_DIRECTORY) +
2292 strlen(SM_HOME_DIRECTORY);
2294 if (len > MAXPATHLEN)
2295 alt_dir = XtRealloc(alt_dir, len + 1);
2297 (void) sprintf (alt_dir, "%s/%s/%s/%s",
2299 DtPERSONAL_CONFIG_DIRECTORY,
2300 DtSM_SESSION_DIRECTORY,
2302 if (!SetAlternateSession (session_dir, alt_dir, True))
2305 smGD.sessionType = HOME_SESSION;
2306 smGD.restoreSession = SM_HOME_DIRECTORY;
2308 else if (!strcmp (session_option, SM_DISPLAY_CURRENT)) {
2310 * Display-specific Current session
2312 (void) sprintf (session_dir, "%s/%s",
2313 smGD.savePath, SM_CURRENT_DIRECTORY);
2315 if ((stat(session_dir, &buf)) != 0){
2317 * The session does not exist, give the user a
2320 if (!ConfirmSessionCreation (CURRENT_SESSION, argc, argv))
2324 if (smGD.clientPath[0] == '\0') {
2326 * First, fallback to the display-specific home session
2330 (void) sprintf (alt_dir, "%s/%s",
2331 smGD.savePath, SM_HOME_DIRECTORY);
2333 if (!SetAlternateSession (session_dir, alt_dir, False)){
2335 * Try the generic home session
2337 if ((home = getenv ("HOME")) == 0)
2340 /* JET - VU#497553 */
2341 len = strlen(home) +
2342 strlen(DtPERSONAL_CONFIG_DIRECTORY) +
2343 strlen(DtSM_SESSION_DIRECTORY) +
2344 strlen(SM_HOME_DIRECTORY);
2346 if (len > MAXPATHLEN)
2347 alt_dir = XtRealloc(alt_dir, len + 1);
2349 (void) sprintf (alt_dir, "%s/%s/%s/%s",
2351 DtPERSONAL_CONFIG_DIRECTORY,
2352 DtSM_SESSION_DIRECTORY,
2355 if (!SetAlternateSession (session_dir,
2361 smGD.sessionType = CURRENT_SESSION;
2362 smGD.restoreSession = SM_CURRENT_DIRECTORY;
2365 if (session_dir) XtFree(session_dir);
2366 if (alt_dir) XtFree(alt_dir);
2370 if (session_dir) XtFree(session_dir);
2371 if (alt_dir) XtFree(alt_dir);
2376 /*************************************<->*************************************
2382 * Initializes the following variables:
2387 * smGD.clientPath - [0] = '\0' if the database files do not exist
2391 * session_name = "current" or "home"
2400 *************************************<->***********************************/
2403 char * session_name,
2406 char *db_file = (char *) XtMalloc(MAXPATHLEN);
2409 smGD.savePath = _DtCreateDtDirs(disp);
2411 (void) sprintf (smGD.settingPath, "%s/%s/%s",
2412 smGD.savePath, session_name, SM_SETTING_FILE);
2414 (void) sprintf (smGD.resourcePath, "%s/%s/%s",
2415 smGD.savePath, session_name, SM_RESOURCE_FILE);
2418 smGD.clientPath[0] = '\0';
2420 (void) sprintf (db_file, "%s/%s/%s",
2421 smGD.savePath, session_name, SM_CLIENT_FILE2);
2423 if ((stat(db_file, &buf)) == 0)
2424 (void) strcpy (smGD.clientPath, db_file);
2426 (void) sprintf (db_file, "%s/%s/%s",
2427 smGD.savePath, session_name, SM_CLIENT_FILE);
2428 if ((stat(db_file, &buf)) == 0)
2429 (void) strcpy (smGD.clientPath, db_file);
2431 if (db_file) XtFree(db_file);
2435 /*************************************<->*************************************
2437 * SetAlternateSession
2441 * Neither of the client databases in the session_dir directory
2446 * session_dir - the directory path for the session including home
2448 * alt_dir - the directory to use in the search for an alternate
2449 * or fallback session database
2450 * make_dir - if True, a session_dir will be created if it does not
2451 * exits; if False, session_dir will not be created
2457 *************************************<->***********************************/
2459 SetAlternateSession (
2464 char *tmp_dir = NULL;
2465 char *db_file1 = (char *) XtMalloc(MAXPATHLEN);
2466 char *db_file2 = (char *) XtMalloc(MAXPATHLEN);
2469 if ((stat (session_dir, &buf)) != 0) {
2471 * The requested dir does not exist, create it
2472 * by either copying the session from alt_dir (if
2473 * it exists and has a client database) or by
2477 (void) sprintf (db_file1, "%s/%s",
2478 alt_dir, SM_CLIENT_FILE2);
2479 (void) sprintf (db_file2, "%s/%s",
2480 alt_dir, SM_CLIENT_FILE);
2482 if ((stat(db_file1, &buf)) == 0)
2484 else if ((stat(db_file2, &buf)) == 0)
2487 if (!tmp_dir && !make_dir) {
2488 if (db_file1) XtFree(db_file1);
2489 if (db_file2) XtFree(db_file2);
2491 * This alt_dir doesn't have a session database
2492 * return now and try another directory
2499 * The alt_dir has a session database, create
2500 * a copy of its entire directory because all
2501 * of the sessions state is needed.
2505 tmp = XtMalloc (strlen (alt_dir) +
2506 strlen (session_dir) + 10);
2510 (void) sprintf (tmp, "cp -r %s %s",
2511 alt_dir, session_dir);
2513 if ((system (tmp)) == -1)
2517 if ((stat(session_dir, &buf)) != 0)
2519 * It should have been created by the cp
2524 * The session database needs to be updated.
2526 if (tmp_dir == db_file1)
2527 sprintf (smGD.clientPath, "%s/%s",
2528 session_dir, SM_CLIENT_FILE2);
2530 sprintf (smGD.clientPath, "%s/%s",
2531 session_dir, SM_CLIENT_FILE);
2534 * The alt_dir did not have a session database.
2535 * Create a directory and load the system defaults
2537 if ((mkdir (session_dir, 0000)) == 0)
2538 (void) chmod (session_dir, 0755);
2540 PrintErrnoError(DtError,
2541 smNLS.cantCreateDirsString);
2548 * The directory for the specified session exists
2549 * but it doesn't have any client databases. Start
2550 * a new user session. If a user wants a sesssion
2551 * with no apps, they should create a zero-length
2557 if (db_file1) XtFree(db_file1);
2558 if (db_file2) XtFree(db_file2);
2567 /* JET - needed to rework this to avoid exiting before we are
2570 if (smGD.ExitComplete)
2572 if (smXSMP.saveState.saveComplete &&
2573 smXSMP.saveState.shutdown &&
2574 !smXSMP.saveState.shutdownCanceled)
2583 SetSIGPIPEToDefault ()
2585 struct sigaction pipeSig;
2587 sigemptyset(&pipeSig.sa_mask);
2588 pipeSig.sa_flags = 0;
2589 pipeSig.sa_handler = SIG_DFL;
2590 (void) sigaction(SIGPIPE, &pipeSig, (struct sigaction *) NULL);