View Single Post
  #4   (View Single Post)  
Old 6th February 2014
J65nko J65nko is offline
Administrator
 
Join Date: May 2008
Location: Budel - the Netherlands
Posts: 4,128
Default

Right now, I don't have time to work on this anymore, but maybe somebody else has

A shell test program aptly called testit that sets the environment and calls that Perl snippet with some diagnostics:
Code:
#!/bin/sh

pkg_path='PKG_PATH=/home/p1:scp://j65nko@pkg_bulk.my.local:ftp://ftp.nluug.nl/pub/OpenBSD'
pkg_config_libdir='PKG_CONFIG_LIBDIR=/usr/bin/local/lib:/sbin/lib:/usr/sbin/lib'

env -i ${pkg_path} ${pkg_config_libdir}  ./wonder_why.pl
The wonder_why.pl program:
Code:
#!/usr/bin/perl

use warnings;
use strict;

my @PKGPATH;

sub show_env {
   print "The environment:\n===============\n";
   foreach my $key (sort keys %ENV) {
     print $key, '=', $ENV{$key}, "\n";
   } 
   print "===============\n\n";
}

sub pr_array {
    my $listref = shift;
    print "\n---- $listref -----\n";
    for (@$listref) {
       print;
       print " \n";
    }
    print "---- end of $listref -----\n";
}


sub orig {

        defined($ENV{PKG_CONFIG_LIBDIR}) ?  print "YES defined\n" : print "NOT defined\n"; 
        $ENV{PKG_CONFIG_LIBDIR} ? print "YES bare\n" : print "NO bare\n";

        if (defined($ENV{PKG_CONFIG_LIBDIR}) && $ENV{PKG_CONFIG_LIBDIR}) {
                print "\nPKG_CONFIG_LIBDIR test succeeded\n";
                @PKGPATH = split(/:/, $ENV{PKG_CONFIG_LIBDIR});
                pr_array(\@PKGPATH);
        } elsif (defined($ENV{PKG_CONFIG_PATH}) && $ENV{PKG_CONFIG_PATH}) {
                print "\nPKG_CONFIG_PATH test succeeded\n";
                unshift(@PKGPATH, split(/:/, $ENV{PKG_CONFIG_PATH}));
                pr_array(\@PKGPATH);
        }

}

sub new {
        if ($ENV{PKG_CONFIG_LIBDIR}) {
            @PKGPATH = split(/:/, $ENV{PKG_CONFIG_LIBDIR});
        } elsif ($ENV{PKG_CONFIG_PATH}) {
            unshift(@PKGPATH, split(/:/, $ENV{PKG_CONFIG_PATH}));
        }
}

show_env() ;
orig();
A test run:
Code:
$ ./testit
                                                                
The environment:
===============
PKG_CONFIG_LIBDIR=/usr/bin/local/lib:/sbin/lib:/usr/sbin/lib
PKG_PATH=/home/p1:scp://j65nko@pkg_bulk.my.local:ftp://ftp.nluug.nl/pub/OpenBSD
===============

YES defined
YES bare

PKG_CONFIG_LIBDIR test succeeded

---- ARRAY(0x1e4f00d83c88) -----
/usr/bin/local/lib 
/sbin/lib 
/usr/sbin/lib 
---- end of ARRAY(0x1e4f00d83c88) -----
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump
Reply With Quote