On Wed, 23 Aug 2023 18:23:40 -0700, Andrew Hewus Fresh wrote:

> I would have to see an example of doing that between ksh and perl.

Standard output should already be a pipe in the perl process by
virtue of running as a co-process.  In theory you should be able
to poll on it checking for POLLHUP.  Since our pipes are actually
bidiretional we can cheat and use select.  Something like this:

 - todd

lock_db() {
        [ "${LOCKPID:-}" ] && return 0

        # The installer doesn't have perl, so we can't lock there
        [ -e /usr/bin/perl ] || return 0

        set -o monitor
        perl <<'EOL' |&
                use v5.16;
                use warnings;
                no lib ('/usr/local/libdata/perl5/site_perl');
                use OpenBSD::PackageInfo qw< lock_db >;

                $|=1;

                lock_db(0);
        
                say $$;
                my $rin = my $win = my $ein = '';
                vec($ein, fileno(STDOUT), 1) = 1;
                vec($rin, fileno(STDOUT), 1) = 1;
                my $nfound = select(my $rout = $rin, my $wout = $win, my $eout 
= $ein, undef);
EOL
        set +o monitor

        read -rp LOCKPID

        return 0
}

Reply via email to