summaryrefslogtreecommitdiff
path: root/src/chroot-tools/hooks-distcc.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/chroot-tools/hooks-distcc.sh')
-rw-r--r--src/chroot-tools/hooks-distcc.sh79
1 files changed, 57 insertions, 22 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
}