Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 903775 | Differences between
and this patch

Collapse All | Expand All

(-)file_not_specified_in_diff (-13 / +14 lines)
Line  Link Here
0
-- /mnt/ro/fs/usr/sbin/asterisk_wrapper
0
++ /mnt/changes/usr/sbin/asterisk_wrapper
Lines 1-4 Link Here
1
#! /bin/bash
1
#! /bin/sh
2
# Copyright 1999-2022 Gentoo Authors
2
# Copyright 1999-2022 Gentoo Authors
3
# Distributed under the terms of the GNU General Public License v2
3
# Distributed under the terms of the GNU General Public License v2
4
4
Lines 83-91 Link Here
83
done
83
done
84
shift # --
84
shift # --
85
85
86
ast_opts=("$@")
86
ast_opts="$@"
87
87
88
if ! [[ "${restartdelay}" =~ ^[1-9][0-9]*$ ]]; then
88
if ! printf "%s\n" "${restartdelay}" | grep -qE '^[1-9][0-9]*$' ; then
89
	echo "Invalid --restartdelay value ${restartdelay}, resetting to 5." >&2
89
	echo "Invalid --restartdelay value ${restartdelay}, resetting to 5." >&2
90
	restartdelay=5
90
	restartdelay=5
91
fi
91
fi
Lines 108-114 Link Here
108
	# To fix this is quite complex in that we need to keep an fd, compare inode numbers
108
	# To fix this is quite complex in that we need to keep an fd, compare inode numbers
109
	# and manage flock's.
109
	# and manage flock's.
110
	[[ -r "${rundir}/${progname}.pid" ]] && \
110
	[[ -r "${rundir}/${progname}.pid" ]] && \
111
		[[ "$(<"${rundir}/${progname}.pid")" = $$ ]] && \
111
		[[ "$(cat "${rundir}/${progname}.pid")" = $$ ]] && \
112
		rm "${rundir}/${progname}.pid"
112
		rm "${rundir}/${progname}.pid"
113
}
113
}
114
trap cleanup EXIT
114
trap cleanup EXIT
Lines 118-124 Link Here
118
# config file and request a core stop when convenient so that we can take over.
118
# config file and request a core stop when convenient so that we can take over.
119
echo $$ > "${rundir}/${progname}.pid"
119
echo $$ > "${rundir}/${progname}.pid"
120
if [[ -r "${rundir}/asterisk.pid" ]]; then
120
if [[ -r "${rundir}/asterisk.pid" ]]; then
121
	ast_pid="$(<"${rundir}/asterisk.pid")"
121
	ast_pid="$(cat "${rundir}/asterisk.pid")"
122
	[[ -r "/proc/${ast_pid}/cmdline" ]] && ast_conf="$(tr '\0' '\n' < "/proc/${ast_pid}/cmdline" | grep -A1 '^-C$' | tail -n1)" && /usr/sbin/asterisk -C "${ast_conf:-/etc/asterisk/asterisk.conf}" -rx "core stop when convenient"
122
	[[ -r "/proc/${ast_pid}/cmdline" ]] && ast_conf="$(tr '\0' '\n' < "/proc/${ast_pid}/cmdline" | grep -A1 '^-C$' | tail -n1)" && /usr/sbin/asterisk -C "${ast_conf:-/etc/asterisk/asterisk.conf}" -rx "core stop when convenient"
123
	# We may hit a few (depending on how busy the server is a great many number) loop failures still ...
123
	# We may hit a few (depending on how busy the server is a great many number) loop failures still ...
124
fi
124
fi
Lines 126-153 Link Here
126
ulimit -c "${dumpcore}"
126
ulimit -c "${dumpcore}"
127
ulimit -n "${maxfd}"
127
ulimit -n "${maxfd}"
128
128
129
ast_cmd=()
129
ast_cmd=""
130
if [ -n "${nicelevel}" ]; then
130
if [ -n "${nicelevel}" ]; then
131
	ast_cmd+=(nice -n "${nicelevel}")
131
	ast_cmd="${ast_cmd} nice -n ${nicelevel}"
132
fi
132
fi
133
ast_cmd+=(/usr/sbin/asterisk "${ast_opts[@]}")
133
ast_cmd="${ast_cmd} /usr/sbin/asterisk ${ast_opts}"
134
134
135
135
while [[ -r "${rundir}/${progname}.pid" ]]; do
136
while [[ -r "${rundir}/${progname}.pid" ]]; do
136
	# Another instance is looking to replace us, so terminate.
137
	# Another instance is looking to replace us, so terminate.
137
	if [[ "$(<"${rundir}/${progname}.pid")" != $$ ]]; then
138
	if [[ "$(cat "${rundir}/${progname}.pid")" != $$ ]]; then
138
		break
139
		break
139
	fi
140
	fi
140
141
141
	echo "Starting asterisk with ${ast_opts[*]}"
142
	echo "Starting asterisk with ${ast_opts}"
142
	if [ -n "${tty+yes}" ]; then
143
	if [ -n "${tty+yes}" ]; then
143
		/bin/stty -F "${tty}" sane
144
		/bin/stty -F "${tty}" sane
144
		"${ast_cmd[@]}" >"${tty}" 2>&1 <"${tty}"
145
		${ast_cmd} >"${tty}" 2>&1 <"${tty}"
145
		result=$?
146
		result=$?
146
	else
147
	else
147
		# Purposefully leave stderr alone, this will under certain odd cases (like exceptions,
148
		# Purposefully leave stderr alone, this will under certain odd cases (like exceptions,
148
		# and other odd cases logged from glibc) result in those logs at least being captured
149
		# and other odd cases logged from glibc) result in those logs at least being captured
149
		# in syslog.
150
		# in syslog.
150
		"${ast_cmd[@]}" </dev/null >/dev/null
151
		${ast_cmd} </dev/null >/dev/null
151
		result=$?
152
		result=$?
152
	fi
153
	fi
153
154

Return to bug 903775