Index | Thread | Search

From:
Marc Espie <marc.espie.openbsd@gmail.com>
Subject:
pkg_add change for uptodate quirks
To:
tech@openbsd.org
Cc:
tb@openbsd.org
Date:
Sat, 3 May 2025 11:51:57 +0200

Download raw body.

Thread
  • Marc Espie:

    pkg_add change for uptodate quirks

As noticed by tb@, there is a bug in pkg_add where it runs an outdated
version of quirks during an update. This is a side-effect of separating
the updatedb in a different set: since the other set is not tagged "quirks"
then the safeguards to prevent running quirks early won't trigger, and thus
quirks will be loaded from the older installed version.

The following patch takes a different approach: instead of excluding the
quirks set from loading quirks, we only allow loading quirks once we're
sure it's up-to-date (or as up-to-date as it can be, since pkg_delete won't
try to do anything to it).

This leads to somewhat cleaner code, as all the "don't do this to quirks"
exceptions can disappear, thus removing a few tests.

Please test (and commit)

Index: OpenBSD/AddDelete.pm
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.sbin/pkg_add/OpenBSD/AddDelete.pm,v
diff -u -p -r1.100 AddDelete.pm
--- OpenBSD/AddDelete.pm	2 Jul 2023 13:33:10 -0000	1.100
+++ OpenBSD/AddDelete.pm	3 May 2025 09:36:44 -0000
@@ -319,6 +319,7 @@ sub log($self, @p)
 
 sub run_quirks($state, $sub)
 {
+	return if !$state->{uptodate_quirks};
 	if (!exists $state->{quirks}) {
 		eval {
 			use lib ('/usr/local/libdata/perl5/site_perl');
Index: OpenBSD/PkgAdd.pm
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.sbin/pkg_add/OpenBSD/PkgAdd.pm,v
diff -u -p -r1.151 PkgAdd.pm
--- OpenBSD/PkgAdd.pm	2 Dec 2024 22:32:57 -0000	1.151
+++ OpenBSD/PkgAdd.pm	3 May 2025 09:37:44 -0000
@@ -303,7 +303,6 @@ sub check_security($set, $state, $plist,
 {
 	return if $checked->{$plist->fullpkgpath};
 	$checked->{$plist->fullpkgpath} = 1;
-	return if $set->{quirks};
 	my ($error, $bad);
 	$state->run_quirks(
 		sub($quirks) {
@@ -962,6 +961,9 @@ sub process_set($self, $set, $state)
 
 	if ($set->newer == 0 && $set->older_to_do == 0) {
 		$state->tracker->uptodate($set);
+		if ($set->{quirks}) {
+			$state->{uptodate_quirks} = 1;
+		}
 		return ();
 	}
 
@@ -1064,6 +1066,9 @@ sub process_set($self, $set, $state)
 		for my $p ($set->newer_names) {
 			$self->may_grab_debug_for($p, 0, $state);
 		}
+	}
+	if ($set->{quirks}) {
+		$state->{uptodate_quirks} = 1;
 	}
 	return ();
 }
Index: OpenBSD/PkgDelete.pm
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.sbin/pkg_add/OpenBSD/PkgDelete.pm,v
diff -u -p -r1.51 PkgDelete.pm
--- OpenBSD/PkgDelete.pm	9 Oct 2023 07:12:22 -0000	1.51
+++ OpenBSD/PkgDelete.pm	3 May 2025 09:38:55 -0000
@@ -357,6 +357,8 @@ sub process_set($self, $set, $state)
 
 sub main($self, $state)
 {
+	# we're only removing packages, so we're not even going to update quirks
+	$state->{uptodate_quirks} = 1;
 	if ($state->{exclude}) {
 		my $names = {};
 		for my $l (@{$state->{setlist}}) {
Index: OpenBSD/Update.pm
===================================================================
RCS file: /build/data/openbsd/cvs/src/usr.sbin/pkg_add/OpenBSD/Update.pm,v
diff -u -p -r1.171 Update.pm
--- OpenBSD/Update.pm	7 Oct 2023 09:10:03 -0000	1.171
+++ OpenBSD/Update.pm	3 May 2025 09:45:04 -0000
@@ -96,17 +96,15 @@ sub process_handle($self, $set, $h, $sta
 		return 0;
 	}
 
-	if (!$set->{quirks}) {
-		my $base = 0;
-		$state->run_quirks(
-		    sub($quirks) {
-			$base = $quirks->is_base_system($h, $state);
-		    });
-		if ($base) {
-			$h->{update_found} = OpenBSD::Handle->system;
-			$set->{updates}++;
-			return 1;
-		}
+	my $base = 0;
+	$state->run_quirks(
+	    sub($quirks) {
+		$base = $quirks->is_base_system($h, $state);
+	    });
+	if ($base) {
+		$h->{update_found} = OpenBSD::Handle->system;
+		$set->{updates}++;
+		return 1;
 	}
 
 	my $plist = OpenBSD::PackingList->from_installation($pkgname,
@@ -133,12 +131,10 @@ sub process_handle($self, $set, $h, $sta
 	}
 	push(@search, OpenBSD::Search::Stem->split($sname));
 
-	if (!$set->{quirks}) {
-		$state->run_quirks(
-		    sub($quirks) {
-			$quirks->tweak_search(\@search, $h, $state);
-		    });
-	}
+	$state->run_quirks(
+	    sub($quirks) {
+		$quirks->tweak_search(\@search, $h, $state);
+	    });
 	my $oldfound = 0;
 	my @skipped_locs = ();