source: trunk/athena/bin/session/end_session @ 2050

Revision 2050, 2.8 KB checked in by raeburn, 35 years ago (diff)
Initial revision
Line 
1#! /bin/csh -f
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,v $
6#       $Header: /afs/dev.mit.edu/source/repository/athena/bin/session/end_session,v 1.1 1989-08-15 16:32:27 raeburn Exp $
7#       $Author: raeburn $
8#
9
10
11#  Process the argument list.
12
13while ( $#argv != 0 )
14        switch ($argv[1])
15
16            case "-f":
17            case "-force":
18                set force
19                breaksw
20
21            default:
22                goto usage
23
24        endsw
25        shift argv
26end
27
28
29#  Name of file containing process ID of the session_gate process.
30
31set pid_file=/tmp/session_gate_pid.$uid
32
33
34if ($?force) then
35
36    #  Kill session_gate processes by brute force.
37
38    set pids = `/bin/ps uxc | /bin/awk '($10 == "session_gate") { print $2 }'`
39
40    if ($#pids == 0)  then
41        echo "************************************************************"
42        echo "No session_gate processes are running -- you are probably"
43        echo "using a customized session file.  End your session by"
44        echo "terminating the last process you started in your session"
45        echo "file."
46        echo "************************************************************"
47        exit 2
48    else
49        kill -HUP $pids
50    endif
51
52else
53
54    #  Check for readability of the file containing the process ID of the
55    #  session_gate process.
56
57    if (! -r $pid_file) then
58        echo "************************************************************"
59        echo "                Your session is still running."
60        echo ""
61        echo "end_session failed because:"
62        echo "  The file $pid_file doesn't exist or is"
63        echo "  not readable."
64        echo ""
65        echo "If you are running a .xsession file other than the system"
66        echo "default, and that file does not invoke the program"
67        echo "'session_gate', then end_session will not work.  You should"
68        echo "end your session by terminating the last process you started"
69        echo "in your .xsession file."
70        echo ""
71        echo "If you did run session_gate, then the file was somehow"
72        echo "deleted.  Try typing 'end_session -force' (this time only)"
73        echo "to end your session."
74        echo "************************************************************"
75        exit 3
76    endif
77
78    #  Read the process ID and attempt to kill the process.
79
80    set pids = `/bin/cat $pid_file`
81    if ($#pids == 0) set problem
82    foreach pid ($pids)
83        if ($pid =~ -*) then            #  Don't kill negative pid's
84            set problem
85        else
86            /bin/kill -HUP $pid >& /dev/null
87            if ($status > 1) set problem
88        endif
89    end
90
91    if ($?problem) then
92        echo "************************************************************"
93        echo "end_session failed because:"
94        echo "  The file $pid_file has been modified."
95        echo ""
96        echo "Try typing 'end_session -force' (this time only) to end your"
97        echo "session."
98        echo "************************************************************"
99        exit 4
100    endif
101
102endif
103exit 0
104
105usage:
106echo "usage:  $0 [-force]"
107exit 1
108
Note: See TracBrowser for help on using the repository browser.