Provide getcwd(NULL, 0) for Solaris (SunOS5)
[exim.git] / src / src / eximon.src
1 # Base source of start-up shell script for the Exim Monitor. Used to set the
2 # required environment variables before running the program. Using script
3 # rather than a configuration file means that computation can be done.
4 # The build process concatenates on the front of this various settings from
5 # os-specific files and from the user's configuration file.
6
7 # Copyright (c) 2004 - 2015 University of Cambridge.
8 # See the file NOTICE for conditions of use and distribution.
9
10 # Except when they appear in comments, the following placeholders in this
11 # source are replaced when it is turned into a runnable script:
12 #
13 # CONFIGURE_FILE_USE_NODE
14 # CONFIGURE_FILE
15 # BIN_DIRECTORY
16 # BASENAME_COMMAND
17 # HOSTNAME_COMMAND
18 # X11_LD_LIBRARY
19
20 # PROCESSED_FLAG
21
22 # See if caller wants to invoke gdb
23
24 use_gdb=''
25
26 case ${1:-foo} in
27 gdb*) use_gdb="$1"; shift ;;
28 esac
29
30 # Save arguments (can be the usual X parameters)
31
32 cmd_args="$@"
33
34 # See if this installation is using the esoteric "USE_NODE" feature of Exim,
35 # in which it uses the host's name as a suffix for the configuration file name.
36
37 if [ "CONFIGURE_FILE_USE_NODE" = "yes" ]; then
38 hostsuffix=.`uname -n`
39 fi
40
41 # Now find the configuration file name. This has got complicated because
42 # CONFIGURE_FILE may now be a list of files. The one that is used is the first
43 # one that exists. Mimic the code in readconf.c by testing first for the
44 # suffixed file in each case.
45
46 set `awk -F: '{ for (i = 1; i <= NF; i++) print $i }' <<End
47 CONFIGURE_FILE
48 End
49 `
50 while [ "$config" = "" -a $# -gt 0 ] ; do
51 if [ -f "$1$hostsuffix" ] ; then
52 config="$1$hostsuffix"
53 elif [ -f "$1" ] ; then
54 config="$1"
55 fi
56 shift
57 done
58
59 # Determine where the spool directory is and whether there is any setting of
60 # log_file_path. Search for an exim_path setting in the configure file;
61 # otherwise use the bin directory. Call that version of Exim to find the spool
62 # directory and the setting of log_file_path.
63
64 config=${EXIMON_EXIM_CONFIG-$config}
65
66 # Add code here to redefine "config" if an alternative configuration file
67 # should be used in some circumstances. If you do that, you should also arrange
68 # for the value to be set in EXIMON_EXIM_CONFIG, and to export that variable
69 # into the environment. BEWARE: a tab character is needed in the command below.
70 # It has had a nasty tendency to get lost in the past. Use a variable to hold a
71 # space and a tab to keep the tab in one place.
72
73 st=' '
74 EXIM_PATH=`grep "^[$st]*exim_path" $config | sed "s/.*=[$st]*//"`
75 if test "$EXIM_PATH" = ""; then EXIM_PATH=BIN_DIRECTORY/exim; fi
76
77 SPOOL_DIRECTORY=`$EXIM_PATH -C $config -bP spool_directory | sed 's/.*=[ ]*//'`
78 LOG_FILE_PATH=`$EXIM_PATH -C $config -bP log_file_path | sed 's/.*=[ ]*//'`
79
80 # If log_file_path is "syslog" then logging is only to syslog, and the monitor
81 # is unable to display a log tail unless EXIMON_LOG_FILE_PATH is set to tell
82 # it where the log data is. If log_file_path is unset (i.e. empty) the default
83 # is "mainlog" in the "log" directory in the spool directory. Otherwise,
84 # remove any occurrences of "syslog:" or ":syslog" (spaces allowed in various
85 # places) and look at the remainder of the entry. If it's null, check whether
86 # LOG_FILE_NAME was set a compile time and contains a path. Otherwise fall
87 # back to the default path.
88
89 if [ "$EXIMON_LOG_FILE_PATH" != "" ] ; then
90 LOG_FILE_NAME="$EXIMON_LOG_FILE_PATH"
91 elif [ "$LOG_FILE_PATH" = "syslog" ] ; then
92 LOG_FILE_NAME=""
93 echo \*\*\*
94 echo Exim is using the syslog interface for its log data. If you redirect all
95 echo MAIL.INFO syslog messages into a separate file, you can point eximon at
96 echo that file with the EXIMON_LOG_FILE_PATH environment variable.
97 echo \*\*\*
98 elif [ "$LOG_FILE_PATH" = "" ] ; then
99 LOG_FILE_NAME=$SPOOL_DIRECTORY/log/mainlog
100 else
101 LOG_FILE_NAME=`echo $LOG_FILE_PATH | \
102 sed -e 's/ *: *syslog *: */:/' \
103 -e 's/ *: *syslog *$//' \
104 -e 's/^ *syslog *: *//' \
105 -e 's/%s/main/'`
106 if [ "$LOG_FILE_NAME" = "" ] ; then
107 COMPILETIMEDEFAULT=`$EXIM_PATH -C /dev/null -bP log_file_path | \
108 sed -e 's/.*=[ ]*//' \
109 -e 's/ *: *syslog *: */:/' \
110 -e 's/ *: *syslog *$//' \
111 -e 's/^ *syslog *: *//' \
112 -e 's/%s/main/'`
113 if [ "$COMPILETIMEDEFAULT" != "" ] ; then
114 LOG_FILE_NAME="$COMPILETIMEDEFAULT"
115 else
116 LOG_FILE_NAME=$SPOOL_DIRECTORY/log/mainlog
117 fi
118 fi
119 fi
120
121 # The basename and hostname commands vary from system to system
122
123 basename=BASENAME_COMMAND
124 hostname=HOSTNAME_COMMAND
125
126 # SunOS5 is a pain in that they may be in one of two places. So is Linux
127 # in the case of basename. Set up a general mechanism for searching for
128 # them in several places.
129
130 if [ "${basename}" = "look_for_it" ] ; then
131 if [ -f /usr/bin/basename ] ; then
132 basename=/usr/bin/basename
133 else
134 if [ -f /bin/basename ] ; then
135 basename=/bin/basename
136 else
137 basename=/usr/ucb/basename
138 fi
139 fi
140 fi
141
142 if [ "${hostname}" = "look_for_it" ] ; then
143 if [ -f /usr/bin/hostname ] ; then
144 hostname=/usr/bin/hostname
145 else
146 if [ -f /bin/hostname ] ; then
147 hostname=/bin/hostname
148 else
149 hostname=/usr/ucb/hostname
150 fi
151 fi
152 fi
153
154 # Set hostname to the full hostname with the specified domain
155 # stripped off its end. On Solaris 2, the default basename
156 # command treats its suffix argument as a pattern. Consequently,
157 # if fullhostname contains no dots but ends with what looks like
158 # the domain, straightforward use of basename screws things up.
159 # Use a general test for this case, just in case any other OS
160 # do the same.
161
162 fullhostname=`${hostname}`
163 case `${basename} abc .c` in
164 a) hostname=`${basename} ${fullhostname} '\.'${DOMAIN}` ;;
165 *) hostname=`${basename} ${fullhostname} .${DOMAIN}` ;;
166 esac
167
168
169 # Arrange for the window title field to be substituted by the shell
170 # so that it can contain either the full or the short host name. This
171 # is a tedious little bit of magic, but I don't know how to do it
172 # in a less tortuous way.
173
174 WINDOW_TITLE=`fullhostname=${fullhostname} hostname=${hostname} /bin/sh <<xx
175 echo ${WINDOW_TITLE}
176 xx
177 `
178
179 # Add the X11 library to the library path, and then export the
180 # environment variables used by eximon. The string X11-LD-LIBRARY
181 # (with underscores, not hyphens) below is replaced by the configured
182 # library name when the script is built. (Hyphens are used in the description
183 # to stop it getting changed there too.)
184
185 X11LIB=X11_LD_LIBRARY
186
187 if [ "${LD_LIBRARY_PATH}" = "" ] ; then
188 LD_LIBRARY_PATH=${X11LIB}
189 else
190 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${X11LIB}
191 fi
192
193 export EXIM_PATH LD_LIBRARY_PATH \
194 LOG_BUFFER LOG_DEPTH LOG_FILE_NAME LOG_FONT LOG_WIDTH \
195 ACTION_OUTPUT ACTION_QUEUE_UPDATE\
196 MENU_EVENT MIN_HEIGHT MIN_WIDTH \
197 QUALIFY_DOMAIN QUEUE_DEPTH QUEUE_FONT QUEUE_INTERVAL QUEUE_MAX_ADDRESSES \
198 QUEUE_STRIPCHART_NAME QUEUE_TOTAL QUEUE_WIDTH SPOOL_DIRECTORY \
199 START_DEPTH LOG_STRIPCHARTS SIZE_STRIPCHART SIZE_STRIPCHART_NAME \
200 START_SMALL STRIPCHART_INTERVAL \
201 TEXT_DEPTH WINDOW_TITLE
202
203 # Exec to the program we really want to run, thereby continuing in
204 # just the one process, and let it run in parallel with whatever
205 # called this script (unless gdb was requested in original $1).
206
207 if [ "${use_gdb:-}" = "" ] ; then
208 exec "${EXIMON_BINARY}" $cmd_args &
209 else
210 exec "$use_gdb" "${EXIMON_BINARY}" $cmd_args
211 # not backgrounded
212 fi
213
214 # End