Use FreeBSD-specific invocation of /bin/ps
[oweals/cde.git] / cde / programs / dtlogin / config / Xsession.src
1 XCOMM! /bin/ksh
2 XCOMM ##########################################################################
3 XCOMM
4 XCOMM   Xsession
5 XCOMM
6 XCOMM   Common Desktop Environment (CDE)
7 XCOMM
8 XCOMM   Configuration script for the Login Manager
9 XCOMM
10 XCOMM   (c) Copyright 1996 Digital Equipment Corporation.
11 XCOMM   (c) Copyright 1993,1994,1996 Hewlett-Packard Company.
12 XCOMM   (c) Copyright 1993,1994,1996 International Business Machines Corp.
13 XCOMM   (c) Copyright 1993,1994,1996 Sun Microsystems, Inc.
14 XCOMM   (c) Copyright 1993,1994,1996 Novell, Inc. 
15 XCOMM   (c) Copyright 1996 FUJITSU LIMITED.
16 XCOMM   (c) Copyright 1996 Hitachi.
17 XCOMM
18 XCOMM       ************** DO NOT EDIT THIS FILE **************
19 XCOMM
20 XCOMM   CDE_INSTALLATION_TOP/bin/Xsession is a factory-default file and will
21 XCOMM   be unconditionally overwritten upon subsequent installation.
22 XCOMM   Modification is discouraged.
23 XCOMM
24 XCOMM   $TOG: Xsession.src /main/19 1999/03/30 09:38:50 mgreess $
25 XCOMM
26 XCOMM   Usage: $0 [-session session_name]
27 XCOMM
28 XCOMM ##########################################################################
29
30 #define HASH #
31
32 #ifdef sun 
33   HASH 
34   HASH Set OPENWINHOME 
35   HASH 
36   if [ -z "$OPENWINHOME" ]
37   then
38       export OPENWINHOME="/usr/openwin"
39   fi
40 #endif
41
42
43 #if 0
44 /*
45  * Platform specific definitions
46  *
47  * cpp_XINITUSER - user's xinit startup file
48  * cpp_MAIL - system mail file
49  * cpp_HELLO - dthello command line
50  * cpp_XDMSYS - xdm system session file
51  */
52 #endif
53
54 #if defined (_AIX)
55 #  define cpp_XINITUSER "$HOME/.xinitrc"
56 #  define cpp_MAIL "/var/spool/mail/$USER"
57 #elif defined (__hpux)
58 #  define cpp_XDMSYS "/usr/lib/X11/xdm/sys.xsession"
59 #elif defined (sun)
60 #  define cpp_MAIL "/var/mail/$USER"
61 #endif
62
63 #ifdef __osf__
64 #  undef cpp_MAIL
65 #  define cpp_MAIL "/usr/spool/mail/$USER"
66 #endif
67
68 #if defined (__hpux) && defined (BLS)
69 #  undef cpp_HELLO
70 #  define cpp_HELLO "$DT_BINPATH/dthello -file /etc/copyright -file $HOME/.dtlogininfo &"
71 #endif
72
73 #ifdef linux
74 #  define cpp_MAIL "/var/spool/mail/$USER"
75 #  define cpp_XDIR "/usr/bin"
76 #  define cpp_XINITUSER "$HOME/.xinitrc"
77 #  define cpp_XDMSYS "/etc/X11/Xsession"
78 #  undef cpp_HELLO
79 #  define cpp_HELLO "$DT_BINPATH/dthello -file /usr/dt/copyright &"
80 #endif
81
82
83 #if 0
84 /*
85  * Fallback definitions
86  */
87 #endif
88
89 #if !defined (cpp_XINITUSER)
90 #  define cpp_XINITUSER "$HOME/.x11start"
91 #endif
92
93 #if !defined (cpp_MAIL)
94 #  define cpp_MAIL "/usr/mail/$USER"
95 #endif
96
97 #if !defined (cpp_HELLO)
98 #  define cpp_HELLO "$DT_BINPATH/dthello &"
99 #endif
100
101 #if !defined (cpp_XDMSYS)
102 #  define cpp_XDMSYS "/usr/lib/X11/xdm/Xsession"
103 #endif
104
105 XCOMM ##########################################################################
106 XCOMM 
107 XCOMM 
108 XCOMM   This script starts the user's session. It searches for one of three
109 XCOMM   types of startup mechanisms, in the following order:
110 XCOMM 
111 XCOMM     DT     existence of CDE DT Session Manager on the system
112 XCOMM     XDM    "$HOME/.xsession" (executable)
113 XCOMM     xinit  cpp_XINITUSER  (executable)
114 XCOMM 
115 XCOMM   If none of these startup mechanisms exist, a default window manager
116 XCOMM   and terminal emulator client are started.
117 XCOMM 
118 XCOMM ##########################################################################
119
120 XCOMM
121 XCOMM Variables must be explicitly exported
122 XCOMM 
123 set +a
124
125 XCOMM ##########################################################################
126 XCOMM 
127 XCOMM   Initialize session startup logging
128 XCOMM 
129 XCOMM ##########################################################################
130
131   exec >/dev/null 2>/dev/null
132
133   LOGDIR=$HOME/.dt
134   LOGFILENAME=$LOGDIR/startlog
135   MSGLOGFILENAME=$LOGDIR/errorlog
136   
137   if [ ! -d $LOGDIR ]; then
138     mkdir $LOGDIR
139     if [ -d $LOGDIR ]; then
140       chmod 755 $LOGDIR
141     fi
142   fi
143
144   [ -f $LOGFILENAME.older ] && rm -f $LOGFILENAME.older
145   [ -f $LOGFILENAME.old ] && mv -f $LOGFILENAME.old $LOGFILENAME.older
146   [ -f $LOGFILENAME ] && mv -f $LOGFILENAME $LOGFILENAME.old
147   touch $LOGFILENAME
148   [ ! -f $MSGLOGFILENAME ] && touch $MSGLOGFILENAME
149
150   if [ -w $LOGFILENAME ]; then
151     exec >>$LOGFILENAME 2>&1
152   fi
153
154
155   Log()
156   {
157     echo "--- $1" >>$LOGFILENAME 2>&1
158   }
159
160   Log "$(date)"
161   Log "$0 starting..."
162
163 XCOMM ##########################################################################
164 XCOMM 
165 XCOMM   Global environment section
166 XCOMM 
167 XCOMM    DT pre-sets the following environment variables for each user.
168 XCOMM    
169 XCOMM     (internal)
170 XCOMM 
171 XCOMM     DISPLAY      set to the value of the first field in the Xservers file.
172 XCOMM     HOME         set to the user's home directory (from /etc/passwd)
173 XCOMM     LANG         set to the display's current NLS language (if any)
174 XCOMM     LC_ALL       set to the value of $LANG
175 XCOMM     LOGNAME      set to the user name
176 XCOMM     PATH         set to the value of the Dtlogin "userPath" resource
177 XCOMM     USER         set to the user name
178 XCOMM     SHELL        set to the user's default shell (from /etc/passwd)
179 XCOMM     TZ           set to the value of the Dtlogin "timeZone" resource
180 XCOMM 
181 XCOMM
182 XCOMM     (Xsession)
183 XCOMM 
184 XCOMM     TERM         set to xterm
185 XCOMM     EDITOR       set to the default editor
186 XCOMM     KBD_LANG     set to the value of $LANG for certain languages
187 XCOMM     MAIL         set to cpp_MAIL
188 XCOMM 
189 XCOMM 
190 XCOMM    Three methods are available to modify or add to this list depending 
191 XCOMM    on the desired scope of the resulting environment variable. 
192 XCOMM    
193 XCOMM     1. X server and/or all users on a display       (Xconfig file)
194 XCOMM     2. all users on a display                       (Xsession file)
195 XCOMM     3. individual users                             (.dtprofile file)
196 XCOMM 
197 XCOMM    See DT on-line help, the DT Users Guide, or the Dtlogin(1X) man
198 XCOMM    page for details on setting environment variables.
199 XCOMM     
200 XCOMM     
201 XCOMM ##########################################################################
202
203   [ -z "$EDITOR" ] && EDITOR=CDE_INSTALLATION_TOP/bin/dtpad
204   [ -z "$MAIL" ] && MAIL=cpp_MAIL
205   [ -z "$LANG" ] && LANG="C"
206   TERM=dtterm
207   SESSION_SVR=`hostname`
208
209   export PATH EDITOR MAIL TERM SESSION_SVR LANG
210
211 #if defined (_AIX) && defined (AIXV4)
212 XCOMM
213 XCOMM Clear the LFT message locale override if set
214 XCOMM
215 if [ "$LC_MESSAGES" = "C@lft" ]
216 then
217   unset LC_MESSAGES
218 fi
219 #endif
220
221 #if defined (__osf__)
222   HASH
223   HASH Set XFILESEARCHPATH if necessary
224   HASH
225   if [ -z "$XFILESEARCHPATH" ]
226   then
227       export XFILESEARCHPATH="%D"
228   fi
229   HASH
230   HASH check if network is configured. If not, set environment variable
231   HASH so that tooltalk will use localhost/loopback rather than system
232   HASH name
233   RCMGR=/usr/sbin/rcmgr
234   NUM_NETCONFIG=`$RCMGR get NUM_NETCONFIG`
235   if [ "$NUM_NETCONFIG" = '' -o "$NUM_NETCONFIG" = 0 ]; then
236         export DTNONETWORK=true
237   fi
238 #endif
239  
240 #if defined (__hpux)
241   HASH
242   HASH Set the keyboard language if necessary...
243   HASH
244   if [ ! -z "$LANG" ]
245   then
246       case $LANG in
247             bulgarian | czech   | hebrew | hungarian | \
248             japanese  | korean  | polish | rumanian  | \
249             russian   | serbocroatian) 
250                         KBD_LANG=$LANG
251                         export KBD_LANG;;
252            
253              chinese-t) KBD_LANG=t_chinese
254                         export KBD_LANG;;
255              chinese-s) KBD_LANG=s_chinese
256                         export KBD_LANG;;
257             
258              *);; 
259      esac
260   fi
261 #endif
262
263   HASH
264   HASH Locate configuration file directories
265   HASH
266   XDIR=XPROJECTROOT/bin
267   DT_BINPATH=CDE_INSTALLATION_TOP/bin
268   DT_INSTALL_CONFIG=CDE_INSTALLATION_TOP/config
269   DT_CONFIG=CDE_CONFIGURATION_TOP/config
270   DT_CONFIG_PATH="$DT_INSTALL_CONFIG $DT_CONFIG"
271
272 XCOMM ##########################################################################
273 XCOMM
274 XCOMM  Default desktop component configuration variable settings
275 XCOMM
276 XCOMM  This section sets the default value for variables controlling
277 XCOMM  some desktop components.
278 XCOMM
279 XCOMM ##########################################################################
280
281   HASH 
282   HASH Input method server startup
283   HASH 
284   if [ -z "$DTSTARTIMS" ]; then
285      DTSTARTIMS=True
286   fi
287
288   if [ "$DTSTARTIMS" = "False" ]; then
289      unset DTSTARTIMS
290   fi
291
292   HASH 
293   HASH Default desktop screen saver action list 
294   HASH  
295   export DTSCREENSAVERLIST="StartDtscreenSwarm StartDtscreenQix \
296     StartDtscreenFlame StartDtscreenHop StartDtscreenImage StartDtscreenLife \
297     StartDtscreenRotor StartDtscreenPyro StartDtscreenWorm StartDtscreenBlank"
298
299   HASH 
300   HASH Session startup clients and args
301   HASH 
302   if [ "$SESSIONTYPE" = "altDt" ]; then
303       dtstart_session[0]="$SDT_ALT_SESSION"
304       dtstart_hello[0]="$SDT_ALT_HELLO"
305   else
306       DTSESSION_ARGS=""
307       if [ $# -ge 2 ]; then
308           if [ "$1" = "-session" ]; then
309               DTSESSION_ARGS="$1 $2"
310           fi
311       fi
312       dtstart_session[0]="$DT_BINPATH/dtsession $DTSESSION_ARGS"
313       dtstart_hello[0]=cpp_HELLO
314   fi
315   dtstart_session[1]="$HOME/.xsession"
316   dtstart_session[2]=cpp_XINITUSER
317   dtstart_session[3]="$XDIR/xterm -geometry 80x24+10+10"
318   dtstart_hello[1]="$XDIR/xsetroot -default &"
319   dtstart_searchpath="$DT_BINPATH/dtsearchpath -ksh"
320   dtstart_ttsession="$DT_BINPATH/ttsession -s"
321   dtstart_dtdbcache="$DT_BINPATH/dtdbcache -init"
322   HASH
323   HASH dtdbcache file's directory should match
324   HASH _DTDTSMMTEMPDIR in DtSvc/DtUtil1/DtsMM.h
325   HASH
326 #ifdef __osf__
327   dtdbcacherm="rm -f /var/tmp/dtdbcache_$DISPLAY"
328 #else
329   dtdbcacherm="rm -f /tmp/dtdbcache_$DISPLAY"
330 #endif
331   dtstart_appgather="$DT_BINPATH/dtappgather &"
332 #if defined(USL) || defined(sun) || defined(__uxp__)
333   dtstart_dsdm="$DT_BINPATH/dsdm &"
334 #endif
335
336   xdmstart_session[0]="$HOME/.xsession"
337   xdmstart_session[1]=cpp_XDMSYS
338   xdmstart_session[2]="xterm -geometry 80x24+10+10 -ls"
339   xdmstart_hello="$XDIR/xsetroot -default &"
340
341
342   SESSIONLOGDIR=$LOGDIR/sessionlogs
343   SESSIONLOGFILENAME="$SESSIONLOGDIR/$SESSION_SVR"_DISPLAY=$DISPLAY
344
345   if [ ! -d $SESSIONLOGDIR ]; then
346     mkdir $SESSIONLOGDIR
347     if [ -d $SESSIONLOGDIR ]; then
348       chmod 755 $SESSIONLOGDIR
349     fi
350   fi
351
352   touch $SESSIONLOGFILENAME
353
354   if [ -w $SESSIONLOGFILENAME ]; then
355       dtstart_sessionlogfile="$SESSIONLOGFILENAME"
356   else
357       dtstart_sessionlogfile="/dev/null"
358   fi
359
360   rm -f $SESSIONLOGFILENAME
361
362 #ifdef sun
363   if [ "$DTXSERVERLOCATION" != "remote" ]
364   then
365   HASH
366   HASH Start fallback console
367   HASH
368      if [ -x $XDIR/fbconsole ]
369      then
370         $XDIR/fbconsole &
371      fi
372   fi
373 #endif
374
375 #define cpp_Xsession
376 #include "_common.ksh.src"
377 #undef cpp_Xsession
378
379 #if defined (__osf__)
380 XCOMM
381 XCOMM Bring up the sysman checklist if it hasn't been run before
382 XCOMM
383   if [ -f /usr/sbin/start_checklist ]
384   then
385       Log "Starting the checklist setup"
386       /usr/sbin/start_checklist&
387   fi
388 #endif
389
390 XCOMM ##########################################################################
391 XCOMM 
392 XCOMM   Source user's desktop profile
393 XCOMM 
394 XCOMM   This section determines if the user has a desktop profile in their
395 XCOMM   home directory. If not, the desktop default profile is copied to
396 XCOMM   the home directory. The desktop profile is then sourced. The purpose
397 XCOMM   is to incorporate any per-user/per-session environment customizations
398 XCOMM   and thereby propagate them to applications and desktop components.
399 XCOMM 
400 XCOMM ##########################################################################
401
402
403   DTSYSPROFILE=sys.dtprofile
404   DTPROFILE=.dtprofile
405
406   if [ ! -f $HOME/$DTPROFILE ]; then
407     for i in $DT_CONFIG_PATH
408     do
409       if [ -f $i/$DTSYSPROFILE ]; then
410         /usr/bin/awk '
411           BEGIN {printit=1}
412           /SYSPROFILE COMMENT START/ {printit=0; next}
413           /SYSPROFILE COMMENT END/ {printit=1; next}
414           printit==1 {print}' <$i/$DTSYSPROFILE >$HOME/$DTPROFILE
415         /bin/chmod 755 $HOME/$DTPROFILE
416         break
417       fi
418     done
419   fi
420
421   HASH
422   HASH source the .dtprofile.
423   HASH
424   if [ -f $HOME/$DTPROFILE ]; then
425     dtprofile_errors=`/bin/ksh -n $HOME/$DTPROFILE 2>&1`
426     if [ "0" = "$?" ]; then
427       Log "sourcing $HOME/$DTPROFILE..."
428       . $HOME/$DTPROFILE
429     else
430       Log "not sourcing $HOME/$DTPROFILE due to errors..."
431       Log "$dtprofile_errors"
432     fi
433   fi
434
435
436 XCOMM ##########################################################################
437 XCOMM 
438 XCOMM  External Xsession processing section
439 XCOMM 
440 XCOMM  This section searches the Xsession.d subdirectory and sources
441 XCOMM  the files contained therein.  The purpose is to set up any
442 XCOMM  per-user/per-session environment customizations and thereby propagate
443 XCOMM  them to applications and desktop components.
444 XCOMM 
445 XCOMM ##########################################################################
446
447   DT_XSESSION_DIR=Xsession.d
448
449   for i in $DT_CONFIG_PATH
450   do
451     if [[ -d $i/$DT_XSESSION_DIR ]]; then
452       HASH 
453       HASH Run custom Xsession scripts for this session.
454       HASH 
455       for SCRIPT in $(ls $i/$DT_XSESSION_DIR); do
456         if [ -x $i/$DT_XSESSION_DIR/$SCRIPT -a \
457             \( ! -d $i/$DT_XSESSION_DIR/$SCRIPT \) ]; then
458                Log "sourcing $i/$DT_XSESSION_DIR/$SCRIPT..."
459                . $i/$DT_XSESSION_DIR/$SCRIPT
460           fi
461       done
462     fi
463   done
464
465
466 XCOMM ##########################################################################
467 XCOMM 
468 XCOMM   Startup section.
469 XCOMM      
470 XCOMM   Note: The ksh syntax ${parameter%% *} is used when appropriate to
471 XCOMM       remove any command line options that may have been included
472 XCOMM       in the definition of a DT executable below.
473 XCOMM      
474 XCOMM ##########################################################################
475
476 XCOMM 
477 XCOMM Return first command in array named by $1 that is executable
478 XCOMM 
479 GetFirst()
480 {
481   let i=0
482   while true; do
483     eval "cmd=\${$1[$i]}"
484     [ -z "$cmd" ] && break
485     [ -x "${cmd%% *}" ] && echo "$cmd" && break
486     Log "could not start $cmd"
487     let i=$i+1
488   done
489 }
490
491 XCOMM 
492 XCOMM Start first command in array named by $1 that is executable. If
493 XCOMM $2 is 'eval', command result will be 'eval'ed. 
494 XCOMM 
495 StartFirst()
496 {
497   first=$(GetFirst $1)
498   if [ ! -z "$first" ]; then
499     Log "starting $first"
500     if [ "$2" = "eval" ]; then
501       eval `eval "PATH=$DT_BINPATH:$PATH $first"`
502     else
503       eval "PATH=$DT_BINPATH:$PATH $first"
504     fi
505   fi
506 }
507
508   HASH 
509   HASH Prepare for session startup
510   HASH 
511
512   if [ "$DTSOURCEPROFILE" = "true" ]
513   then
514     case ${SHELL##*/} in
515        sh | ksh | dtksh) shellprofile="$HOME/.profile";;
516        bash) shellprofile="$HOME/.bash_profile";;
517        csh | tcsh) shellprofile="$HOME/.login";;
518        *) Log "non-standard shell $SHELL"
519     esac
520   fi
521
522   if [ "$shellprofile" -a ! -f "$shellprofile" ]
523   then
524     Log "could not read $shellprofile"
525     unset shellprofile
526   fi
527
528   if [ "$SESSIONTYPE" = "xdm" ]; then
529     startup=$(GetFirst xdmstart_session)    # get xdm session client
530     StartFirst xdmstart_hello               # start xdm hello client
531   else
532     startup=$(GetFirst dtstart_session)     # get desktop session client
533     StartFirst dtstart_hello                # start desktop hello client
534     StartFirst dtstart_searchpath eval      # setup desktop search paths
535
536     tooltalk=$(GetFirst dtstart_ttsession)  # get tooltalk client
537     dtdbcache=$(GetFirst dtstart_dtdbcache) # get dtdbcache client
538
539 #if defined(USL) || defined(sun) || defined(__uxp__)
540     if [ -z "$SDT_NO_DSDM" ]; then
541         StartFirst dtstart_dsdm             # start drag and drop proxy
542     fi
543 #endif
544     StartFirst dtstart_appgather            # setup session applications
545   fi
546
547   HASH 
548   HASH Start the session.
549   HASH 
550
551   if [ $shellprofile ]; then
552     Log "execing $startup using $shellprofile..."
553
554     case ${SHELL##*/} in
555
556       sh | bash | ksh | dtksh)
557         dotprofile_errors=`$SHELL -n $shellprofile 2>&1`
558         if [ "0" = "$?" ]; then
559           source_profile=". $shellprofile"
560           source_login="source $shellprofile"
561         else
562           Log "parse errors found in $shellprofile..."
563           Log "$dotprofile_errors"
564           source_profile="echo 'not execing $shellprofile due to errors'"
565           source_login="echo 'not execing $shellprofile due to errors'"
566         fi;;
567            
568       *)
569         source_profile=". $shellprofile"
570         source_login="source $shellprofile";; 
571     esac
572
573   else
574     Log "execing $startup..."
575
576     source_profile="echo 'not execing $HOME/.profile (see $HOME/.dtprofile)'"
577     source_login="echo 'not execing $HOME/.login (see $HOME/.dtprofile)'"
578   fi
579
580   if [ -z "$dtdbcache" ]; then
581         dtdbcache="echo could not start $dtstart_dtdbcache"
582   fi
583
584   export DT=true;
585   case ${SHELL##*/} in
586       sh | bash) $SHELL -c "$source_profile; \
587                            unset DT; \
588                            $dtdbcache; \
589                            PATH=/usr/dt/bin:\$PATH $tooltalk;   \
590                            $startup > $dtstart_sessionlogfile 2>&1" ;;
591
592       ksh | dtksh) $SHELL -c "$source_profile; \
593                            unset DT; \
594                            $dtdbcache; \
595                            PATH=/usr/dt/bin:\$PATH $tooltalk;\
596                            $startup >| $dtstart_sessionlogfile 2>&1" ;;
597
598       csh | tcsh) $SHELL -c "unsetenv _ PWD;       \
599                            $source_login; \
600                            unsetenv DT;          \
601                            $dtdbcache; \
602                            (set path = ( $DT_BINPATH \$path ); $tooltalk ); \
603                            $startup  >&! $dtstart_sessionlogfile" ;;
604
605       *) unset DT
606          $dtdbcache
607          StartFirst dtstart_ttsession
608          $startup >| $dtstart_sessionlogfile 2>&1 ;;
609   esac
610
611 $dtdbcacherm            # remove the actions/datatypes cachefile
612
613 XCOMM ####################         eof      #################################