Added a backwards-compatible interface to a fake DNS resolver for use by
[exim.git] / src / src / exiwhat.src
CommitLineData
059ec3d9
PH
1#! /bin/sh
2# $Cambridge: exim/src/src/exiwhat.src,v 1.1 2004/10/07 10:39:01 ph10 Exp $
3
4# Copyright (c) 2003 University of Cambridge.
5# See the file NOTICE for conditions of use and distribution.
6
7# Except when they appear in comments, the following placeholders in this
8# source are replaced when it is turned into a runnable script:
9#
10# CONFIGURE_FILE_USE_NODE
11# CONFIGURE_FILE
12# BIN_DIRECTORY
13# EXIWHAT_PS_CMD
14# EXIWHAT_PS_ARG
15# EXIWHAT_KILL_SIGNAL
16# EXIWHAT_EGREP_ARG
17# EXIWHAT_MULTIKILL_CMD
18# EXIWHAT_MULTIKILL_ARG
19
20# PROCESSED_FLAG
21
22# Shell script for seeing what the exim processes are doing. It gets rid
23# of the old process log, then sends SIGUSR1 to all exim processes to get
24# them to write their state to the log. Then it displays the contents of
25# the log.
26
27# The following lines are generated from Exim's configuration file when
28# this source is built into a script, but you can subsequently edit them
29# without rebuilding things, as long are you are careful not to overwrite
30# the script in the next Exim rebuild/install. However, it's best to
31# arrange your build-time configuration file to get the correct values.
32
33# Some operating systems have a command that finds processes that match
34# certain conditions (by default usually those running specific commands)
35# and sends them signals. If such a command is defined for your OS, the
36# following variables are set and used.
37
38multikill_cmd=EXIWHAT_MULTIKILL_CMD
39multikill_arg=EXIWHAT_MULTIKILL_ARG
40
41# In other operating systems, Exim has to use "ps" and "egrep" to find the
42# processes itself. In those cases, the next three variables are used:
43
44ps_cmd=EXIWHAT_PS_CMD
45ps_arg=EXIWHAT_PS_ARG
46egrep_arg=EXIWHAT_EGREP_ARG
47
48# In both cases, kill_arg is the argument for the (multi)kill command to send
49# SIGUSR1 (at least one OS requires a numeric value).
50
51signal=EXIWHAT_KILL_SIGNAL
52
53# See if this installation is using the esoteric "USE_NODE" feature of Exim,
54# in which it uses the host's name as a suffix for the configuration file name.
55
56if [ "CONFIGURE_FILE_USE_NODE" = "yes" ]; then
57 hostsuffix=.`uname -n`
58fi
59
60# Now find the configuration file name. This has got complicated because
61# CONFIGURE_FILE may now be a list of files. The one that is used is the first
62# one that exists. Mimic the code in readconf.c by testing first for the
63# suffixed file in each case.
64
65set `awk -F: '{ for (i = 1; i <= NF; i++) print $i }' <<End
66CONFIGURE_FILE
67End
68`
69while [ "$config" = "" -a $# -gt 0 ] ; do
70 if [ -f "$1$hostsuffix" ] ; then
71 config="$1$hostsuffix"
72 elif [ -f "$1" ] ; then
73 config="$1"
74 fi
75 shift
76done
77
78# Determine where the spool directory is. Search for an exim_path setting
79# in the configure file; otherwise use the bin directory. Call that version of
80# Exim to find the spool directory. BEWARE: a tab character is needed in the
81# first command below. It has had a nasty tendency to get lost in the past. Use
82# a variable to hold a space and a tab. This is less likely to be touched.
83
84st=' '
85exim_path=`grep "^[$st]*exim_path" $config | sed "s/.*=[$st]*//"`
86if test "$exim_path" = ""; then exim_path=BIN_DIRECTORY/exim; fi
87spool_directory=`$exim_path -C $config -bP spool_directory | sed "s/.*=[ ]*//"`
88process_log_path=`$exim_path -C $config -bP process_log_path | sed "s/.*=[ ]*//"`
89
90# The file that Exim writes when sent the SIGUSR1 signal is specified by
91# the process_log_path option. If that is not defined, Exim uses the file
92# called "exim-process.info" in the spool directory.
93
94log=$process_log_path
95if [ "$log" = "" ] ; then
96 log=$spool_directory/exim-process.info
97fi
98
99# Now do the job.
100
101/bin/rm -f ${log}
102if [ -f ${log} ]; then
103 echo "** Failed to remove ${log}"
104 exit 1
105fi
106
107# If there is a multikill command, use it. On some OS this command is called
108# "killall" (Linux, FreeBSD). On Solaris it is called "pkill". Note that on
109# Solaris, "killall" kills ALL processes - this is the System V version of this
110# command, and not what we want!
111
112if [ "$multikill_cmd" != "" ] ; then
113 $multikill_cmd $signal "$multikill_arg"
114
115# No multikill command; do it the hard way
116
117else
118 $ps_cmd $ps_arg | \
119 egrep "$egrep_arg" | \
120 awk "{print \"kill $signal \"\$1}" | \
121 uniq | sh
122fi
123
124sleep 1
125
126if [ ! -s ${log} ] ; then echo "No exim process data" ;
127 else sed 's/^[0-9-]* [0-9:]* \([+-][0-9]* \)*//' ${log} | sort -n | uniq ; fi
128
129
130# End of exiwhat