From: tb Date: Tue, 1 Oct 2024 18:48:29 +0000 (+0000) Subject: Extend Log->system to support the same features as BaseState->system X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=9acbf608f1e1b3977edf18bee2d16e28a430ad2a;p=openbsd Extend Log->system to support the same features as BaseState->system In order to support privsep in tags, we need to be able to pass some code values in child/parent. from espie, tested by sthen, ok giovanni --- diff --git a/usr.sbin/pkg_add/OpenBSD/Log.pm b/usr.sbin/pkg_add/OpenBSD/Log.pm index 9eb45704eed..79b381ad3cb 100644 --- a/usr.sbin/pkg_add/OpenBSD/Log.pm +++ b/usr.sbin/pkg_add/OpenBSD/Log.pm @@ -1,5 +1,5 @@ # ex:ts=8 sw=4: -# $OpenBSD: Log.pm,v 1.10 2023/06/13 09:07:17 espie Exp $ +# $OpenBSD: Log.pm,v 1.11 2024/10/01 18:48:29 tb Exp $ # # Copyright (c) 2007-2010 Marc Espie # @@ -104,7 +104,24 @@ sub fatal($self, @p) sub system($self, @p) { - if (open(my $grab, "-|", @p)) { + my ($todo, $todo2); + if (ref $p[0] eq 'CODE') { + $todo = shift @p; + } else { + $todo = sub() {}; + } + if (ref $p[0] eq 'CODE') { + $todo2 = shift @p; + } else { + $todo2 = sub() {}; + } + my $child_pid = open(my $grab, "-|"); + if (!defined $child_pid) { + $self->{p}->say("system(#1) was not run: #2 #3", + join(", ", @p), $!, $self->{p}->child_error); + } + if ($child_pid) { + &$todo2(); while (<$grab>) { $self->{p}->_print($_); } @@ -115,8 +132,9 @@ sub system($self, @p) } return $?; } else { - $self->{p}->say("system(#1) was not run: #2 #3", - join(", ", @p), $!, $self->{p}->child_error); + $DB::inhibit_exit = 0; + &$todo(); + exec {$p[0]} (@p) or exit 1; } }