Hi, all.

Blinny and I have been picking at an rc.d script over the past few weeks
to handle killing stale user processes that may have lingered from a
previous login when users login again, as well as to prompt if the user
is logged in elsewhere and offer to kill off her other session.

Attached is the result of the effort.  I'd like to put it out there for
others who may be interested to test.  Ultimately, if this works well,
we may wrap the whole thing in lts.conf-param toggle, so admins can
enable this feature or disable it as they see fit.  As the script
currently stands, it will never be enabled by default, as there exist
environments where users may not want their processes from a previous
session killed.

If you try it, please give feedback.

The script should be placed in:

/opt/ltsp/i386/usr/lib/ldm/rc.d/S15userLoginCheck

and then, reroll the image.

NOTE:  Older versions of ldm, may have the rc.d directory
in:  /opt/ltsp/i386/usr/share/ldm/rc.d/

Enjoy,

-Gadi


-- 
--------------------------------------------------------
Gideon Romm | Proud LTSP Developer
[EMAIL PROTECTED]

Support LTSP!  Buy your hardware at:

        www.DisklessWorkstations.com
        www.DisklessThinClients.com 
 
(use coupon code: LTSP5P for 5% off thin clients from DisklessThinClients.com)
#
# sourced with .
#
# Script to check if user is already logged in and offers to kill all of his
# procs (asside from sshd and SENTINEL related ones) before continuing
#

userProcs=$(ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} '/usr/bin/pgrep -u ${USER}')

# Since we use a socket, by taking out the newest sshd proc from the kill list,
# we should preserve our socket.
sshdProc=$(ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} '/usr/bin/pgrep -n -u $USER 
sshd')

sshdChildren=$(ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} "/usr/bin/pgrep -P 
$sshdProc")

# Let's check if there is an old session or simply stale prcoesses
allsshdProcs=$(ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} '/usr/bin/pgrep -u $USER 
sshd')
oldSessions=0
for p in $allsshdProcs; do
  if [ "$p" != "$sshdProc" ]; then
    oldSessions=$(($oldSessions+1))
  fi 
done

# Now, let's make sure not to kill "screen"s on the server or any of *their* 
kids
screenProcs=$(ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} '/usr/bin/pgrep -u $USER 
screen')
screenProcChildren=""
for s in $screenProcs; do
  thisScreenProcChildren=$(ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} 
"/usr/bin/pgrep -P $s")
  screenProcChildren="$screenProcChildren $thisScreenProcChildren"
done

# Take out sshd and kids
procs=
for i in $userProcs; do
  match=
  for j in $sshdProc $sshdChildren $screenProcs $screenProcChildren; do
    [ "$i" = "$j" ] && match=1 
  done
  [ -z "$match" ] && procs="$procs $i"
done

procsCheck=$(echo $procs|sed -e 's/ //g')

if [ -n "$procsCheck" ]; then
  if [ $oldSessions -gt 0 ]; then
    #zenity --question --text="There appear to be processes already running for 
this user.  Would you like to kill these processes and continue logging in?"
    xmessage -center -buttons "Kill Current Session":0,"Cancel":5 The system 
thinks you are logged in elsewhere.  Would you like to close the other session 
and begin anew here?
    ret=$?
  else
    ret=0
  fi

  if [ "$ret" = 0 ]; then
    ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} "/bin/kill $procs"
    sleep 1 
    ssh -X -S ${LDM_SOCKET} ${LDM_SERVER} "/bin/kill -9 $procs"
  else
    if [ "$ret" = 5 ]; then
      /bin/kill -9 ${PPID}
    fi
  fi
fi
-------------------------------------------------------------------------
Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW!
Studies have shown that voting for your favorite open source project,
along with a healthy diet, reduces your potential for chronic lameness
and boredom. Vote Now at http://www.sourceforge.net/community/cca08
_____________________________________________________________________
Ltsp-discuss mailing list.   To un-subscribe, or change prefs, goto:
      https://lists.sourceforge.net/lists/listinfo/ltsp-discuss
For additional LTSP help,   try #ltsp channel on irc.freenode.net

Reply via email to