Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dpkg lock #15735

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/sonic-build-hooks/hooks/dpkg
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

. /usr/local/share/buildinfo/scripts/buildinfo_base.sh
REAL_COMMAND=$(get_command dpkg)
COMMAND_INFO="Locked by command: $REAL_COMMAND $@"
NEED_RELEASE_LOCK=n
if [[ "$DPKG_HOOK_LOCKED" != "y" ]];then
COMMAND_INFO="Locked by command: $REAL_COMMAND $*"
DPKG_NEED_LOCK=$(check_dpkg_need_lock "$@")

if [ "$DPKG_NEED_LOCK" == "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
33 changes: 33 additions & 0 deletions src/sonic-build-hooks/scripts/buildinfo_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,39 @@ check_apt_install()
done
}

# Check if we need to use apt_installation_lock for this dpkg command
check_dpkg_need_lock()
{
for para in "$@"
do
if [ "$para" == "-i" ] || [ "$para" == "--install" ]; then
echo y
break
fi

if [ "$para" == "-P" ] || [ "$para" == "--purge" ]; then
echo y
break
fi

if [ "$para" == "-r" ] || [ "$para" == "--remove" ]; then
echo y
break
fi

if [ "$para" == "--unpack" ] || [ "$para" == "--configure" ]; then
echo y
break
fi

if [ "$para" == "--update-avail" ] || [ "$para" == "--merge-avail" ] || [ "$para" == "--clear-avail" ]; then
echo y
break
fi

done
}

# Print warning message if a debian package version not specified when debian version control enabled.
check_apt_version()
{
Expand Down