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

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