install.sh: expand @cfg_name@ in processed scripts
[girocco.git] / bin / gitweb-gc.sh
blobd869ecfb3f666ec6979850f7e46e2e68118ee98c
1 #!/bin/sh
2 # Allow gitweb.cgi to be run from a fastcgi server that does
3 # not really support periodic "garbage collection" exits
4 # (even on an exit status of 0) without losing fastcgi requests.
5 # Signals are forwarded in both directions.
6 cgiroot=@cgiroot@
7 bg=
8 handle_sig() { [ -z "$bg" ] || kill -$1 "$bg" 2>/dev/null; }
9 # backgrounding the cgi with '&' causes it to ignore SIGINT and SIGQUIT
10 # therefore we redirect INT to TERM and QUIT to ABRT when forwarding those
11 trap 'handle_sig HUP' HUP
12 trap 'handle_sig ABRT' ABRT QUIT
13 trap 'handle_sig PIPE' PIPE
14 trap 'handle_sig ALRM' ALRM
15 trap 'handle_sig TERM' TERM INT
16 trap 'handle_sig USR1' USR1
17 trap 'handle_sig USR2' USR2
18 while :; do
19 exec 3<&0
20 (exec 0<&3 3<&-; exec "$cgiroot/gitweb.cgi" "$@")&
21 bg="$!"
22 exec 3<&-
23 while :; do
24 ec=0
25 wait "$bg" || ec="$?"
26 kill -0 "$bg" 2>/dev/null || break
27 # was a signal to self that's now been forwarded
28 # go around the loop again
29 done
30 bg=
31 [ "${ec:-0}" = "0" ] || break
32 # was a gitweb "garbage collection" exit
33 # go around the loop again and restart gitweb
34 done
35 trap - HUP INT QUIT ABRT PIPE ALRM TERM USR1 USR2
36 if [ "${ec:-0}" -gt 128 ] && [ "${ec:-0}" -lt 160 ]; then
37 # self terminate
38 kill -$(($ec-128)) $$
40 exit "$ec"