summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-05-01 17:19:22 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-05-04 03:28:40 -0400
commit6d935b88d80181707d6d3821814af5a6c99ffea8 (patch)
treeccf610e7586ea010da53644bd2228870d27fffde /src
parent3dd9a5f0de096ae9b7ba47c4907d38ca4c087326 (diff)
bugfix [2/2]: libremakepkg: hooks-distcc: Fix for the basic smoke test.
Diffstat (limited to 'src')
-rw-r--r--src/chroot-tools/hooks-distcc.sh79
-rwxr-xr-xsrc/chroot-tools/libremakepkg10
2 files changed, 63 insertions, 26 deletions
diff --git a/src/chroot-tools/hooks-distcc.sh b/src/chroot-tools/hooks-distcc.sh
index 2660b6d..a4b05cc 100644
--- a/src/chroot-tools/hooks-distcc.sh
+++ b/src/chroot-tools/hooks-distcc.sh
@@ -18,22 +18,28 @@
# You should have received a copy of the GNU General Public License
# along with Parabola. If not, see <http://www.gnu.org/licenses/>.
-hook_pre_build+=("distcc_start")
-hook_post_build+=("distcc_stop")
+hook_pre_build+=("distcc_start_odaemon")
+hook_post_build+=("distcc_stop_odaemon")
_distcc_check() {
local copydir=$1
local home=$2
local files=(
- "$copydir/bin/distcc-tool"
- "$copydir/run/distcc-tool.pid"
+ # From previous versions
"$home/.makepkg.conf"
+ "$copydir/run/distcc-tool.pid"
+
+ # From this version
+ "$copydir/bin/distcc-tool"
+ "$copydir/run/distcc-tool-idaemon.pid"
+ "$copydir/run/distcc-tool-odaemon.pid"
+ "$home/.config/pacman/makepkg.conf"
"$home/.ssh/config"
)
- local file_err=false
- for files in "${files[@]}"; do
+ local file file_err=false
+ for file in "${files[@]}"; do
if [[ -f $file ]]; then
file_err=true
error "Auto-generated file already exists, remove it: %s" "$file"
@@ -44,7 +50,27 @@ _distcc_check() {
fi
}
-distcc_start() {
+_distcc_start_idaemon() {
+ (
+ set -C
+ echo $BASHPID >/run/distcc-tool-idaemon.pid || exit 0
+ trap 'jobs -p | xargs -r kill --' EXIT
+ /bin/distcc-tool idaemon "$@" &
+ wait
+ ) &>/dev/null &
+}
+
+_distcc_stop_idaemon() {
+ if [[ -f /run/distcc-tool-idaemon.pid ]]; then
+ local idaemon
+ idaemon=$(< /run/distcc-tool-idaemon.pid) || exit
+ kill -- "$idaemon" || exit
+
+ rm -f -- /run/distcc-tool-idaemon.pid
+ fi
+}
+
+distcc_start_odaemon() {
local copydir=$1
# Because /{,usr/}{,s}bin are all symlinked together for
@@ -58,29 +84,37 @@ distcc_start() {
home="$copydir/build"
fi
- _distcc_check
+ _distcc_check "$copydir" "$home"
local _distcc_tool; _distcc_tool="$(librelib chroot/distcc-tool)"
install -m755 "$_distcc_tool" "$copydir/bin/distcc-tool"
- mkdir -p "$home/.ssh"
-
- printf '%s\n' \
- '/bin/distcc-tool idaemon "$DISTCC_HOSTS" &' \
- 'DISTCC_HOSTS="$(/bin/distcc-tool rewrite "$DISTCC_HOSTS")"' \
- > "$home/.makepkg.conf"
+ mkdir -p "$home/.config/pacman"
+ {
+ declare -f _distcc_start_idaemon
+ declare -f _distcc_stop_idaemon
+ printf '%s\n' \
+ '_discc_start_idaemon "$DISTCC_HOSTS"' \
+ 'trap _distcc_stop_idaemon EXIT' \
+ 'DISTCC_HOSTS="$(/bin/distcc-tool rewrite "$DISTCC_HOSTS")"'
+ } > "$home/.config/pacman/makepkg.conf"
+ mkdir -p "$home/.ssh"
printf '%s\n' \
'Host *' \
' ProxyCommand /bin/distcc-tool client %h %p' \
> "$home/.ssh/config"
- "$_distcc_tool" odaemon "$copydir" &
- echo $! > "$copydir/run/distcc-tool.pid"
+ (
+ echo $BASHPID >"$copydir"/run/distcc-tool-odaemon.pid
+ trap 'jobs -p | xargs -r kill --' EXIT
+ "$_distcc_tool" odaemon "$copydir" &
+ wait
+ ) &>/dev/null &
fi
}
-distcc_stop() {
+distcc_stop_odaemon() {
local copydir=$1
local home
@@ -90,15 +124,16 @@ distcc_stop() {
home="$copydir/build"
fi
- if [[ -f "$copydir/run/distcc-tool.pid" ]]; then
-
- odaemon=$(< "$copydir/distcc-tool.pid")
+ if [[ -f "$copydir/run/distcc-tool-odaemon.pid" ]]; then
+ local odaemon
+ odaemon=$(< "$copydir/run/distcc-tool-odaemon.pid")
kill -- "$odaemon"
rm -f -- \
- "$home/.makepkg.conf" \
+ "$home/.config/pacman/makepkg.conf" \
"$home/.ssh/config" \
"$copydir/bin/distcc-tool" \
- "$copydir/run/distcc-tool.pid"
+ "$copydir/run/distcc-tool-odaemon.pid" \
+ "$copydir/run/distcc-tool-idaemon.pid"
fi
}
diff --git a/src/chroot-tools/libremakepkg b/src/chroot-tools/libremakepkg
index 5b86c03..cd9e60e 100755
--- a/src/chroot-tools/libremakepkg
+++ b/src/chroot-tools/libremakepkg
@@ -69,14 +69,16 @@ exit_copy() {
}
# Usage; run_hook $hookname $args...
-run_hook() (
+run_hook() {
local hookname=$1; shift
local hookvar="hook_${hookname}[@]"
local fails=()
- set -o pipefail
+
for hook in "${!hookvar}"; do
- { "$hook" "$@" |& indent; } || fails+=("$hook")
+ # The "<&0&wait $!" trick is to prevent "||" from
+ # disabling "set -e"
+ { "$hook" "$@" |& indent; } <&0&wait $! || fails+=("$hook")
done
if [[ ${#fails[@]} -gt 0 ]]; then
@@ -85,7 +87,7 @@ run_hook() (
else
return 0
fi
-)
+}
# Usage: add_to_local_repo $copydir $pkgfiles...
add_to_local_repo() {