Commit 17c9a183 authored by Raphaël Hertzog's avatar Raphaël Hertzog

Replace APT hook with a dpkg trigger

Any package installing/updating a binary in the PATH will now trigger
kali-menu's postint to run update-kali-menu. This avoids mucking with
dpkg's lock file to wait its completion. The downside is that it might
run a few more times but it will also avoid kludges in live-build where
we try to wait until it has been run.
parent cfc23cba
DPkg::Post-Invoke { "[ ! -x /usr/share/kali-menu/update-kali-menu ] || /usr/share/kali-menu/update-kali-menu wait_dpkg"; }
......@@ -2,7 +2,6 @@ menus/kali-applications.menu etc/xdg/menus/applications-merged/
menus/xfce-applications.menu etc/xdg/menus/
desktop-directories/*.directory usr/share/desktop-directories/
desktop-files/*.desktop usr/share/kali-menu/applications/
apt.conf.d/99kali-menu etc/apt/apt.conf.d/
update-kali-menu usr/share/kali-menu/
menu-icons/* usr/share/icons/hicolor/
dconf/kali-menu etc/dconf/db/local.d/
......
# Can't be fixed until #945131 is fixed
kali-menu: uses-dpkg-database-directly usr/share/kali-menu/update-kali-menu
# It's not the homepage
kali-menu: description-possibly-contains-homepage http://standards.freedesktop.org/menu-spec/menu-spec-1.0.html
rm_conffile /etc/apt/apt.conf.d/99kali-menu 2020.1.3~
......@@ -2,15 +2,15 @@
set -e
if [ "$1" = "configure" ] && dpkg --compare-versions "$2" lt "0.83"; then
# Initial installation or first upgrade, the hook is not yet in place,
# we call it ourselves and it will wait until dpkg/apt is over
/usr/share/kali-menu/update-kali-menu </dev/null >/dev/null 2>&1 &
fi
case "$1" in
configure|triggered)
/usr/share/kali-menu/update-kali-menu
if which dconf >/dev/null 2>&1; then
dconf update || true
fi
[ "$1" = "triggered" ] && exit 0 # Early stop for triggered action
#DEBHELPER#
if which dconf >/dev/null 2>&1; then
dconf update || true
fi
esac
#DEBHELPER#
interest-noawait /bin
interest-noawait /sbin
interest-noawait /usr/bin
interest-noawait /usr/sbin
......@@ -13,7 +13,6 @@ use File::Path qw(make_path);
use constant {
INCOMING_APPDIR => "/usr/share/kali-menu/applications",
OUTGOING_APPDIR => "/usr/share/applications",
DPKG_LOCKFILE => "/var/lib/dpkg/lock",
KALI_MENU_LOCKFILE => "/var/lock/kali-menu",
};
......@@ -27,9 +26,6 @@ my $lock = get_lock(); # Can stop here if another instance is already running
parse_kali_desktop_files();
my $arg = shift @ARGV || "";
wait_dpkg() if (defined $ENV{'DPKG_RUNNING_VERSION'} or $arg eq "wait_dpkg");
# Scan installed packages to identify desktop files to install
foreach my $pkg (list_installed_packages()) {
$installed{$pkg} = 1;
......@@ -190,30 +186,3 @@ sub get_lock {
$fh->sync();
return $fh;
}
sub wait_dpkg {
return unless -e DPKG_LOCKFILE;
open my $fh, '<', DPKG_LOCKFILE or syserr("Can't open %s", DPKG_LOCKFILE);
my $fs = new File::FcntlLock l_type => F_WRLCK;
# Wait until dpkg releases the lock and doesn't grab it back in the
# next 5 seconds
my $count = 0;
while ($count < 2) {
if (can_lock($fh, $fs)) {
$count++;
} else {
$count = 0;
}
sleep(5);
}
close $fh;
}
sub can_lock {
my ($fh, $fs) = @_;
$fs->l_type(F_WRLCK);
if (not $fs->lock($fh, F_GETLK)) {
error("Failed to analyze lock on %s: %s", DPKG_LOCKFILE, $fs->error());
}
return $fs->l_type == F_UNLCK;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment