SmGlobals.c 67 KB

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