Skip Menu |
 

This queue is for tickets about the Argv CPAN distribution.

Report information
The Basics
Id: 85757
Status: open
Priority: 0/
Queue: Argv

People
Owner: Nobody in particular
Requestors: dirk.heinrichs [...] altum.de
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Argv finds external command even if environment is empty
Date: Fri, 31 May 2013 11:00:31 +0200
To: bug-Argv [...] rt.cpan.org
From: Dirk Heinrichs <dirk.heinrichs [...] altum.de>
Download (untitled) / with headers
text/plain 1.5k
Hello, don't know wether it's really a bug, but at least something I'd like to understand. I was testing a program that is using Argv for wether it can be used from cron, so I started it with env -i ./myprogram.pl to start it with an empty environment and found out it worked, although I used only the basename of the external programs I called via Argv. So my question is: Why is it working at all, given that the environment is empty? I was expecting that it failed with some kind of "No such file or directory" error. The following small program shows the behaviour: #!/usr/bin/perl use strict; use warnings; use Argv; my $cmd=Argv->new({autochomp=>1,autofail=>1,dbglevel=>2}); # Verify environment is empty print ("Environment:\n"); foreach my $key ( sort( keys(%ENV) ) ) { printf( "%s=%s\n", $key, $ENV{$key} ); } # Call external command print ("Calling external command:\n"); $cmd->hg("--version")->system; exit (0); It gives the following output when started via "env -i": $ which hg /usr/local/bin/hg $ env -i ./argv_test.pl Environment: Calling external command: + hg --version Mercurial Distributed SCM (version 1.9) (see http://mercurial.selenic.com for more information) Copyright (C) 2005-2011 Matt Mackall and others This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + ($? == 0) How comes? Thanks... Dirk -- Dirk Heinrichs <dirk.heinrichs@altum.de> Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913 GPG Public Key C2E467BB | Jabber: dirk.heinrichs@altum.de
Download signature.asc
application/pgp-signature 190b

Message body not shown because it is not plain text.

Download (untitled) / with headers
text/plain 281b
I don't have hg installed but I took your test program and replaced hg with git. It worked for me (meaning that it failed as expected). I do see that the error from exec is not shown, which may be a secondary bug, but that's orthogonal. Try the attached variant of your test case.
Subject: rt85757-1.pl
Download rt85757-1.pl
text/x-perl 466b
#!/usr/bin/perl use strict; use warnings; use Argv; my $cmd=Argv->new({autochomp=>1,autofail=>1,dbglevel=>2}); # Verify internal environment is empty print ("Internal environment:\n"); foreach my $key ( sort( keys(%ENV) ) ) { printf( "%s=%s\n", $key, $ENV{$key} ); } # Compare external environment print ("External environment:\n"); $cmd->env->system; # Call external command print ("Calling external command:\n"); $cmd->git("--version")->system; exit (0);
Subject: Re: [rt.cpan.org #85757] Argv finds external command even if environment is empty
Date: Fri, 31 May 2013 23:56:32 +0200
To: bug-Argv [...] rt.cpan.org
From: Dirk Heinrichs <dirk.heinrichs [...] altum.de>
Download (untitled) / with headers
text/plain 1.2k
Hi, The result is the same, no matter where I try (RHEL 5.x, Debian Jessie (arm/i386), Ubuntu raring, Exherbo): % env -i ~/perl/argv_test.pl Internal environment: External environment: + env + ($? == 0) Calling external command: + git --version git version 1.8.3 + ($? == 0) $cmd->env->system; shouldn't work either, because env is an external command, and should be found via $PATH, which isn't set. I've also run it through strace, and I can clearly see that execve is searching some path (and that it has zero vars): 4430 execve("env", ["env"], [/* 0 vars */] <unfinished ...> 4429 wait4(4430, <unfinished ...> 4430 <... execve resumed> ) = -1 ENOENT (No such file or directory) 4430 execve("/bin/env", ["env"], [/* 0 vars */]) = 0 4431 execve("git", ["git", "--version"], [/* 0 vars */]) = -1 ENOENT (No such file or directory) 4431 execve("/bin/git", ["git", "--version"], [/* 0 vars */]) = -1 ENOENT (No such file or directory) 4431 execve("/usr/bin/git", ["git", "--version"], [/* 0 vars */]) = 0 But execve(3) doesn't mention any predefined path. Bye... Dirk -- Dirk Heinrichs <dirk.heinrichs@altum.de> Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913 GPG Public Key C2E467BB | Jabber: dirk.heinrichs@altum.de
Download signature.asc
application/pgp-signature 190b

Message body not shown because it is not plain text.

Download (untitled) / with headers
text/plain 198b
I don't understand either, but it seems independent of Argv. This test case behaves identically for me on Ubuntu: #!/usr/bin/perl use strict; use warnings; system(qw(git --version)); exit (0);
Subject: Re: [rt.cpan.org #85757] Argv finds external command even if environment is empty
Date: Sat, 01 Jun 2013 08:14 +0200
To: bug-Argv [...] rt.cpan.org
From: Dirk Heinrichs <dirk.heinrichs [...] altum.de>
Download (untitled) / with headers
text/plain 329b
Ah, OK. I rarely use those functions directly, so I didn't recognize. I'll try to find an explanation elsewhere, then. Thank you very much for your effort. Bye... Dirk -- Dirk Heinrichs <dirk.heinrichs@altum.de> Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913 GPG Public Key C2E467BB | Jabber: dirk.heinrichs@altum.de
Download signature.asc
application/pgp-signature 190b

Message body not shown because it is not plain text.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.