File: writelog.in

package info (click to toggle)
inn2 2.5.4-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,720 kB
  • ctags: 8,983
  • sloc: ansic: 92,499; sh: 13,509; perl: 12,921; makefile: 2,985; yacc: 842; python: 342; lex: 255
file content (56 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /bin/sh
# fixscript will replace this line with code to load innshellvars

##  $Revision: 2677 $
##  Write a log file entry, by either mailing it or writing it safely.
##  Usage:
##	writelog name text... <input
##  where
##	name	is 'mail' to mail it, or filename to append to.

MAXTRY=60

##  Parse arguments.
if [ $# -lt 2 ] ; then
    echo "usage: $0 'logfile|mail' message ..." 1>&2
    exit 1
fi
LOGFILE="$1"
shift
MESSAGE="$@"

##  Handle the easy cases.
case "X${LOGFILE}" in
X/dev/null)
    exit 0
    ;;
Xmail)
    sed -e 's/^~/~~/' | ${MAILCMD} -s "${MESSAGE}" ${NEWSMASTER}
    exit 0
    ;;
esac

##  We're sending to a file.
LOCK=${LOCKS}/LOCK.`basename ${LOGFILE}`

##  Remember our PID, in case while is a sub-shell.
PID=$$
TRY=0

export LOCK MAXTRY PID LOGFILE ARTICLE MESSAGE TRY
while [ ${TRY} -lt ${MAXTRY} ]; do
    shlock -p ${PID} -f ${LOCK} && break
    sleep 2
    TRY=`expr ${TRY} + 1`
done

##  If we got the lock, update the file; otherwise, give up.
if [ ${TRY} -lt ${MAXTRY} ]; then
    echo "${MESSAGE}" >>${LOGFILE}
    ${SED} -e 's/^/    /' >>${LOGFILE}
    echo "" >>${LOGFILE}
    rm -f ${LOCK}
else
    ##  This goes to errlog, usually.
    echo "$0: Cannot grab lock ${LOCK}, held by:" `cat ${LOCK}` 1>&2
fi