SmGlobals.c 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with these libraries and programs; if not, write
  20. * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
  21. * Floor, Boston, MA 02110-1301 USA
  22. */
  23. /* $TOG: SmGlobals.c /main/37 1998/10/26 17:21:18 mgreess $ */
  24. /*
  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.
  32. */
  33. /*************************************<+>*************************************
  34. *****************************************************************************
  35. **
  36. ** File: SmGlobals.c
  37. **
  38. ** Project: HP DT Session Manager (dtsession)
  39. **
  40. ** Description:
  41. ** -----------
  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.
  45. **
  46. **
  47. **
  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. ********************************************************************
  54. **
  55. **
  56. **
  57. *****************************************************************************
  58. *************************************<+>*************************************/
  59. #include <stdio.h>
  60. #include <errno.h>
  61. #include <string.h>
  62. #include <ctype.h>
  63. #include <sys/wait.h>
  64. #include <sys/types.h>
  65. #include <sys/utsname.h>
  66. #include <unistd.h>
  67. #include <sys/stat.h>
  68. #include <sys/param.h>
  69. #include <X11/Intrinsic.h>
  70. #include <X11/Xutil.h>
  71. #include <X11/StringDefs.h>
  72. #include <Xm/Xm.h>
  73. #include <Dt/DtP.h>
  74. #include <Dt/SessionP.h>
  75. #include <Dt/Wsm.h>
  76. #include <Dt/WsmP.h>
  77. #include <Dt/UserMsg.h>
  78. #include <Dt/HourGlass.h>
  79. #include <Dt/SessionM.h>
  80. #include <Dt/EnvControlP.h>
  81. #include <Dt/Qualify.h>
  82. #include <Dt/MsgLog.h>
  83. #include "Sm.h"
  84. #include "SmResource.h"
  85. #include "SmError.h"
  86. #include "SmUI.h"
  87. #include "SmGlobals.h"
  88. #include "SmLock.h"
  89. #include "SmRestore.h"
  90. #include "SmProtocol.h"
  91. #include "SmXSMP.h"
  92. /*
  93. * Internal Variable Declaraions
  94. */
  95. static char savedDir [MAXPATHLEN];
  96. static char savedOldDir [MAXPATHLEN];
  97. static char savedTmpDir [MAXPATHLEN];
  98. /*
  99. * Internal Function Declaraions
  100. */
  101. static int SetSysDefaults( void ) ;
  102. static int SetResSet( void ) ;
  103. static void RemoveFiles( char *) ;
  104. static void TrimErrorlog(void);
  105. static void _SmWaitClientTimeoutDefault (
  106. Widget widget,
  107. int offset,
  108. XrmValue *value);
  109. static void _SmWaitWmTimeoutDefault (
  110. Widget widget,
  111. int offset,
  112. XrmValue *value);
  113. void SmCvtStringToContManagement (
  114. XrmValue *args,
  115. Cardinal numArgs,
  116. XrmValue *fromVal,
  117. XrmValue *toVal);
  118. unsigned char *_DtNextToken (
  119. unsigned char *pchIn,
  120. int *pLen,
  121. unsigned char **ppchNext);
  122. Boolean _DtWmStringsAreEqual (
  123. unsigned char *pch1,
  124. unsigned char *pch2,
  125. int len);
  126. static Boolean InitializeSpecificSession (
  127. char *session_name,
  128. Display *disp,
  129. unsigned int argc,
  130. char **argv);
  131. static void InitializeGenericSession (
  132. Display *disp);
  133. static void InitializePaths (
  134. char *session_option,
  135. Display *disp);
  136. static Boolean SetAlternateSession (
  137. char * session_dir,
  138. char * alt_dir,
  139. Boolean make_dir);
  140. /*
  141. * Global Data
  142. */
  143. /*
  144. * These are the global structures used throughout dtsession
  145. * They are defined in Sm.h
  146. */
  147. SessionResources smRes;
  148. SaverResources smSaverRes;
  149. SettingsSet smToSet;
  150. SettingsCust smCust;
  151. SessionSettings smSettings;
  152. GeneralData smGD;
  153. char SM_SCREEN_SAVER_LOC [MAXPATHLEN + 1];
  154. /*
  155. * Internal Global Data
  156. */
  157. static char tmpDisplayName[MAXPATHLEN + 1];
  158. int machineType = 0;
  159. static XtResource sessionResources[]=
  160. {
  161. {SmNwmStartup, SmCwmStartup, XtRString, sizeof(String),
  162. XtOffset(SessionResourcesPtr, wmStartup),
  163. XtRImmediate, (XtPointer) NULL},
  164. {SmNquerySettings, SmCquerySettings, XtRBoolean, sizeof(Boolean),
  165. XtOffset(SessionResourcesPtr, querySettings),
  166. XtRImmediate, (XtPointer) False},
  167. {SmNkeys, SmCkeys, XtRString, sizeof(String),
  168. XtOffset(SessionResourcesPtr, keyholders), XtRString, NULL},
  169. {SmNalarmTime, SmCalarmTime, XtRInt, sizeof(int),
  170. XtOffset(SessionResourcesPtr, alarmTime),
  171. XtRImmediate, (XtPointer) 10},
  172. {SmNmemThreshold, SmCmemThreshold, XtRInt, sizeof(int),
  173. XtOffset(SessionResourcesPtr, memThreshold),
  174. XtRImmediate, (XtPointer) 100},
  175. {SmNsessionVersion, SmCsessionVersion, XtRString, sizeof(String),
  176. XtOffset(SessionResourcesPtr, sessionVersion),
  177. XtRImmediate, (XtPointer) NULL},
  178. {SmNdisplayResolution, SmCdisplayResolution, XtRInt, sizeof(int),
  179. XtOffset(SessionResourcesPtr, displayResolution),
  180. XtRImmediate, (XtPointer) 0},
  181. {SmNsessionLang, SmCsessionLang, XtRString, sizeof(String),
  182. XtOffset(SessionResourcesPtr, sessionLang),
  183. XtRImmediate, (XtPointer) ""},
  184. {SmNcontManagement, SmCContManagement, SmRContManagement, sizeof(long),
  185. XtOffset(SessionResourcesPtr, contManagement),
  186. XtRImmediate, (XtPointer) (SM_CM_DEFAULT)},
  187. {SmNwaitClientTimeout, SmCWaitClientTimeout, XtRInt, sizeof(int),
  188. XtOffset(SessionResourcesPtr, waitClientTimeout),
  189. XtRCallProc, (XtPointer)_SmWaitClientTimeoutDefault },
  190. {SmNwaitWmTimeout, SmCWaitWmTimeout, XtRInt, sizeof(int),
  191. XtOffset(SessionResourcesPtr, waitWmTimeout),
  192. XtRCallProc, (XtPointer)_SmWaitWmTimeoutDefault },
  193. {SmNuseMessaging, SmCUseMessaging, XtRBoolean, sizeof(Boolean),
  194. XtOffset(SessionResourcesPtr, useBMS),
  195. XtRImmediate, (XtPointer) True},
  196. {SmNsaveFontPath, SmCsaveFontPath, XtRBoolean, sizeof(Boolean),
  197. XtOffset(SessionResourcesPtr, saveFontPath),
  198. XtRImmediate, (XtPointer) False},
  199. {SmNsaveYourselfTimeout, SmCsaveYourselfTimeout, XtRInt, sizeof(int),
  200. XtOffset(SessionResourcesPtr, saveYourselfTimeout),
  201. XtRImmediate, (XtPointer) 5},
  202. {SmNnumSessionsBackedup, SmCnumSessionsBackedup, XtRInt, sizeof(int),
  203. XtOffset(SessionResourcesPtr, numSessionsBackedup),
  204. XtRImmediate, (XtPointer) DEFAULT_NUM_SESSIONS_BACKED_UP},
  205. {SmNignoreEnvironment, SmCignoreEnvironment, XtRString, sizeof(String),
  206. XtOffset(SessionResourcesPtr, ignoreEnvironment),
  207. XtRImmediate, (XtPointer) NULL},
  208. #if defined(USE_XINERAMA) /* JET - Xinerama */
  209. {SmNxineramaPreferredScreen, SmCxineramaPreferredScreen, XtRInt, sizeof(int),
  210. XtOffset(SessionResourcesPtr, xineramaPreferredScreen),
  211. XtRImmediate, (XtPointer) 0},
  212. #endif
  213. }
  214. ;
  215. static XtResource saverResources[]=
  216. {
  217. {SmNcycleTimeout, SmCcycleTimeout, XtRInt, sizeof(int),
  218. XtOffset(SaverResourcesPtr, cycleTimeout),
  219. XtRImmediate, (XtPointer) -1},
  220. {SmNlockTimeout, SmClockTimeout, XtRInt, sizeof(int),
  221. XtOffset(SaverResourcesPtr, lockTimeout),
  222. XtRImmediate, (XtPointer) -1},
  223. {SmNsaverTimeout, SmCsaverTimeout, XtRInt, sizeof(int),
  224. XtOffset(SaverResourcesPtr, saverTimeout),
  225. XtRImmediate, (XtPointer) -1},
  226. {SmNrandom, SmCrandom, XtRBoolean, sizeof(Boolean),
  227. XtOffset(SaverResourcesPtr, random),
  228. XtRImmediate, (XtPointer) False},
  229. {SmNsaverList, SmCsaverList, XtRString, sizeof(String),
  230. XtOffset(SaverResourcesPtr, saverList),
  231. XtRImmediate, (XtPointer) ""},
  232. }
  233. ;
  234. /*
  235. * Machine specific defaults.
  236. */
  237. static struct
  238. {
  239. int machineType;
  240. int clientTimeout;
  241. int wmTimeout;
  242. }
  243. machineDefault[] =
  244. {
  245. { 0, 20, 60}, /* Machine independent default */
  246. #ifdef __hpux
  247. {300, 10, 60}, /* HP s300 */
  248. {400, 10, 60}, /* HP s400 */
  249. {600, 5, 60}, /* HP s600 */
  250. {700, 5, 60}, /* HP s700 */
  251. {800, 5, 60}, /* HP s800 */
  252. #endif /* __hpux */
  253. };
  254. #define MACHINEDEFAULTS (sizeof(machineDefault) / sizeof(machineDefault[0]))
  255. /*************************************<->*************************************
  256. *
  257. * _SmWaitClientTimeoutDefault (widget, offset, value)
  258. *
  259. *
  260. * Description:
  261. * -----------
  262. * This function generates a default value for the waitClientTimeout resource.
  263. * We dynamically default to 10 seconds for s400/s300 and to
  264. * 5 seconds for s700/s800.
  265. *
  266. * Inputs:
  267. * ------
  268. * widget = this is not used
  269. *
  270. * offset = this is the resource offset
  271. *
  272. * value = this is a pointer to a XrmValue in which to store the result
  273. *
  274. * Outputs:
  275. * -------
  276. * value = default resource value and size
  277. *
  278. *************************************<->***********************************/
  279. static
  280. void
  281. _SmWaitClientTimeoutDefault (Widget widget, int offset, XrmValue *value)
  282. {
  283. int i;
  284. for (i = 0; i < MACHINEDEFAULTS; i++)
  285. {
  286. if (machineDefault[i].machineType == machineType)
  287. {
  288. break;
  289. }
  290. }
  291. if (i == MACHINEDEFAULTS)
  292. {
  293. i = 0;
  294. }
  295. value->addr = (char *)&machineDefault[i].clientTimeout;
  296. value->size = sizeof (int);
  297. } /* END OF FUNCTION _SmWaitClientTimeoutDefault */
  298. /*************************************<->*************************************
  299. *
  300. * _SmWaitWmTimeoutDefault (widget, offset, value)
  301. *
  302. *
  303. * Description:
  304. * -----------
  305. * This function generates a default value for the waitWmTimeout resource.
  306. * We dynamically default to 60 seconds for s400/s300 and to
  307. * 60 seconds for s700/s800. This could change if we get feedback indicating
  308. * the need for a new default.
  309. *
  310. * Inputs:
  311. * ------
  312. * widget = this is not used
  313. *
  314. * offset = this is the resource offset
  315. *
  316. * value = this is a pointer to a XrmValue in which to store the result
  317. *
  318. * Outputs:
  319. * -------
  320. * value = default resource value and size
  321. *
  322. *************************************<->***********************************/
  323. static
  324. void
  325. _SmWaitWmTimeoutDefault (Widget widget, int offset, XrmValue *value)
  326. {
  327. int i;
  328. smGD.userSetWaitWmTimeout = False; /* if we are here, it is not user set */
  329. for (i = 0; i < MACHINEDEFAULTS; i++)
  330. {
  331. if (machineDefault[i].machineType == machineType)
  332. {
  333. break;
  334. }
  335. }
  336. if (i == MACHINEDEFAULTS)
  337. {
  338. i = 0;
  339. }
  340. value->addr = (char *)&machineDefault[i].wmTimeout;
  341. value->size = sizeof (int);
  342. } /* END OF FUNCTION _SmWaitWmTimeoutDefault */
  343. /*************************************<->*************************************
  344. *
  345. * InitSMGlobals ()
  346. *
  347. *
  348. * Description:
  349. * -----------
  350. * Sets SM global resources and global settings to a starting value.
  351. *
  352. *
  353. * Inputs:
  354. * ------
  355. * buttonForm = form widget for button that allows cursor to get colors
  356. * smRes(global) = structure that holds session resources.
  357. * smToSet(global) = structure that holds "which settings to set and how" info
  358. * smGD(global) = structure that holds general data info
  359. *
  360. * Outputs:
  361. * -------
  362. * smRes(global) = structure that holds session resources.
  363. * smToSet(global) = structure that holds "which settings to set and how" info
  364. * smGD(global) = structure that holds general data info
  365. *
  366. * Comments:
  367. * --------
  368. * Resources are set to an initial value by the resource manager. The
  369. * rest are set in the routine.
  370. *
  371. *************************************<->***********************************/
  372. void
  373. InitSMGlobals( void )
  374. {
  375. int i;
  376. PropDtSmWindowInfo property;
  377. struct utsname nameRec;
  378. char *firstSlash;
  379. char *keyNum;
  380. smGD.userSetWaitWmTimeout = True; /* assume it is */
  381. #ifdef __hpux
  382. if (uname(&nameRec) == 0)
  383. {
  384. keyNum = nameRec.machine;
  385. if (firstSlash = strchr(keyNum, '/'))
  386. {
  387. keyNum = ++firstSlash;
  388. if ( keyNum[0] == '3')
  389. {
  390. machineType = 300;
  391. }
  392. else if (keyNum[0] == '4')
  393. {
  394. machineType = 400;
  395. }
  396. else if (keyNum[0] == '6')
  397. {
  398. machineType = 600;
  399. }
  400. else if (keyNum[0] == '7')
  401. {
  402. machineType = 700;
  403. }
  404. else if (keyNum[0] == '8')
  405. {
  406. machineType = 800;
  407. }
  408. }
  409. }
  410. #endif /* __hpux */
  411. /*
  412. * Get application specific resource values
  413. */
  414. XtAppAddConverter (smGD.appCon, XtRString, SmRContManagement,
  415. (XtConverter)SmCvtStringToContManagement, NULL, 0);
  416. XtGetApplicationResources(smGD.topLevelWid, (XtPointer) &smRes,
  417. sessionResources,
  418. XtNumber(sessionResources), NULL, 0);
  419. if (smGD.lockOnTimeoutStatus == True)
  420. {
  421. /*
  422. * Pull screen saver resources from Dtsession*extension.<name>.
  423. */
  424. smGD.SmNextension = "extension";
  425. smGD.SmCextension = "Extension";
  426. smGD.extensionSpec = "extension.";
  427. }
  428. else
  429. {
  430. /*
  431. * Pull screen saver resources from Dtsession*<name>.
  432. */
  433. smGD.SmNextension = smGD.SmCextension = smGD.extensionSpec = "";
  434. }
  435. XtGetSubresources(smGD.topLevelWid, (XtPointer) &smSaverRes,
  436. smGD.SmNextension, smGD.SmCextension,
  437. saverResources,
  438. XtNumber(saverResources), NULL, 0);
  439. smGD.wmStartup = SmNewString(smRes.wmStartup);
  440. smGD.keyholders = SmNewString(smRes.keyholders);
  441. smGD.sessionLang = SmNewString(smRes.sessionLang);
  442. smGD.saverList = SmNewString(smSaverRes.saverList);
  443. /*
  444. * Initialize general data used by apps not initialized by
  445. * XtInitialize or DtInitialize
  446. */
  447. smGD.topLevelWindow = XtWindow(smGD.topLevelWid);
  448. smGD.numSavedScreens = (ScreenCount(smGD.display) > MAX_SCREENS_SAVED)
  449. ? MAX_SCREENS_SAVED : ScreenCount(smGD.display);
  450. smGD.dtwmRunning = False;
  451. smSettings.confirmMode = DtSM_VERBOSE_MODE;
  452. if (smGD.sessionType == CURRENT_SESSION ||
  453. smGD.sessionType == DEFAULT_SESSION)
  454. smSettings.startState = DtSM_CURRENT_STATE;
  455. else
  456. smSettings.startState = DtSM_HOME_STATE;
  457. smGD.homeSave = False;
  458. smGD.saverListParse = NULL;
  459. smGD.loggingOut = False;
  460. /*
  461. * Sanity check on timeouts for negative numbers
  462. */
  463. if (smRes.waitClientTimeout < 0)
  464. {
  465. smRes.waitClientTimeout = -smRes.waitClientTimeout;
  466. }
  467. if (smRes.waitWmTimeout < 0)
  468. {
  469. smRes.waitWmTimeout = -smRes.waitWmTimeout;
  470. }
  471. if (smRes.saveYourselfTimeout < 0)
  472. {
  473. smRes.saveYourselfTimeout = -smRes.saveYourselfTimeout;
  474. }
  475. /*
  476. * Now convert users view of seconds in to XtAppAddTimout's
  477. * need for milliseconds.
  478. */
  479. smRes.waitClientTimeout = 1000 * smRes.waitClientTimeout;
  480. smRes.waitWmTimeout = 1000 * smRes.waitWmTimeout;
  481. smRes.saveYourselfTimeout = 1000 * smRes.saveYourselfTimeout;
  482. smGD.savedWaitWmTimeout = smRes.waitWmTimeout;
  483. /*
  484. * Initialize lock data
  485. */
  486. smGD.screen = XDefaultScreen(smGD.display);
  487. smGD.blackPixel = XBlackPixel(smGD.display, smGD.screen);
  488. smGD.whitePixel = XWhitePixel(smGD.display, smGD.screen);
  489. smDD.lockDialog = NULL;
  490. smDD.lockCoverDialog = NULL;
  491. for(i = 0;i < smGD.numSavedScreens;i++)
  492. {
  493. smDD.coverDialog[i] = NULL;
  494. smDD.coverDrawing[i] = NULL;
  495. }
  496. smGD.lockedState = UNLOCKED;
  497. /*
  498. * Sanity check screen saver resource values.
  499. */
  500. if (smRes.alarmTime < 0) smRes.alarmTime = 0;
  501. #define SMBOUND(A) (A < 0 ? 0 : A)
  502. smSaverRes.lockTimeout = SMBOUND(smSaverRes.lockTimeout) * 60;
  503. smSaverRes.saverTimeout = SMBOUND(smSaverRes.saverTimeout) * 60;
  504. smSaverRes.cycleTimeout = SMBOUND(smSaverRes.cycleTimeout) * 60;
  505. CreateLockCursor();
  506. smGD.waitCursor = _DtGetHourGlassCursor(smGD.display);
  507. /*
  508. * Initialize other global data related to dialogs
  509. */
  510. smDD.confExit = NULL;
  511. smDD.qExit = NULL;
  512. smDD.compatExit = NULL;
  513. smDD.deadWid = NULL;
  514. smDD.saveSession = NULL; /* Error dialog for Save_Session */
  515. if (!smDD.smHelpDialog)
  516. /*
  517. * Don't wipe it out if it is already created
  518. */
  519. smDD.smHelpDialog = NULL;
  520. /*
  521. * Intern all the atoms needed for the WSM communication
  522. */
  523. {
  524. enum { XA_DT_SM_WINDOW_INFO, XA_DT_SM_WM_PROTOCOL,
  525. XA_DT_SM_START_ACK_WINDOWS, XA_DT_SM_STOP_ACK_WINDOWS,
  526. XA_DT_WM_WINDOW_ACK, XA_DT_WM_EXIT_SESSION,
  527. XA_DT_WM_LOCK_DISPLAY, XA_DT_WM_READY, NUM_ATOMS };
  528. static char *atom_names[] = {
  529. _XA_DT_SM_WINDOW_INFO, _XA_DT_SM_WM_PROTOCOL,
  530. _XA_DT_SM_START_ACK_WINDOWS, _XA_DT_SM_STOP_ACK_WINDOWS,
  531. _XA_DT_WM_WINDOW_ACK, _XA_DT_WM_EXIT_SESSION,
  532. _XA_DT_WM_LOCK_DISPLAY, _XA_DT_WM_READY };
  533. Atom atoms[XtNumber(atom_names)];
  534. XInternAtoms(smGD.display, atom_names, XtNumber(atom_names),
  535. False, atoms);
  536. XaVsmInfo = atoms[XA_DT_SM_WINDOW_INFO];
  537. XaSmWmProtocol = atoms[XA_DT_SM_WM_PROTOCOL];
  538. XaSmStartAckWindow = atoms[XA_DT_SM_START_ACK_WINDOWS];
  539. XaSmStopAckWindow = atoms[XA_DT_SM_STOP_ACK_WINDOWS];
  540. XaWmWindowAck = atoms[XA_DT_WM_WINDOW_ACK];
  541. XaWmExitSession = atoms[XA_DT_WM_EXIT_SESSION];
  542. XaWmLockDisplay = atoms[XA_DT_WM_LOCK_DISPLAY];
  543. XaWmReady = atoms[XA_DT_WM_READY];
  544. }
  545. /*
  546. * Set the session manager window property on the root window
  547. */
  548. property.flags = 0;
  549. property.smWindow = (unsigned long) smGD.topLevelWindow;
  550. XChangeProperty (smGD.display, RootWindow(smGD.display, 0),
  551. XaVsmInfo, XaVsmInfo,
  552. 32, PropModeReplace, (unsigned char *)&property,
  553. PROP_DT_SM_WINDOW_INFO_ELEMENTS);
  554. /*
  555. * Set up the signal handler for forking and execing
  556. */
  557. sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
  558. }
  559. /*************************************<->*************************************
  560. *
  561. * SetRestorePath ()
  562. *
  563. *
  564. * Description:
  565. * -----------
  566. * Sets SM global resources and global settings to a starting value.
  567. *
  568. *
  569. * Inputs:
  570. * ------
  571. * smGD.display = display structure for session manager. Used to construct
  572. * a display directory
  573. *
  574. * Outputs:
  575. * -------
  576. * smGD.resourcePath(global) = Path where the resources to be restored are
  577. * held
  578. * smGD.settingPath(global) = Path where the settings to be restored are
  579. * held
  580. * smGD.clientPath(global) = Path where the clients to be restored are
  581. * held
  582. * smGD.savePath(global) = Path where all save files are to be saved
  583. *
  584. * Return:
  585. * ------
  586. * Display connection
  587. *
  588. * Comments:
  589. * --------
  590. * WARNING: This routine also determines whether dtsession is being started
  591. * in compatibility mode. If so - no restore paths are set up and
  592. * the routine is exited.
  593. *
  594. *************************************<->***********************************/
  595. int
  596. SetRestorePath(
  597. unsigned int argc,
  598. char *argv[] )
  599. {
  600. Display *tmpDisplay;
  601. int i;
  602. char *displayName = NULL;
  603. char *session_option = NULL;
  604. smGD.compatMode = False;
  605. for(i = 0;i < argc;i++)
  606. {
  607. if(!strcmp(argv[i], "-display"))
  608. {
  609. displayName = argv[i + 1];
  610. /*
  611. * If -display is used but DISPLAY is not set,
  612. * put DISPLAY into the environment
  613. */
  614. if (getenv("DISPLAY") == 0)
  615. {
  616. snprintf(tmpDisplayName, MAXPATHLEN, "DISPLAY=%s", displayName);
  617. putenv(tmpDisplayName);
  618. }
  619. }
  620. if(!strcmp(argv[i], "-norestore"))
  621. {
  622. smGD.compatMode = True;
  623. }
  624. if(!strcmp(argv[i], "-session"))
  625. {
  626. i++;
  627. if (i >= argc)
  628. {
  629. char *pch;
  630. pch = strdup ((char *) GETMESSAGE (40, 15,
  631. " No session name was provided for the -session command line option."));
  632. if (pch)
  633. {
  634. DtMsgLogMessage (argv[0], DtMsgLogWarning, pch);
  635. free (pch);
  636. }
  637. break;
  638. }
  639. session_option = argv[i];
  640. }
  641. }
  642. /*
  643. * If we are in compatibility mode - no restore paths are set
  644. * up and we just return
  645. */
  646. if(smGD.compatMode == True)
  647. {
  648. smGD.clientPath[0] = 0;
  649. smGD.resourcePath[0] = 0;
  650. smGD.settingPath[0] = 0;
  651. smGD.sessionType = DEFAULT_SESSION;
  652. smGD.restoreSession = NULL;
  653. return(0);
  654. }
  655. tmpDisplay = XOpenDisplay(displayName);
  656. if(tmpDisplay == NULL)
  657. {
  658. PrintError(DtError, GETMESSAGE(4, 1, "Invalid display name - exiting."));
  659. SM_EXIT(-1);
  660. }
  661. if (session_option)
  662. {
  663. if (!InitializeSpecificSession (session_option, tmpDisplay, argc, argv))
  664. InitializeGenericSession (tmpDisplay);
  665. }
  666. else
  667. InitializeGenericSession (tmpDisplay);
  668. /*
  669. * Need to know if the session is for a specific display
  670. */
  671. smGD.displaySpecific = True;
  672. if (session_option = strrchr (smGD.savePath, '/'))
  673. {
  674. session_option++;
  675. if (!strcmp (session_option, DtSM_SESSION_DIRECTORY))
  676. smGD.displaySpecific = False;
  677. }
  678. TrimErrorlog();
  679. XCloseDisplay(tmpDisplay);
  680. /*
  681. ** User's session startup script:
  682. ** $HOME/.dt/sessions/sessionetc
  683. */
  684. strcpy(smGD.etcPath, smGD.savePath);
  685. strcat(smGD.etcPath, "/");
  686. strcat(smGD.etcPath, smEtcFile);
  687. /*
  688. ** User's session shutdown script:
  689. ** $HOME/.dt/sessions/sessionexit
  690. */
  691. strcpy(smGD.exitPath, smGD.savePath);
  692. strcat(smGD.exitPath, "/");
  693. strcat(smGD.exitPath, smExitFile);
  694. return(0);
  695. }
  696. void
  697. FixPath
  698. (
  699. char * the1stPath
  700. )
  701. {
  702. char * tempPath;
  703. char * pathList = (char *)XtMalloc(strlen(SM_SYSTEM_PATH) +
  704. strlen(":" CDE_INSTALLATION_TOP "/config") + 1);
  705. strcpy(pathList,SM_SYSTEM_PATH);
  706. strcat(pathList,":" CDE_INSTALLATION_TOP "/config");
  707. tempPath = _DtQualifyWithFirst(the1stPath,pathList);
  708. if (tempPath != NULL) {
  709. strcpy(the1stPath,tempPath);
  710. free(tempPath);
  711. }
  712. XtFree(pathList);
  713. }
  714. /*************************************<->*************************************
  715. *
  716. * SetSysDefaults ()
  717. *
  718. *
  719. * Description:
  720. * -----------
  721. * Sets the path to restore the system default files. A convenience routine
  722. *
  723. *
  724. * Inputs:
  725. * ------
  726. * smGD.savePath = path that files are to be saved in (set up in
  727. * SetRestorePaths)
  728. *
  729. * Outputs:
  730. * -------
  731. * smGD.resourcePath(global) = Path where the resources to be saved are
  732. * to be saved.
  733. * smGD.settingPath(global) = Path where the settings to be saved are
  734. * to be saved.
  735. * smGD.clientPath(global) = Path where the clients to be saved are
  736. * to be saved.
  737. *
  738. * Comments:
  739. * --------
  740. *
  741. *************************************<->***********************************/
  742. static int
  743. SetSysDefaults( void )
  744. {
  745. int status;
  746. struct stat buf;
  747. String tmpString;
  748. char *langSpec;
  749. char *tempPath;
  750. /*
  751. * No files exist for restoration - use the
  752. * system defaults
  753. */
  754. strcpy(smGD.resourcePath, "");
  755. strcpy(smGD.clientPath, "");
  756. smGD.settingPath[0] = 0;
  757. smGD.sessionType = DEFAULT_SESSION;
  758. smGD.restoreSession = (char *) SM_SYSTEM_DIRECTORY;
  759. langSpec = getenv("LANG");
  760. if ((langSpec != NULL) && (*langSpec != 0))
  761. {
  762. strcat(smGD.clientPath, "/");
  763. strncat(smGD.clientPath, langSpec, MAXPATHLEN-2);
  764. smGD.clientPath[MAXPATHLEN-1] = 0;
  765. }
  766. strcat(smGD.clientPath, "/");
  767. strcat(smGD.clientPath, SM_SYSTEM_CLIENT_FILE);
  768. FixPath(smGD.clientPath);
  769. /*
  770. * If the system files don't exist - we're in
  771. * trouble - First try LANG location then default
  772. */
  773. status = stat(smGD.clientPath, &buf);
  774. if(status == -1)
  775. {
  776. if((langSpec == NULL) || (*langSpec == 0))
  777. {
  778. PrintErrnoError(DtError, GETMESSAGE(4, 2,
  779. "No defaults files exist. "
  780. "No applications will be restarted."));
  781. smGD.clientPath[0] = 0;
  782. smGD.resourcePath[0] = 0;
  783. }
  784. else
  785. {
  786. strcpy(smGD.clientPath, "/C/");
  787. strcat(smGD.clientPath, SM_SYSTEM_CLIENT_FILE);
  788. FixPath(smGD.clientPath);
  789. status = stat(smGD.clientPath, &buf);
  790. if(status == -1)
  791. {
  792. PrintErrnoError(DtError, GETMESSAGE(4, 3,
  793. "No defaults files exist. "
  794. "No applications will be restarted."));
  795. smGD.clientPath[0] = 0;
  796. smGD.resourcePath[0] = 0;
  797. }
  798. }
  799. }
  800. return(0);
  801. }
  802. /*************************************<->*************************************
  803. *
  804. * SetResSet ()
  805. *
  806. *
  807. * Description:
  808. * -----------
  809. * Sets the path to restore the settings and resource files.
  810. * A convenience routine
  811. *
  812. *
  813. * Inputs:
  814. * ------
  815. * smGD.savePath = path that files are to be saved in (set up in
  816. * SetRestorePaths)
  817. *
  818. * Outputs:
  819. * -------
  820. * smGD.resourcePath(global) = Path where the resources to be saved are
  821. * to be saved.
  822. * smGD.settingPath(global) = Path where the settings to be saved are
  823. * to be saved.
  824. * smGD.clientPath(global) = Path where the clients to be saved are
  825. * to be saved.
  826. *
  827. * Comments:
  828. * --------
  829. *
  830. *************************************<->***********************************/
  831. static int
  832. SetResSet( void )
  833. {
  834. int status;
  835. struct stat buf;
  836. /*
  837. * If resource or settings file does not exist - just null out
  838. * the path so these things will not get restored
  839. */
  840. status = stat(smGD.resourcePath, &buf);
  841. if(status == -1)
  842. {
  843. smGD.resourcePath[0] = 0;
  844. }
  845. status = stat(smGD.settingPath, &buf);
  846. if(status == -1)
  847. {
  848. smGD.settingPath[0] = 0;
  849. }
  850. return(0);
  851. }
  852. /*************************************<->*************************************
  853. *
  854. * UndoSetSavePath () - Undoes the directory manipulations done by
  855. * SetSavePath. This function is only called if a shutdown/save
  856. * is canceled.
  857. *
  858. *************************************<->***********************************/
  859. void
  860. UndoSetSavePath (void)
  861. {
  862. char * buf;
  863. if (strcmp ("", savedDir)) {
  864. /*
  865. * Remove the directory where the save occurred, e.g.:
  866. *
  867. * ~/.dt/<session_dir>/current
  868. * ~/.dt/<session_dir>/home
  869. */
  870. buf = XtMalloc (strlen (savedDir) + 9);
  871. sprintf (buf, "rm -rf %s", savedDir);
  872. SystemCmd (buf);
  873. XtFree (buf);
  874. if (strcmp ("", savedOldDir)) {
  875. MoveDirectory (savedOldDir, savedDir, False);
  876. if (strcmp ("", savedTmpDir)) {
  877. MoveDirectory (savedTmpDir, savedOldDir, False);
  878. }
  879. }
  880. }
  881. }
  882. /*************************************<->*************************************
  883. *
  884. * SetSavePath (saveToHome, mode)
  885. *
  886. *
  887. * Description:
  888. * -----------
  889. * Sets up paths for files that need to be saved. Also removes any files
  890. * that shouldn't be there after the save.
  891. *
  892. *
  893. * Inputs:
  894. * ------
  895. * smGD.display = display structure for session manager. Used to construct
  896. * a display directory
  897. * saveToHome = whether this is a save to home session or not
  898. * mode = whether we are resetting or restarting
  899. *
  900. * Outputs:
  901. * -------
  902. * smGD.resourcePath(global) = Path where the resources to be saved are
  903. * to be saved.
  904. * smGD.settingPath(global) = Path where the settings to be saved are
  905. * to be saved.
  906. * smGD.clientPath(global) = Path where the clients to be saved are
  907. * to be saved.
  908. *
  909. * Comments:
  910. * --------
  911. *
  912. *************************************<->***********************************/
  913. int
  914. SetSavePath(
  915. Boolean saveToHome,
  916. int mode )
  917. {
  918. struct stat buf;
  919. int status;
  920. /*
  921. * These directory paths are needed in UndoSetSavePaths
  922. * if a shutdown/save is canceled.
  923. */
  924. strcpy (savedDir, "");
  925. strcpy (savedOldDir, "");
  926. strcpy (savedTmpDir, "");
  927. /*
  928. * Make sure the user hasn't done something like delete the .dt
  929. * directories during the session. If so - recreate them
  930. */
  931. SM_FREE(smGD.savePath);
  932. smGD.savePath = _DtCreateDtDirs(smGD.display);
  933. if(smGD.savePath == NULL)
  934. {
  935. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  936. smGD.clientPath[0] = 0;
  937. smGD.settingPath[0] = 0;
  938. smGD.resourcePath[0] = 0;
  939. return(-1);
  940. }
  941. /*
  942. * Path for a save defaults to save the current session.
  943. * Otherwise just remove the directories
  944. */
  945. strcpy(smGD.clientPath, smGD.savePath);
  946. strcpy(smGD.settingPath, smGD.savePath);
  947. strcpy(smGD.resourcePath, smGD.savePath);
  948. strcat(smGD.clientPath, "/");
  949. strcat(smGD.settingPath, "/");
  950. strcat(smGD.resourcePath, "/");
  951. if(saveToHome == False)
  952. {
  953. strcat(smGD.clientPath, SM_CURRENT_DIRECTORY);
  954. strcat(smGD.resourcePath, SM_CURRENT_DIRECTORY);
  955. strcat(smGD.settingPath, SM_CURRENT_DIRECTORY);
  956. smGD.restoreSession = SM_CURRENT_DIRECTORY;
  957. }
  958. else
  959. {
  960. strcat(smGD.clientPath, SM_HOME_DIRECTORY);
  961. strcat(smGD.resourcePath, SM_HOME_DIRECTORY);
  962. strcat(smGD.settingPath, SM_HOME_DIRECTORY);
  963. smGD.restoreSession = SM_HOME_DIRECTORY;
  964. }
  965. if ((mode == DtSM_HOME_STATE) && (saveToHome == False) &&
  966. (smSettings.startState == DtSM_HOME_STATE))
  967. {
  968. /*
  969. * The only time this should should be true is if the
  970. * current session is a Home session and the session
  971. * is being exited. The idea is that if a "current"
  972. * directory exits, it must be moved because when the
  973. * user next logs in, a Home session should be started
  974. * (if a session is not selected at the login screen)
  975. * and the Session Manager decides whether or not it
  976. * starts a Home or Current session based on if a
  977. * "current" directory exists. If a "current" directory
  978. * exists, a Current session will be started.
  979. */
  980. status = stat(smGD.clientPath, &buf);
  981. if(status != -1)
  982. {
  983. /*
  984. * The "current" directory exists and must be moved to its
  985. * ".old" version. But first, if the ".old" version exists,
  986. * it must be moved to a temporary directory. This temporary
  987. * directory will eventually be pruned - when a user next
  988. * runs a Current session and saves the session.
  989. */
  990. strcpy (savedDir, smGD.clientPath);
  991. snprintf(smGD.etcPath, sizeof(smGD.etcPath), "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
  992. status = stat(smGD.etcPath, &buf);
  993. if(status == 0)
  994. {
  995. char * tmpName;
  996. int len, tfd;
  997. strcpy(savedOldDir, smGD.etcPath);
  998. len = strlen(smGD.savePath) + strlen(smGD.restoreSession)
  999. + strlen("XXXXXX") + 3;
  1000. tmpName = (char *) XtCalloc(1, len);
  1001. sprintf(tmpName, "%s/%s.XXXXXX", smGD.savePath,
  1002. smGD.restoreSession);
  1003. if ((tfd = mkstemp(tmpName)) == -1)
  1004. {
  1005. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1006. }
  1007. else
  1008. {
  1009. close(tfd);
  1010. unlink(tmpName);
  1011. MoveDirectory(smGD.etcPath, tmpName, False);
  1012. strncpy(savedTmpDir, tmpName, len - 1);
  1013. }
  1014. XtFree((char *) tmpName);
  1015. }
  1016. MoveDirectory(smGD.clientPath, smGD.etcPath, False);
  1017. }
  1018. smGD.clientPath[0] = 0;
  1019. smGD.settingPath[0] = 0;
  1020. smGD.resourcePath[0] = 0;
  1021. }
  1022. else
  1023. {
  1024. strcpy (savedDir, smGD.clientPath);
  1025. /*
  1026. * If the desired directory doesn't exist, create it.
  1027. */
  1028. status = stat(smGD.clientPath, &buf);
  1029. if(status == -1)
  1030. {
  1031. status = mkdir(smGD.clientPath, 0000);
  1032. if(status == -1)
  1033. {
  1034. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1035. smGD.clientPath[0] = 0;
  1036. smGD.settingPath[0] = 0;
  1037. smGD.resourcePath[0] = 0;
  1038. return(-1);
  1039. }
  1040. if(-1 == chmod(smGD.clientPath, 0755))
  1041. {
  1042. fprintf(stderr, "%s chmod error %s\n", smGD.clientPath, strerror(errno));
  1043. }
  1044. }
  1045. else
  1046. {
  1047. /*
  1048. * The desired directory already exists so it must
  1049. * be archived by moving it to its ".old" version. But
  1050. * first, if its ".old" version already exists, it must
  1051. * be moved to a temporary directory that will be removed
  1052. * when the session directories are pruned - after the
  1053. * save is complete.
  1054. */
  1055. char * tmpName;
  1056. snprintf(smGD.etcPath, sizeof(smGD.etcPath), "%s.%s", smGD.clientPath, SM_OLD_EXTENSION);
  1057. status = stat(smGD.etcPath, &buf);
  1058. if(status == 0)
  1059. {
  1060. int len, tfd;
  1061. len = strlen(smGD.savePath) + strlen(smGD.restoreSession)
  1062. + strlen("XXXXXX") + 3;
  1063. tmpName = (char *) XtCalloc(1, len);
  1064. snprintf(tmpName, len, "%s/%s.XXXXXX", smGD.savePath,
  1065. smGD.restoreSession);
  1066. strcpy (savedOldDir, smGD.etcPath);
  1067. if ((tfd = mkstemp(tmpName)) == -1)
  1068. {
  1069. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1070. }
  1071. else
  1072. {
  1073. close(tfd);
  1074. unlink(tmpName);
  1075. MoveDirectory (smGD.etcPath, tmpName, False);
  1076. strcpy (savedTmpDir, tmpName);
  1077. }
  1078. XtFree((char *) tmpName);
  1079. }
  1080. MoveDirectory(smGD.clientPath, smGD.etcPath, False);
  1081. /*
  1082. * Now re-make the directory
  1083. */
  1084. status = mkdir(smGD.clientPath, 0000);
  1085. if(status == -1)
  1086. {
  1087. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1088. smGD.clientPath[0] = 0;
  1089. smGD.settingPath[0] = 0;
  1090. smGD.resourcePath[0] = 0;
  1091. return(-1);
  1092. }
  1093. status = chmod(smGD.clientPath, 0755);
  1094. if(status == -1)
  1095. {
  1096. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1097. smGD.clientPath[0] = 0;
  1098. smGD.settingPath[0] = 0;
  1099. smGD.resourcePath[0] = 0;
  1100. return(-1);
  1101. }
  1102. }
  1103. strcat(smGD.clientPath, "/");
  1104. strcat(smGD.clientPath, SM_CLIENT_FILE2);
  1105. strcat(smGD.settingPath, "/");
  1106. strcat(smGD.settingPath, SM_SETTING_FILE);
  1107. strcat(smGD.resourcePath, "/");
  1108. strcat(smGD.resourcePath, SM_RESOURCE_FILE);
  1109. }
  1110. return(0);
  1111. }
  1112. /*************************************<->*************************************
  1113. *
  1114. * SetFontSavePath (saveToHome, mode)
  1115. *
  1116. *
  1117. * Description:
  1118. * -----------
  1119. * Sets up the save path for the auxillary directory.
  1120. *
  1121. *
  1122. * Inputs:
  1123. * ------
  1124. *
  1125. * Outputs:
  1126. * -------
  1127. *
  1128. * Comments:
  1129. * --------
  1130. *
  1131. *************************************<->***********************************/
  1132. int
  1133. SetFontSavePath(char *langPtr)
  1134. {
  1135. struct stat buf;
  1136. int status;
  1137. char *sessionSaved;
  1138. /*
  1139. * Set up the session font directory and see if it exists
  1140. */
  1141. if(smGD.sessionType == CURRENT_SESSION)
  1142. {
  1143. sessionSaved = SM_CURRENT_FONT_DIRECTORY;
  1144. }
  1145. else
  1146. {
  1147. sessionSaved = SM_HOME_FONT_DIRECTORY;
  1148. }
  1149. snprintf(smGD.fontPath, MAXPATHLEN, "%s/%s", smGD.savePath, sessionSaved);
  1150. status = stat(smGD.fontPath, &buf);
  1151. if(status == -1)
  1152. {
  1153. status = mkdir(smGD.fontPath, 0000);
  1154. if(status == -1)
  1155. {
  1156. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1157. smGD.fontPath[0] = 0;
  1158. return(-1);
  1159. }
  1160. if(-1 == chmod(smGD.fontPath, 0755))
  1161. {
  1162. fprintf(stderr, "%s chmod error %s\n", smGD.fontPath, strerror(errno));
  1163. }
  1164. }
  1165. /*
  1166. * Now add the lang subdirectory and see if it exists
  1167. */
  1168. strncat(smGD.fontPath, "/", MAXPATHLEN);
  1169. strncat(smGD.fontPath, langPtr, MAXPATHLEN);
  1170. status = stat(smGD.fontPath, &buf);
  1171. if(status == -1)
  1172. {
  1173. status = mkdir(smGD.fontPath, 0000);
  1174. if(status == -1)
  1175. {
  1176. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1177. smGD.fontPath[0] = 0;
  1178. return(-1);
  1179. }
  1180. status = chmod(smGD.fontPath, 0755);
  1181. if(status == -1)
  1182. {
  1183. PrintErrnoError(DtError, smNLS.cantCreateDirsString);
  1184. smGD.fontPath[0] = 0;
  1185. return(-1);
  1186. }
  1187. }
  1188. return(0);
  1189. }
  1190. /*************************************<->*************************************
  1191. *
  1192. * RemoveFiles()
  1193. *
  1194. *
  1195. * Description:
  1196. * -----------
  1197. * Remove the files that need to be removed
  1198. *
  1199. *
  1200. * Inputs:
  1201. * ------
  1202. *
  1203. * Outputs:
  1204. * -------
  1205. *
  1206. *
  1207. * Comments:
  1208. * --------
  1209. *
  1210. *************************************<->***********************************/
  1211. static void
  1212. RemoveFiles(
  1213. char *path )
  1214. {
  1215. pid_t clientFork;
  1216. int execStatus, childStatus, i, statLoc;
  1217. String tmpString;
  1218. /*
  1219. * Fork and exec the client process
  1220. */
  1221. sigaction(SIGCHLD, &smGD.defvec, (struct sigaction *) NULL);
  1222. clientFork = vfork();
  1223. /*
  1224. * If the fork fails - Send out an error and return
  1225. */
  1226. if(clientFork < 0)
  1227. {
  1228. PrintErrnoError(DtError, smNLS.cantForkClientString);
  1229. return;
  1230. }
  1231. /*
  1232. * Fork succeeded - now do the exec
  1233. */
  1234. if(clientFork == 0)
  1235. {
  1236. SetSIGPIPEToDefault ();
  1237. /*
  1238. * Set the gid of the process back from bin
  1239. */
  1240. #ifndef __hpux
  1241. #ifndef SVR4
  1242. setregid(smGD.runningGID, smGD.runningGID);
  1243. #else
  1244. setgid(smGD.runningGID);
  1245. setegid(smGD.runningGID);
  1246. #endif
  1247. #endif
  1248. _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
  1249. #if defined(CSRG_BASED)
  1250. setsid();
  1251. #else
  1252. (void) setpgrp();
  1253. #endif /* CSRG_BASED */
  1254. execStatus = execlp("rm","rm", "-rf", path, (char *) 0);
  1255. if(execStatus != 0)
  1256. {
  1257. 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.")) ;
  1258. PrintErrnoError(DtError, tmpString);
  1259. SM_FREE(tmpString);
  1260. SM_EXIT(-1);
  1261. }
  1262. }
  1263. while(wait(&statLoc) != clientFork);
  1264. sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
  1265. }
  1266. /*************************************<->*************************************
  1267. *
  1268. * MoveDirectory()
  1269. *
  1270. * Description:
  1271. * -----------
  1272. * Move the directory specified by pathFrom - to the directory specified
  1273. * by pathTo.
  1274. *
  1275. * Inputs:
  1276. * ------
  1277. * pathFrom = the directory to move from
  1278. * pathTo = the directory to move to
  1279. * removeDestDir = if True, directory pathTo is removed before the
  1280. * move occurs
  1281. *
  1282. * Outputs:
  1283. * -------
  1284. *
  1285. * Comments:
  1286. * --------
  1287. *
  1288. *************************************<->***********************************/
  1289. void
  1290. MoveDirectory(
  1291. char *pathFrom,
  1292. char *pathTo,
  1293. Boolean removeDestDir)
  1294. {
  1295. struct stat buf;
  1296. pid_t clientFork;
  1297. int status, execStatus, childStatus, i, statLoc;
  1298. String tmpString;
  1299. /*
  1300. * If the pathTo directory exists - remove it
  1301. */
  1302. if (removeDestDir)
  1303. {
  1304. status = stat(pathTo, &buf);
  1305. if(status != -1)
  1306. {
  1307. RemoveFiles(pathTo);
  1308. }
  1309. }
  1310. /*
  1311. * Fork and exec the client process
  1312. */
  1313. sigaction(SIGCHLD, &smGD.defvec, (struct sigaction *) NULL);
  1314. clientFork = vfork();
  1315. /*
  1316. * If the fork fails - Send out an error and return
  1317. */
  1318. if(clientFork < 0)
  1319. {
  1320. PrintErrnoError(DtError, smNLS.cantForkClientString);
  1321. return;
  1322. }
  1323. /*
  1324. * Fork succeeded - now do the exec
  1325. */
  1326. if(clientFork == 0)
  1327. {
  1328. SetSIGPIPEToDefault ();
  1329. /*
  1330. * Set the gid of the process back from bin
  1331. */
  1332. #ifndef __hpux
  1333. #ifndef SVR4
  1334. setregid(smGD.runningGID, smGD.runningGID);
  1335. #else
  1336. setgid(smGD.runningGID);
  1337. setegid(smGD.runningGID);
  1338. #endif
  1339. #endif
  1340. _DtEnvControl(DT_ENV_RESTORE_PRE_DT);
  1341. #if defined(CSRG_BASED)
  1342. setsid();
  1343. #else
  1344. (void) setpgrp();
  1345. #endif /* CSRG_BASED */
  1346. execStatus = execlp("mv","mv", pathFrom, pathTo, (char *) 0);
  1347. if(execStatus != 0)
  1348. {
  1349. 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.")) ;
  1350. PrintErrnoError(DtError, tmpString);
  1351. SM_FREE(tmpString);
  1352. SM_EXIT(-1);
  1353. }
  1354. }
  1355. while(wait(&statLoc) != clientFork);
  1356. sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
  1357. }
  1358. /*************************************<->*************************************
  1359. *
  1360. * InitNlsStrings()
  1361. *
  1362. *
  1363. * Description:
  1364. * -----------
  1365. * Initialize the NLS strings used in dtsession
  1366. *
  1367. *
  1368. * Inputs:
  1369. * ------
  1370. *
  1371. * Outputs:
  1372. * -------
  1373. *
  1374. *
  1375. * Comments:
  1376. * --------
  1377. *
  1378. *************************************<->***********************************/
  1379. void
  1380. InitNlsStrings( void )
  1381. {
  1382. char *tmpString;
  1383. /*
  1384. * Malloc failure error message - THIS MESSAGE MUST BE INITIALIZED FIRST
  1385. */
  1386. smNLS.cantMallocErrorString = strdup (((char *)GETMESSAGE(4, 5, "Unable to malloc memory for operation.")));
  1387. /*
  1388. * Error message when dtsession cant lock the display
  1389. */
  1390. smNLS.cantLockErrorString = strdup (((char *)GETMESSAGE(4, 6, "Unable to lock display. Another application may have the pointer or keyboard grabbed.")));
  1391. /*
  1392. * Error message when dtsession cant open files for reading or writing
  1393. */
  1394. smNLS.cantOpenFileString = strdup (((char *)GETMESSAGE(4, 7, "Unable to open session file. No clients will be restarted.")));
  1395. /*
  1396. * Error message when dtsession cant fork client process
  1397. */
  1398. smNLS.cantForkClientString = strdup (((char *)GETMESSAGE(4, 8, "Unable to fork client process.")));
  1399. /*
  1400. * Error message when dtsession cant create dt directories
  1401. */
  1402. smNLS.cantCreateDirsString = strdup (((char *)GETMESSAGE(4, 9, "Unable to create DT directories. Check permissions on home directory.")));
  1403. /*
  1404. * Error message when trying to lock display on trusted system
  1405. */
  1406. smNLS.trustedSystemErrorString = strdup (((char *)GETMESSAGE(4, 10, "Unable to lock display due to security restrictions")));
  1407. }
  1408. /*************************************<->*************************************
  1409. *
  1410. * WaitChildDeath()
  1411. *
  1412. *
  1413. * Description:
  1414. * -----------
  1415. * When a SIGCHLD signal comes in, wait for all child processes to die.
  1416. *
  1417. *
  1418. * Inputs:
  1419. * ------
  1420. *
  1421. * Outputs:
  1422. * -------
  1423. *
  1424. *
  1425. * Comments:
  1426. * --------
  1427. *
  1428. *************************************<->***********************************/
  1429. void
  1430. WaitChildDeath( int i )
  1431. {
  1432. int stat_loc;
  1433. pid_t pid;
  1434. /*
  1435. * Wait on any children that have died since the last SIGCHLD we
  1436. * received. Any child process death that occurs while we are
  1437. * in WaitChildDeath() will not result in a SIGCHLD. Any
  1438. * child proceses that die after our last call to waitpid() will
  1439. * remain zombiefied until the next invocation of WaitChildDeath().
  1440. */
  1441. while ((pid = waitpid(-1, &stat_loc, WNOHANG)) > 0)
  1442. ;
  1443. sigaction(SIGCHLD, &smGD.childvec, (struct sigaction *) NULL);
  1444. }
  1445. /*************************************<->*************************************
  1446. *
  1447. * TrimErrorlog()
  1448. *
  1449. *
  1450. * Description:
  1451. * -----------
  1452. * Trim the errorlog file using the following algorithm:
  1453. * if(errorlog.old exists and is not empty) move it to errorlog.oldest
  1454. * if(errorlog exists and is not empty) move it to errorlog.old
  1455. *
  1456. *
  1457. * Inputs:
  1458. * ------
  1459. *
  1460. * Outputs:
  1461. * -------
  1462. *
  1463. *
  1464. * Comments:
  1465. * --------
  1466. *
  1467. *************************************<->***********************************/
  1468. static void
  1469. TrimErrorlog( void )
  1470. {
  1471. char *savePath, /* common path element for all pathnames */
  1472. *checkPath1,
  1473. *checkPath2;
  1474. struct stat buf;
  1475. int len, status;
  1476. char *home;
  1477. /*
  1478. * Allocate the strings needed
  1479. */
  1480. savePath = (char *) SM_MALLOC(MAXPATHLEN + 1);
  1481. checkPath1 = (char *) SM_MALLOC(MAXPATHLEN + 1);
  1482. checkPath2 = (char *) SM_MALLOC(MAXPATHLEN + 1);
  1483. if ((home=getenv("HOME")) == NULL)
  1484. home="";
  1485. len = strlen(home) + strlen(DtPERSONAL_CONFIG_DIRECTORY) + 2;
  1486. if (len > MAXPATHLEN) savePath = SM_REALLOC(savePath, len);
  1487. snprintf(savePath, len, "%s/%s", home, DtPERSONAL_CONFIG_DIRECTORY);
  1488. /*
  1489. * If errorlog.old exists and it is not empty, delete
  1490. * errorlog.older and then move errolog.old to
  1491. * errorlog.older
  1492. */
  1493. if (len + strlen(DtOLDER_ERRORLOG_FILE) > MAXPATHLEN)
  1494. checkPath1 = SM_REALLOC(savePath, len + strlen(DtOLDER_ERRORLOG_FILE));
  1495. sprintf(checkPath1, "%s/%s", savePath, DtOLDER_ERRORLOG_FILE);
  1496. if (len + strlen(DtOLD_ERRORLOG_FILE) > MAXPATHLEN)
  1497. checkPath2 = SM_REALLOC(savePath, len + strlen(DtOLD_ERRORLOG_FILE));
  1498. sprintf(checkPath2, "%s/%s", savePath, DtOLD_ERRORLOG_FILE);
  1499. status = stat(checkPath2, &buf);
  1500. if((status != -1) && (buf.st_size > 0))
  1501. {
  1502. (void) unlink(checkPath1);
  1503. (void) link(checkPath2, checkPath1);
  1504. (void) unlink(checkPath2);
  1505. }
  1506. /*
  1507. * If errorlog exists and it is not empty, move it to
  1508. * errorlog.old
  1509. */
  1510. if (len + strlen(DtERRORLOG_FILE) > MAXPATHLEN)
  1511. checkPath1 = SM_REALLOC(savePath, len + strlen(DtERRORLOG_FILE));
  1512. snprintf(checkPath1, len + strlen(DtERRORLOG_FILE), "%s/%s", savePath, DtERRORLOG_FILE);
  1513. status = stat(checkPath1, &buf);
  1514. if((status != -1) && (buf.st_size > 0))
  1515. {
  1516. (void) link(checkPath1, checkPath2);
  1517. (void) unlink(checkPath1);
  1518. }
  1519. SM_FREE((char *) savePath);
  1520. SM_FREE((char *) checkPath1);
  1521. SM_FREE((char *) checkPath2);
  1522. return;
  1523. }
  1524. /*************************************<->*************************************
  1525. *
  1526. * SetSystemReady()
  1527. *
  1528. *
  1529. * Description:
  1530. * -----------
  1531. * Do everything that needs to be done to get the system back into a
  1532. * READY state. This includes checking to be sure that the BMS did not
  1533. * die while we were in process
  1534. *
  1535. *
  1536. * Inputs:
  1537. * ------
  1538. *
  1539. * Outputs:
  1540. * -------
  1541. *
  1542. *
  1543. * Comments:
  1544. * --------
  1545. *
  1546. *************************************<->***********************************/
  1547. void
  1548. SetSystemReady( void )
  1549. {
  1550. smGD.smState = READY;
  1551. if(smGD.bmsDead == True)
  1552. {
  1553. WarnMsgFailure();
  1554. }
  1555. return;
  1556. }
  1557. /*************************************<->*************************************
  1558. *
  1559. * SmCvtStringToContManagement (args, numArgs, fromVal, toVal)
  1560. *
  1561. *
  1562. * Description:
  1563. * -----------
  1564. * This function converts a string to a value for the
  1565. * contention management flag set.
  1566. *
  1567. *
  1568. * Inputs:
  1569. * ------
  1570. * args = additional XrmValue arguments to the converter - NULL here
  1571. *
  1572. * numArgs = number of XrmValue arguments - 0 here
  1573. *
  1574. * fromVal = resource value to convert
  1575. *
  1576. *
  1577. * Outputs:
  1578. * -------
  1579. * toVal = descriptor to use to return converted value
  1580. *
  1581. *************************************<->***********************************/
  1582. void SmCvtStringToContManagement (XrmValue *args, Cardinal numArgs, XrmValue *fromVal, XrmValue *toVal)
  1583. {
  1584. unsigned char *pch = (unsigned char *) (fromVal->addr);
  1585. unsigned char *pchNext;
  1586. int len;
  1587. static long cval;
  1588. Boolean fHit = False;
  1589. Boolean fAddNext = True;
  1590. /*
  1591. * Names of contention management options
  1592. */
  1593. #define CM_ALL_STR (unsigned char *)"all"
  1594. #define CM_SYSTEM_STR (unsigned char *)"system"
  1595. #define CM_HANDSHAKE_STR (unsigned char *)"handshake"
  1596. #define CM_NONE_STR (unsigned char *)"none"
  1597. /*
  1598. * Check first token. If '-' we subtract from all options.
  1599. * Otherwise, we start with no contention management and add things in.
  1600. */
  1601. if (*pch &&
  1602. (_DtNextToken (pch, &len, &pchNext)) &&
  1603. (*pch == '-'))
  1604. {
  1605. cval = SM_CM_ALL;
  1606. fHit = True;
  1607. }
  1608. else
  1609. {
  1610. cval = SM_CM_NONE;
  1611. }
  1612. while (*pch && _DtNextToken (pch, &len, &pchNext))
  1613. {
  1614. /*
  1615. * Strip off "sign" if prepended to another token, and process
  1616. * that token the next time through.
  1617. */
  1618. if (*pch == '+')
  1619. {
  1620. if (len != 1)
  1621. {
  1622. pchNext = pch + 1;
  1623. }
  1624. fAddNext = TRUE;
  1625. }
  1626. else if (*pch == '-')
  1627. {
  1628. if (len != 1)
  1629. {
  1630. pchNext = pch + 1;
  1631. }
  1632. fAddNext = FALSE;
  1633. }
  1634. if ((*pch == 'A') || (*pch == 'a'))
  1635. {
  1636. if (_DtWmStringsAreEqual (pch, CM_ALL_STR, len))
  1637. {
  1638. cval = fAddNext ? (cval | SM_CM_ALL) :
  1639. (cval & ~SM_CM_ALL);
  1640. fHit = True;
  1641. }
  1642. }
  1643. else if ((*pch == 'S') || (*pch == 's'))
  1644. {
  1645. if (_DtWmStringsAreEqual (pch, CM_SYSTEM_STR, len))
  1646. {
  1647. cval = fAddNext ? (cval | SM_CM_SYSTEM) :
  1648. (cval & ~SM_CM_SYSTEM);
  1649. fHit = True;
  1650. }
  1651. }
  1652. else if ((*pch == 'H') || (*pch == 'h'))
  1653. {
  1654. if (_DtWmStringsAreEqual (pch, CM_HANDSHAKE_STR, len))
  1655. {
  1656. cval = fAddNext ? (cval | SM_CM_HANDSHAKE) :
  1657. (cval & ~SM_CM_HANDSHAKE);
  1658. fHit = True;
  1659. }
  1660. }
  1661. else if ((*pch == 'N') || (*pch == 'n'))
  1662. {
  1663. if (_DtWmStringsAreEqual (pch, CM_NONE_STR, len))
  1664. {
  1665. /* don't bother adding or subtracting nothing */
  1666. fHit = True;
  1667. }
  1668. }
  1669. pch = pchNext;
  1670. }
  1671. /*
  1672. * If we didn't match anything then set to default.
  1673. */
  1674. if (!fHit)
  1675. {
  1676. cval = SM_CM_DEFAULT;
  1677. }
  1678. (*toVal).size = sizeof (long);
  1679. (*toVal).addr = (caddr_t) &cval;
  1680. } /* END OF FUNCTION SmCvtStringToContManagement */
  1681. /*************************************<->*************************************
  1682. *
  1683. * _DtNextToken (pchIn, pLen, ppchNext)
  1684. *
  1685. *
  1686. * Description:
  1687. * -----------
  1688. * XXDescription ...
  1689. *
  1690. *
  1691. * Inputs:
  1692. * ------
  1693. * pchIn = pointer to start of next token
  1694. *
  1695. *
  1696. * Outputs:
  1697. * -------
  1698. * pLen = pointer to integer containing number of characters in next token
  1699. * ppchNext = address of pointer to following token
  1700. *
  1701. * Return = next token or NULL
  1702. *
  1703. *
  1704. * Comments:
  1705. * --------
  1706. * None.
  1707. *
  1708. *************************************<->***********************************/
  1709. unsigned char *_DtNextToken (unsigned char *pchIn, int *pLen,
  1710. unsigned char **ppchNext)
  1711. {
  1712. unsigned char *pchR = pchIn;
  1713. register int i;
  1714. #ifdef MULTIBYTE
  1715. register int chlen;
  1716. for (i = 0; ((chlen = mblen ((char *)pchIn, MB_CUR_MAX)) > 0); i++)
  1717. /* find end of word: requires singlebyte whitespace terminator */
  1718. {
  1719. if ((chlen == 1) && isspace (*pchIn))
  1720. {
  1721. break;
  1722. }
  1723. pchIn += chlen;
  1724. }
  1725. #else
  1726. for (i = 0; *pchIn && !isspace (*pchIn); i++, pchIn++)
  1727. /* find end of word */
  1728. {
  1729. }
  1730. #endif
  1731. /* skip to next word */
  1732. ScanWhitespace (&pchIn);
  1733. *ppchNext = pchIn;
  1734. *pLen = i;
  1735. if (i)
  1736. {
  1737. return(pchR);
  1738. }
  1739. else
  1740. {
  1741. return(NULL);
  1742. }
  1743. } /* END OF FUNCTION _DtNextToken */
  1744. /*************************************<->*************************************
  1745. *
  1746. * _DtWmStringsAreEqual (pch1, pch2, len)
  1747. *
  1748. *
  1749. * Description:
  1750. * -----------
  1751. * XXDescription ...
  1752. *
  1753. *
  1754. * Inputs:
  1755. * ------
  1756. * pch1 =
  1757. * pch2 =
  1758. * len =
  1759. *
  1760. *
  1761. * Outputs:
  1762. * -------
  1763. * Return = (Boolean) True iff strings match (case insensitive)
  1764. *
  1765. *
  1766. * Comments:
  1767. * --------
  1768. * None.
  1769. *
  1770. *************************************<->***********************************/
  1771. Boolean _DtWmStringsAreEqual (unsigned char *pch1, unsigned char *pch2, int len)
  1772. {
  1773. #ifdef MULTIBYTE
  1774. int chlen1;
  1775. int chlen2;
  1776. wchar_t wch1;
  1777. wchar_t wch2;
  1778. while (len &&
  1779. ((chlen1 = mbtowc (&wch1, (char *) pch1, 2)) > 0) &&
  1780. ((chlen2 = mbtowc (&wch2, (char *) pch2, 2)) == chlen1) )
  1781. {
  1782. if (chlen1 == 1)
  1783. /* singlebyte characters -- make case insensitive */
  1784. {
  1785. if ((isupper (*pch1) ? tolower(*pch1) : *pch1) !=
  1786. (isupper (*pch2) ? tolower(*pch2) : *pch2))
  1787. {
  1788. break;
  1789. }
  1790. }
  1791. else
  1792. /* multibyte characters */
  1793. {
  1794. if (wch1 != wch2)
  1795. {
  1796. break;
  1797. }
  1798. }
  1799. pch1 += chlen1;
  1800. pch2 += chlen2;
  1801. len--;
  1802. }
  1803. #else
  1804. while (len && *pch1 && *pch2 &&
  1805. ((isupper (*pch1) ? tolower(*pch1) : *pch1) ==
  1806. (isupper (*pch2) ? tolower(*pch2) : *pch2)))
  1807. {
  1808. *pch1++;
  1809. *pch2++;
  1810. len--;
  1811. }
  1812. #endif
  1813. return (len == 0);
  1814. } /* END OF _DtWmStringsAreEqual */
  1815. /*************************************<->*************************************
  1816. *
  1817. * InitializeGenericSession - set the smGD paths using the CDE 1.0
  1818. * session starting algorithm.
  1819. *
  1820. * Description:
  1821. * -----------
  1822. * Initializes several variables in smGD
  1823. *
  1824. * Inputs:
  1825. * ------
  1826. * tmpDisplay
  1827. *
  1828. * Outputs:
  1829. * -------
  1830. * Return = void
  1831. *
  1832. * Comments:
  1833. * --------
  1834. *
  1835. *************************************<->***********************************/
  1836. static void
  1837. InitializeGenericSession (
  1838. Display *tmpDisplay)
  1839. {
  1840. struct stat buf;
  1841. int session_needed = 1;
  1842. int status;
  1843. char tmpPath[MAXPATHLEN];
  1844. smGD.savePath = _DtCreateDtDirs(tmpDisplay);
  1845. if (session_needed)
  1846. {
  1847. strcpy(smGD.clientPath, smGD.savePath);
  1848. strcat(smGD.clientPath, "/");
  1849. strcat(smGD.clientPath, SM_CURRENT_DIRECTORY);
  1850. strcat(smGD.clientPath, "/");
  1851. strcpy (tmpPath, smGD.clientPath);
  1852. strcat(smGD.clientPath, SM_CLIENT_FILE2);
  1853. status = stat(smGD.clientPath, &buf);
  1854. if (status != 0) {
  1855. strcpy (smGD.clientPath, tmpPath);
  1856. strcat (smGD.clientPath, SM_CLIENT_FILE);
  1857. status = stat(smGD.clientPath, &buf);
  1858. }
  1859. if(status == 0)
  1860. {
  1861. /*
  1862. * sessions/current/dt.settings exist, restore to 'current' session
  1863. */
  1864. strcpy(smGD.resourcePath, smGD.savePath);
  1865. strcat(smGD.resourcePath, "/");
  1866. strcat(smGD.resourcePath, SM_CURRENT_DIRECTORY);
  1867. strcat(smGD.resourcePath, "/");
  1868. strcat(smGD.resourcePath, SM_RESOURCE_FILE);
  1869. strcpy(smGD.settingPath, smGD.savePath);
  1870. strcat(smGD.settingPath, "/");
  1871. strcat(smGD.settingPath, SM_CURRENT_DIRECTORY);
  1872. strcat(smGD.settingPath, "/");
  1873. strcat(smGD.settingPath, SM_SETTING_FILE);
  1874. SetResSet();
  1875. smGD.sessionType = CURRENT_SESSION;
  1876. smGD.restoreSession = (char *) SM_CURRENT_DIRECTORY;
  1877. session_needed = 0;
  1878. }
  1879. }
  1880. if (session_needed)
  1881. {
  1882. strcpy(smGD.clientPath, smGD.savePath);
  1883. strcat(smGD.clientPath, "/");
  1884. strcat(smGD.clientPath, SM_HOME_DIRECTORY);
  1885. strcat(smGD.clientPath, "/");
  1886. strcpy(tmpPath, smGD.clientPath);
  1887. strcat(smGD.clientPath, SM_CLIENT_FILE2);
  1888. status = stat(smGD.clientPath, &buf);
  1889. if (status != 0) {
  1890. strcpy (smGD.clientPath, tmpPath);
  1891. strcat (smGD.clientPath, SM_CLIENT_FILE);
  1892. status = stat(smGD.clientPath, &buf);
  1893. }
  1894. if(status == 0)
  1895. {
  1896. /*
  1897. * sessions/home/dt.settings exist, restore to 'home' session
  1898. */
  1899. strcpy(smGD.resourcePath, smGD.savePath);
  1900. strcat(smGD.resourcePath, "/");
  1901. strcat(smGD.resourcePath, SM_HOME_DIRECTORY);
  1902. strcat(smGD.resourcePath, "/");
  1903. strcat(smGD.resourcePath, SM_RESOURCE_FILE);
  1904. strcpy(smGD.settingPath, smGD.savePath);
  1905. strcat(smGD.settingPath, "/");
  1906. strcat(smGD.settingPath, SM_HOME_DIRECTORY);
  1907. strcat(smGD.settingPath, "/");
  1908. strcat(smGD.settingPath, SM_SETTING_FILE);
  1909. SetResSet();
  1910. smGD.sessionType = HOME_SESSION;
  1911. smGD.restoreSession = (char *) SM_HOME_DIRECTORY;
  1912. session_needed = 0;
  1913. }
  1914. }
  1915. if (session_needed)
  1916. {
  1917. SetSysDefaults();
  1918. }
  1919. }
  1920. /*************************************<->*************************************
  1921. *
  1922. * InternSessionDir - intern the session dir property and put it
  1923. * on the root window
  1924. *
  1925. * NOTE: - also checks the validity of the -session command line
  1926. * option
  1927. *
  1928. * Inputs:
  1929. * ------
  1930. * session_option - as given in the command line
  1931. * display
  1932. *
  1933. * Outputs:
  1934. * ------
  1935. * smGD.restoreSession - initialized
  1936. *
  1937. * Return = void
  1938. *
  1939. *************************************<->***********************************/
  1940. static Boolean
  1941. InternSessionDir (
  1942. char *session_option,
  1943. Display *disp)
  1944. {
  1945. char *pch;
  1946. if (!strcmp (session_option, SM_CURRENT_DIRECTORY)) {
  1947. pch = DtSM_SESSION_DIRECTORY;
  1948. smGD.restoreSession = SM_CURRENT_DIRECTORY;
  1949. }
  1950. else if (!strcmp (session_option, SM_HOME_DIRECTORY)) {
  1951. pch = DtSM_SESSION_DIRECTORY;
  1952. smGD.restoreSession = SM_HOME_DIRECTORY;
  1953. }
  1954. else if (!strcmp (session_option, SM_DISPLAY_HOME)) {
  1955. pch = DtSM_SESSION_DISPLAY_DIRECTORY;
  1956. smGD.restoreSession = SM_HOME_DIRECTORY;
  1957. }
  1958. else if (!strcmp (session_option, SM_DISPLAY_CURRENT)) {
  1959. pch = DtSM_SESSION_DISPLAY_DIRECTORY;
  1960. smGD.restoreSession = SM_CURRENT_DIRECTORY;
  1961. }
  1962. else
  1963. /*
  1964. * The session_option is not supported
  1965. */
  1966. return (False);
  1967. XaSmRestoreDir = XInternAtom(disp, _XA_DT_RESTORE_DIR, False);
  1968. XChangeProperty(disp, RootWindow(disp, 0),
  1969. XaSmRestoreDir, XA_STRING, 8, PropModeReplace,
  1970. (unsigned char *)pch, strlen(pch));
  1971. XFlush(disp);
  1972. return (True);
  1973. }
  1974. /*************************************<->*************************************
  1975. *
  1976. * InitializeSpecificSession - set the smGD paths based on the session
  1977. * name given on the command line.
  1978. *
  1979. * Description:
  1980. * -----------
  1981. * Initializes several variables in smGD
  1982. *
  1983. * Inputs:
  1984. * ------
  1985. * session_option
  1986. * tmpDisplay
  1987. *
  1988. * Outputs:
  1989. * -------
  1990. * Return = void
  1991. *
  1992. * Comments:
  1993. * --------
  1994. *
  1995. *************************************<->***********************************/
  1996. static Boolean
  1997. InitializeSpecificSession (
  1998. char *session_option,
  1999. Display *disp,
  2000. unsigned int argc,
  2001. char **argv)
  2002. {
  2003. char *session_dir = (char *) XtMalloc(MAXPATHLEN);
  2004. char *alt_dir = (char *) XtMalloc(MAXPATHLEN);
  2005. int len;
  2006. struct stat buf;
  2007. if (!InternSessionDir (session_option, disp))
  2008. return (False);
  2009. InitializePaths (smGD.restoreSession, disp);
  2010. if (!strcmp (session_option, SM_HOME_DIRECTORY)) {
  2011. /*
  2012. * Home session
  2013. */
  2014. if (smGD.clientPath[0] == '\0') {
  2015. if ((stat (smGD.savePath, &buf)) != 0) {
  2016. if ((mkdir (smGD.savePath, 0000)) == 0)
  2017. (void) chmod (smGD.savePath, 0755);
  2018. else
  2019. PrintErrnoError(DtError,
  2020. smNLS.cantCreateDirsString);
  2021. }
  2022. SetSysDefaults ();
  2023. }
  2024. smGD.sessionType = HOME_SESSION;
  2025. smGD.restoreSession = SM_HOME_DIRECTORY;
  2026. }
  2027. else if (!strcmp (session_option, SM_CURRENT_DIRECTORY)) {
  2028. /*
  2029. * Current session
  2030. */
  2031. if (smGD.clientPath[0] == '\0') {
  2032. /*
  2033. * Fallback to the generic home session
  2034. */
  2035. (void) sprintf (session_dir, "%s/%s",
  2036. smGD.savePath, SM_CURRENT_DIRECTORY);
  2037. (void) sprintf (alt_dir, "%s/%s",
  2038. smGD.savePath, SM_HOME_DIRECTORY);
  2039. if (!SetAlternateSession (session_dir, alt_dir, True))
  2040. SetSysDefaults ();
  2041. }
  2042. smGD.sessionType = CURRENT_SESSION;
  2043. smGD.restoreSession = SM_CURRENT_DIRECTORY;
  2044. }
  2045. else if (!strcmp (session_option, SM_DISPLAY_HOME)) {
  2046. /*
  2047. * Display-specific Home session
  2048. */
  2049. (void) sprintf (session_dir, "%s/%s",
  2050. smGD.savePath, SM_HOME_DIRECTORY);
  2051. if ((stat(session_dir, &buf)) != 0){
  2052. /*
  2053. * The session does not exist, give the user a
  2054. * change to exit.
  2055. */
  2056. if (!ConfirmSessionCreation (HOME_SESSION, argc, argv))
  2057. SM_EXIT (0);
  2058. }
  2059. if (smGD.clientPath[0] == '\0') {
  2060. /*
  2061. * Fallback to the generic home session
  2062. */
  2063. char *home;
  2064. if ((home = getenv ("HOME")) == 0)
  2065. home = "";
  2066. /* JET - VU#497553 */
  2067. len = strlen(home) +
  2068. strlen(DtPERSONAL_CONFIG_DIRECTORY) +
  2069. strlen(DtSM_SESSION_DIRECTORY) +
  2070. strlen(SM_HOME_DIRECTORY);
  2071. if (len > MAXPATHLEN)
  2072. alt_dir = XtRealloc(alt_dir, len + 1);
  2073. (void) sprintf (alt_dir, "%s/%s/%s/%s",
  2074. home,
  2075. DtPERSONAL_CONFIG_DIRECTORY,
  2076. DtSM_SESSION_DIRECTORY,
  2077. SM_HOME_DIRECTORY);
  2078. if (!SetAlternateSession (session_dir, alt_dir, True))
  2079. SetSysDefaults ();
  2080. }
  2081. smGD.sessionType = HOME_SESSION;
  2082. smGD.restoreSession = SM_HOME_DIRECTORY;
  2083. }
  2084. else if (!strcmp (session_option, SM_DISPLAY_CURRENT)) {
  2085. /*
  2086. * Display-specific Current session
  2087. */
  2088. (void) sprintf (session_dir, "%s/%s",
  2089. smGD.savePath, SM_CURRENT_DIRECTORY);
  2090. if ((stat(session_dir, &buf)) != 0){
  2091. /*
  2092. * The session does not exist, give the user a
  2093. * change to exit.
  2094. */
  2095. if (!ConfirmSessionCreation (CURRENT_SESSION, argc, argv))
  2096. SM_EXIT (0);
  2097. }
  2098. if (smGD.clientPath[0] == '\0') {
  2099. /*
  2100. * First, fallback to the display-specific home session
  2101. */
  2102. char *home;
  2103. (void) sprintf (alt_dir, "%s/%s",
  2104. smGD.savePath, SM_HOME_DIRECTORY);
  2105. if (!SetAlternateSession (session_dir, alt_dir, False)){
  2106. /*
  2107. * Try the generic home session
  2108. */
  2109. if ((home = getenv ("HOME")) == 0)
  2110. home = "";
  2111. /* JET - VU#497553 */
  2112. len = strlen(home) +
  2113. strlen(DtPERSONAL_CONFIG_DIRECTORY) +
  2114. strlen(DtSM_SESSION_DIRECTORY) +
  2115. strlen(SM_HOME_DIRECTORY);
  2116. if (len > MAXPATHLEN)
  2117. alt_dir = XtRealloc(alt_dir, len + 1);
  2118. snprintf(alt_dir, len, "%s/%s/%s/%s",
  2119. home,
  2120. DtPERSONAL_CONFIG_DIRECTORY,
  2121. DtSM_SESSION_DIRECTORY,
  2122. SM_HOME_DIRECTORY);
  2123. if (!SetAlternateSession (session_dir,
  2124. alt_dir,
  2125. True))
  2126. SetSysDefaults ();
  2127. }
  2128. }
  2129. smGD.sessionType = CURRENT_SESSION;
  2130. smGD.restoreSession = SM_CURRENT_DIRECTORY;
  2131. }
  2132. else {
  2133. if (session_dir) XtFree(session_dir);
  2134. if (alt_dir) XtFree(alt_dir);
  2135. return (False);
  2136. }
  2137. if (session_dir) XtFree(session_dir);
  2138. if (alt_dir) XtFree(alt_dir);
  2139. return (True);
  2140. }
  2141. /*************************************<->*************************************
  2142. *
  2143. * InitializePaths
  2144. *
  2145. * Description:
  2146. * -----------
  2147. * Initializes the following variables:
  2148. *
  2149. * smGD.savePath
  2150. * smGD.settingsPath
  2151. * smGD.resourcePath
  2152. * smGD.clientPath - [0] = '\0' if the database files do not exist
  2153. *
  2154. * Inputs:
  2155. * ------
  2156. * session_name = "current" or "home"
  2157. *
  2158. * Outputs:
  2159. * -------
  2160. * Return = void
  2161. *
  2162. * Comments:
  2163. * --------
  2164. *
  2165. *************************************<->***********************************/
  2166. static void
  2167. InitializePaths (
  2168. char * session_name,
  2169. Display * disp)
  2170. {
  2171. char *db_file = (char *) XtMalloc(MAXPATHLEN);
  2172. struct stat buf;
  2173. if (!db_file)
  2174. {
  2175. PrintError(DtError, smNLS.cantMallocErrorString);
  2176. return;
  2177. }
  2178. smGD.savePath = _DtCreateDtDirs(disp);
  2179. (void) sprintf (smGD.settingPath, "%s/%s/%s",
  2180. smGD.savePath, session_name, SM_SETTING_FILE);
  2181. (void) sprintf (smGD.resourcePath, "%s/%s/%s",
  2182. smGD.savePath, session_name, SM_RESOURCE_FILE);
  2183. smGD.clientPath[0] = '\0';
  2184. (void) sprintf (db_file, "%s/%s/%s",
  2185. smGD.savePath, session_name, SM_CLIENT_FILE2);
  2186. if ((stat(db_file, &buf)) == 0)
  2187. (void) strcpy (smGD.clientPath, db_file);
  2188. else {
  2189. (void) sprintf (db_file, "%s/%s/%s",
  2190. smGD.savePath, session_name, SM_CLIENT_FILE);
  2191. if ((stat(db_file, &buf)) == 0)
  2192. (void) strcpy (smGD.clientPath, db_file);
  2193. }
  2194. XtFree(db_file);
  2195. }
  2196. /*************************************<->*************************************
  2197. *
  2198. * SetAlternateSession
  2199. *
  2200. * Assumptions:
  2201. *
  2202. * Neither of the client databases in the session_dir directory
  2203. * exist.
  2204. *
  2205. * Inputs:
  2206. * ------
  2207. * session_dir - the directory path for the session including home
  2208. * or current
  2209. * alt_dir - the directory to use in the search for an alternate
  2210. * or fallback session database
  2211. * make_dir - if True, a session_dir will be created if it does not
  2212. * exits; if False, session_dir will not be created
  2213. *
  2214. * Outputs:
  2215. * -------
  2216. * Return = Boolean
  2217. *
  2218. *************************************<->***********************************/
  2219. static Boolean
  2220. SetAlternateSession (
  2221. char * session_dir,
  2222. char * alt_dir,
  2223. Boolean make_dir)
  2224. {
  2225. char *tmp_dir = NULL;
  2226. char *db_file1 = (char *) XtMalloc(MAXPATHLEN);
  2227. char *db_file2 = (char *) XtMalloc(MAXPATHLEN);
  2228. struct stat buf;
  2229. if (!db_file1 || !db_file2)
  2230. {
  2231. PrintError(DtError, smNLS.cantMallocErrorString);
  2232. return False;
  2233. }
  2234. if ((stat (session_dir, &buf)) != 0) {
  2235. /*
  2236. * The requested dir does not exist, create it
  2237. * by either copying the session from alt_dir (if
  2238. * it exists and has a client database) or by
  2239. * calling mkdir.
  2240. */
  2241. (void) sprintf (db_file1, "%s/%s",
  2242. alt_dir, SM_CLIENT_FILE2);
  2243. (void) sprintf (db_file2, "%s/%s",
  2244. alt_dir, SM_CLIENT_FILE);
  2245. if ((stat(db_file1, &buf)) == 0)
  2246. tmp_dir = db_file1;
  2247. else if ((stat(db_file2, &buf)) == 0)
  2248. tmp_dir = db_file2;
  2249. if (!tmp_dir && !make_dir) {
  2250. if (db_file1) XtFree(db_file1);
  2251. if (db_file2) XtFree(db_file2);
  2252. /*
  2253. * This alt_dir doesn't have a session database
  2254. * return now and try another directory
  2255. */
  2256. return (False);
  2257. }
  2258. if (tmp_dir) {
  2259. /*
  2260. * The alt_dir has a session database, create
  2261. * a copy of its entire directory because all
  2262. * of the sessions state is needed.
  2263. */
  2264. char *tmp;
  2265. tmp = XtMalloc (strlen (alt_dir) +
  2266. strlen (session_dir) + 10);
  2267. if (!tmp)
  2268. return (False);
  2269. (void) sprintf (tmp, "cp -r %s %s",
  2270. alt_dir, session_dir);
  2271. if ((system (tmp)) == -1)
  2272. return (False);
  2273. XtFree (tmp);
  2274. if ((stat(session_dir, &buf)) != 0)
  2275. /*
  2276. * It should have been created by the cp
  2277. */
  2278. return (False);
  2279. /*
  2280. * The session database needs to be updated.
  2281. */
  2282. if (tmp_dir == db_file1)
  2283. sprintf (smGD.clientPath, "%s/%s",
  2284. session_dir, SM_CLIENT_FILE2);
  2285. else
  2286. sprintf (smGD.clientPath, "%s/%s",
  2287. session_dir, SM_CLIENT_FILE);
  2288. } else {
  2289. /*
  2290. * The alt_dir did not have a session database.
  2291. * Create a directory and load the system defaults
  2292. */
  2293. if ((mkdir (session_dir, 0000)) == 0)
  2294. (void) chmod (session_dir, 0755);
  2295. else {
  2296. PrintErrnoError(DtError,
  2297. smNLS.cantCreateDirsString);
  2298. return (False);
  2299. }
  2300. SetSysDefaults ();
  2301. }
  2302. } else {
  2303. /*
  2304. * The directory for the specified session exists
  2305. * but it doesn't have any client databases. Start
  2306. * a new user session. If a user wants a session
  2307. * with no apps, they should create a zero-length
  2308. * session database.
  2309. */
  2310. SetSysDefaults ();
  2311. }
  2312. XtFree(db_file1);
  2313. XtFree(db_file2);
  2314. return (True);
  2315. }
  2316. void
  2317. SmExit (
  2318. int exitStatus)
  2319. {
  2320. /* JET - needed to rework this to avoid exiting before we are
  2321. * *really* ready to
  2322. */
  2323. if (smGD.ExitComplete)
  2324. {
  2325. if (smXSMP.saveState.saveComplete &&
  2326. smXSMP.saveState.shutdown &&
  2327. !smXSMP.saveState.shutdownCanceled)
  2328. XSMPExit ();
  2329. exit(exitStatus);
  2330. }
  2331. else
  2332. return;
  2333. }
  2334. void
  2335. SetSIGPIPEToDefault (void)
  2336. {
  2337. struct sigaction pipeSig;
  2338. sigemptyset(&pipeSig.sa_mask);
  2339. pipeSig.sa_flags = 0;
  2340. pipeSig.sa_handler = SIG_DFL;
  2341. (void) sigaction(SIGPIPE, &pipeSig, (struct sigaction *) NULL);
  2342. }