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