Skip to content

Commit

Permalink
[build] Add environment when using dpkg hook to avoid lock loop. (son…
Browse files Browse the repository at this point in the history
…ic-net#13150)

Why I did it
In some cases, dpkg will call dpkg to validate version.
dpkg hook will get stuck in a loop to lock.

How I did it
Use an env variable to skip duplicated lock.
  • Loading branch information
liushilongbuaa authored and mssonicbld committed Jan 10, 2023
1 parent a1200da commit feef9ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ echo '[INFO] Install and setup eatmydata'
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install eatmydata
sudo LANG=C chroot $FILESYSTEM_ROOT ln -s /usr/bin/eatmydata /usr/local/bin/dpkg
echo 'Dir::Bin::dpkg "/usr/local/bin/dpkg";' | sudo tee $FILESYSTEM_ROOT/etc/apt/apt.conf.d/00image-install-eatmydata > /dev/null
## Note: dpkg hook conflict with eatmydata
sudo LANG=C chroot $FILESYSTEM_ROOT rm /usr/local/sbin/dpkg -f

echo '[INFO] Install packages for building image'
sudo LANG=C chroot $FILESYSTEM_ROOT apt-get -y install makedev psmisc
Expand Down
10 changes: 9 additions & 1 deletion src/sonic-build-hooks/hooks/dpkg
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
REAL_COMMAND=$(get_command dpkg)
COMMAND_INFO="Locked by command: $REAL_COMMAND $@"
lock_result=$(acquire_apt_installation_lock "$COMMAND_INFO" )
NEED_RELEASE_LOCK=n
if [[ "$DPKG_HOOK_LOCKED" != "y" ]];then
lock_result=$(acquire_apt_installation_lock "$COMMAND_INFO" )
export DPKG_HOOK_LOCKED=y
NEED_RELEASE_LOCK=y
fi
$REAL_COMMAND "$@"
command_result=$?
if [[ "$NEED_RELEASE_LOCK" == "y" ]];then
unset DPKG_HOOK_LOCKED
fi
[ "$lock_result" == y ] && release_apt_installation_lock
exit $command_result

0 comments on commit feef9ca

Please sign in to comment.