Index | Thread | Search

From:
Marc Espie <marc.espie.openbsd@gmail.com>
Subject:
Re: [patch] make pkg_add internals a bit more regular
To:
tech@openbsd.org, afresh1@openbsd.org, bentley@openbsd.org
Date:
Wed, 25 Sep 2024 16:30:18 +0200

Download raw body.

Thread
On Fri, Sep 20, 2024 at 03:31:35PM +0100, Stuart Henderson wrote:
> I don't see any problems with this in testing so far, but the code is
> way out of what I'm familiar with in perl.

Most of this is documented in perlipc(1)...

> On 2024/09/17 15:10, Marc Espie wrote:
> > I got bitten recently by the fact that
> > Log->system does not support the same features as
> > BaseState->system
> > 
> > (namely, passing some code values in child/father, which is intended
> > to eventually enable privsep in tags)
> > 
> > So, the following stand-alone patch should go in.
> > 
> > All this does is rewrite the pipeopen to allow code snippets to get
> > in the middle.
> > 
> > Please test and comment.
> > 
> > Index: OpenBSD/Log.pm
> > ===================================================================
> > RCS file: /vide/cvs/src/usr.sbin/pkg_add/OpenBSD/Log.pm,v
> > diff -u -p -r1.10 Log.pm
> > --- OpenBSD/Log.pm	13 Jun 2023 09:07:17 -0000	1.10
> > +++ OpenBSD/Log.pm	17 Sep 2024 13:07:59 -0000
> > @@ -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;
> >  	}
> >  }
> >  
> > 
> 
>