source: trunk/athena/bin/session/end_session.sh @ 6464

Revision 6464, 3.8 KB checked in by probe, 32 years ago (diff)
Use /bin/athena/tcsh, not /bin/csh, in order to query the $uid variable.
Line 
1#!/bin/sh
2#
3#  end_session - Sends hangup signal to all session_gate processes
4#
5#       $Source: /afs/dev.mit.edu/source/repository/athena/bin/session/end_session.sh,v $
6#       $Header: /afs/dev.mit.edu/source/repository/athena/bin/session/end_session.sh,v 1.3 1993-03-12 19:07:49 probe Exp $
7#       $Author: probe $
8#
9
10MAX_PASSES=10
11pass_num=0
12DELAY_TIME=6
13
14trap "exit 6" 2 3
15
16cd /
17
18#  Process the argument list.
19
20force=0
21while [ $# != 0 ]; do
22        case $1 in
23        "-f" | "-force" )
24                force=1
25                ;;
26        * )
27                echo "usage: $0 [-force]"
28                exit 1
29                ;;
30        esac
31        shift
32done
33
34#  Name of file containing process ID of the session_gate process.
35
36## This is not needed, thanks to the T-shell (/bin/athena/tcsh) $uid variable.
37#awkcmd='BEGIN {found=0;} ($1=="'$USER'" && found==0) {print $3; found=1;}'
38#uid=`awk -F: "$awkcmd" < /etc/passwd`
39#if [ x"$uid" = x"" ]; then
40#       fmt << EOF
41#************************************************************
42#end_session:
43#Cannot find you in this machine's password file; therefore
44#your session_gate process id file cannot be found.  I suggest
45#you reboot your workstation to fix this problem.
46#************************************************************
47#EOF
48#       exit 5
49#fi
50
51uid=`/bin/athena/tcsh -fc 'echo $uid'`
52pid_file=/tmp/session_gate_pid.$uid
53
54if [ $force = 1 ]; then
55
56    # If using standard startup, permit time for session_gate to start up.
57
58    sleep 2
59
60    #  Kill session_gate processes by brute force.
61
62    pids="`/bin/ps uxc | /bin/awk '($10 == "session_gate") { print $2 }'`"
63
64    if [ x"$pids" = x"" ]; then
65        echo "************************************************************"
66        echo "No session_gate processes are running -- you are probably"
67        echo "using a customized session file.  End your session by"
68        echo "terminating the last process you started in your session"
69        echo "file."
70        echo "************************************************************"
71        exit 2
72    else
73        /bin/kill -HUP $pids
74    fi
75
76else
77
78    #  Check for readability of the file containing the process ID of the
79    #  session_gate process.
80
81    # First, loop a while, until we can read the file, or until we time out.
82    while [ ! -r $pid_file ] && [ `expr $pass_num '<' $MAX_PASSES` = 1 ]; do
83        sleep $DELAY_TIME
84        pass_num=`expr 1 + $pass_num`
85    done
86    sleep 2
87
88    if [ ! -r $pid_file ]; then
89        echo "************************************************************"
90        echo "                Your session is still running."
91        echo ""
92        echo "end_session failed because:"
93        echo "  The file $pid_file doesn't exist or is"
94        echo "  not readable."
95        echo ""
96        echo "If you are running a .xsession file other than the system"
97        echo "default, and that file does not invoke the program"
98        echo "'session_gate', then end_session will not work.  You should"
99        echo "end your session by terminating the last process you started"
100        echo "in your .xsession file."
101        echo ""
102        echo "If you did run session_gate, then the file was somehow"
103        echo "deleted.  Try typing 'end_session -force' (this time only)"
104        echo "to end your session."
105        echo "************************************************************"
106        exit 3
107    fi
108
109    #  Read the process ID and attempt to kill the process.
110
111    pids="`/bin/cat $pid_file`"
112    problem=0
113    if [ x"$pids" = x"" ]; then
114        problem=1
115    fi
116    for pid in $pids ; do
117        case $pid in
118        -* | 0 | 1 )
119            problem=1
120            ;;
121        * )
122            /bin/kill -HUP $pid > /dev/null 2>&1
123            status=$?
124            case $status in
125                0 | 1 )
126                    # process killed or not found
127                    ;;
128                * )
129                    problem=1
130                    ;;
131            esac
132            ;;
133        esac
134    done
135
136    if [ $problem = 1 ]; then
137        echo "************************************************************"
138        echo "end_session failed because:"
139        echo "  The file $pid_file may have been modified."
140        echo ""
141        echo "Try typing 'end_session -force' (this time only) to end your"
142        echo "session."
143        echo "************************************************************"
144        exit 4
145    fi
146
147fi
148exit 0
Note: See TracBrowser for help on using the repository browser.