chiark / gitweb /
Better message for 503 from peer on idle conn. Conventional macro protection for...
[inn-innduct.git] / scripts / writelog.in
1 #! /bin/sh
2 # fixscript will replace this line with code to load innshellvars
3
4 ##  $Revision: 2677 $
5 ##  Write a log file entry, by either mailing it or writing it safely.
6 ##  Usage:
7 ##      writelog name text... <input
8 ##  where
9 ##      name    is 'mail' to mail it, or filename to append to.
10
11 MAXTRY=60
12
13 ##  Parse arguments.
14 if [ $# -lt 2 ] ; then
15     echo "usage: $0 'logfile|mail' message ..." 1>&2
16     exit 1
17 fi
18 LOGFILE="$1"
19 shift
20 MESSAGE="$@"
21
22 ##  Handle the easy cases.
23 case "X${LOGFILE}" in
24 X/dev/null)
25     exit 0
26     ;;
27 Xmail)
28     sed -e 's/^~/~~/' | ${MAILCMD} -s "${MESSAGE}" ${NEWSMASTER}
29     exit 0
30     ;;
31 esac
32
33 ##  We're sending to a file.
34 LOCK=${LOCKS}/LOCK.`basename ${LOGFILE}`
35
36 ##  Remember our PID, in case while is a sub-shell.
37 PID=$$
38 TRY=0
39
40 export LOCK MAXTRY PID LOGFILE ARTICLE MESSAGE TRY
41 while [ ${TRY} -lt ${MAXTRY} ]; do
42     shlock -p ${PID} -f ${LOCK} && break
43     sleep 2
44     TRY=`expr ${TRY} + 1`
45 done
46
47 ##  If we got the lock, update the file; otherwise, give up.
48 if [ ${TRY} -lt ${MAXTRY} ]; then
49     echo "${MESSAGE}" >>${LOGFILE}
50     ${SED} -e 's/^/    /' >>${LOGFILE}
51     echo "" >>${LOGFILE}
52     rm -f ${LOCK}
53 else
54     ##  This goes to errlog, usually.
55     echo "$0: Cannot grab lock ${LOCK}, held by:" `cat ${LOCK}` 1>&2
56 fi