Article Title           : sgi logout problem
Creation Date           : unknown
Author                  : unknown
Last Update             : 6-1-93
Last Update By          : NCD Technical Support
Expiration Rules        : 
=============================================================================

I've seen several instances over the last few months where, when
using SGI's host-based session management scheme, users are unable
to logout of NCDs using SGI's provided scheme - when they select
logout, nothing happens.  I finally had a little time to track this
down after a demo install on an SGI system.  Here's what I came up with:

1. IRIX v4.0.1 doesn't have this problem, but v4.0.5 does.  Don't
   know about releases in the middle, if there were any.

2. SGI's default XDM configuration uses display classes to invoke
   a different Xsession if you're on a remote display than if you're
   using the SGI workstation.  You can see this in 
   /usr/lib/X11/xdm/xdm-config.  The Xsession-remote script is invoked
   when you use a remote display.

3. After invoking 4Dwm, a terminal emulator, and the "tool chest"
   application launcher, a process caller "reaper" is invoked as
   the last thing in Xsession-remote.  A quick scan of the reaper's
   man page tells you that all it does is put a property on the
   display's root window called _SGI_SESSION_PROPERTY, then waits
   for that property to go away (and then shoots the user's processes).

4. The script /usr/bin/X11/endsession is in the business of removing
   _SGI_SESSION_PROPERTY from the display's root window.  endsession
   gets invoked from a tool chest menu pick.  endsession goes as
   follows....... 

#!/bin/sh
if [ $DISPLAY ]; then
    really=`/usr/bin/X11/xconfirm -geom 350x93 -header Confirm -icon question
-string(?) "Do you really want to log out?"`
    if [ "$really" = Yes ]; then
        PROP_DISPLAY=`expr $DISPLAY : '\(.*\).[0-9]' \| $DISPLAY`
        /usr/bin/X11/xprop -display $PROP_DISPLAY -root -remove _SGI
_SESSION_PROPERTY
    fi
else
    echo 'endsession: $DISPLAY not defined'
fi

The problem is the expr command, which seems to be meant to lop off a
[.screen] from the end of $DISPLAY actually lops off part of the
node name *if* the node name part of the display has a numeric in it.
Specifically, what seems to happen is it returns characters from
$DISPLAY through the 2nd character to the left of the first numeric
it encounters:  Example:

DISPLAY=ncd2:0.0
PROP_DISPLAY=nc

xprop gives up (no display by that name that I can find, buddy),
therefore _SGI_SESSION_PROPERTY remains, ergo no logout (that's
Latin for "stick around, kid"  :)  ).

Interestingly enough, I can't make that expr statement return me a
"wrong" answer under SunOS's sh.  The man page for expr suggests
that it should work the way it does on the SGI, but I'll leave
that to better shell hackers than I to decide.

Anyway, the customer whose machine I used to discover all the
details is a ksh devotee.  He solved the problem by making
endsession a kshell, and changing line in question to:
PROP_DISPLAY=${DISPLAY%%.[0-9]}
which effectively gets rid of .screen.

I'd do it like this:
PROP_DISPLAY=`echo $DISPLAY | sed -e 's/.[0-9]$//'`

Another fix is to change the above from:


	'\(.*\).[0-9]' 

to

	'\(.*\)\.[0-9]'


Other approaches, of course, are to:
- blow off the whole SGI user environment and use NCDwm/NCDlauncher
- avoid using numerics in the NCD's node names

