diff options
author | Theo Buehler <tb@cvs.openbsd.org> | 2024-10-01 18:48:30 +0000 |
---|---|---|
committer | Theo Buehler <tb@cvs.openbsd.org> | 2024-10-01 18:48:30 +0000 |
commit | 93425456f462f24ddcf2869b12c9805a906bde85 (patch) | |
tree | b5b5a4e72ecd84fe0f90f2035e83123fb410c54f /usr.sbin/pkg_add | |
parent | fb88bfee980dfc21ec23f27782e935d03550ca22 (diff) |
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
Diffstat (limited to 'usr.sbin/pkg_add')
-rw-r--r-- | usr.sbin/pkg_add/OpenBSD/Log.pm | 26 |
1 files changed, 22 insertions, 4 deletions
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 <espie@openbsd.org> # @@ -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; } } |