Open p5pRT opened 16 years ago
Under win32\, there is retry logic to spawn a process again\, if the return code is negative\, and if errno is set to a couple of specific values.
This behaves unpredictably. Here's an example:
firstly\, write a C/C++ program that returns a negative number
int main(int argc\, char* argv[]) { std::cout\<\< argv[0] \<\< std::endl; return -1; }
secondly\, run it via perl:
#!/usr/bin/perl my $rv = system ("minus1.exe"); print "got '$rv'\n"; print "which if we shift it is "\, $rv >>8\, "\n";
All is OK. Console output shows that minus1.exe is invoked once.
thirdly\, expand the perl to use an innocuous module:
#!/usr/bin/perl use Cwd; my $dir = cwd(); my $rv = system ("minus1.exe"); print "got '$rv'\n"; print "which if we shift it is "\, $rv >>8\, "\n";
Now\, when you run this\, minus1.exe is executed twice. This is the defect. It also happens with other modules\, such as DBI with DBD:Oracle\, but Cwd is easy to use and appears to be part of the base Perl installation.
Now\, I've never delved into the source of Perl before\, but I've zeroed in on this code in win32.c:
int Perl_do_aspawn(pTHX_ SV *really\, SV **mark\, SV **sp)
\
status = win32_spawnvp(flag\, (const char*)(really ? SvPV_nolen(really) : argv[0])\, (const char* const*)argv);
if (status \< 0 && (errno == ENOEXEC || errno == ENOENT)) { /* possible shell-builtin\, invoke with shell */ int sh_items; sh_items = w32_perlshell_items; while (--index >= 0) argv[index+sh_items] = argv[index]; while (--sh_items >= 0) argv[sh_items] = w32_perlshell_vec[sh_items];
status = win32_spawnvp(flag\, (const char*)(really ? SvPV_nolen(really) : argv[0])\, (const char* const*)argv); }
It checks errno. But\, digging into win32_spawnvp a bit further\, it's CreateProcess that's called\, not system(). I reckon that CreateProcess doesn't manipulate errno at all\, so what we're seeing is the old use of errno\, which is being set by code in the Cwd module. The code in win32_spawnvp only sets errno in *some* conditions\, and does not reset it. Hence the unpredictable behaviour.
----- Original Message ----- From: "alistair@inrevo.com (via RT)" \perlbug\-followup@​perl\.org To: \bugs\-bitbucket@​netlabs\.develooper\.com . .
This behaves unpredictably. Here's an example:
firstly\, write a C/C++ program that returns a negative number
int main(int argc\, char* argv[]) { std::cout\<\< argv[0] \<\< std::endl; return -1; }
secondly\, run it via perl:
#!/usr/bin/perl my $rv = system ("minus1.exe"); print "got '$rv'\n"; print "which if we shift it is "\, $rv >>8\, "\n";
All is OK. Console output shows that minus1.exe is invoked once.
Even at this stage\, I find that minus1.exe is invoked *twice* on most of my builds of Windows perl - 5.8.8\, 5.10.0 (including a 64-bit build of AS perl-5.10.0)\, and 5.11.0. Perl 5.6.2 gets it right.
I guess "unpredictably" is the key adverb.
Cheers\, Rob
The RT System itself - Status changed from 'new' to 'open'
Migrated from rt.perl.org#54028 (status was 'open')
Searchable as RT54028$