RE: env in background process
Thanks for looking at it. I prefer "%ENV = ();" in PerlCleanupHandler handler. (as i don't have to modify so many scripts). I don't think it has any negative effect ... -Niraj > -Original Message- > From: Doug MacEachern [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, September 26, 2000 3:32 PM > To: Niraj Sheth > Cc: [EMAIL PROTECTED] > Subject: RE: env in background process > > > On Tue, 15 Aug 2000, Niraj Sheth wrote: > > > so why dump_env is getting both? > > If I either uncomment "local %ENV = %ENV;" in script or put > "%ENV = ();" > > in PerlCleanupHandler then dump_env is working fine. > > I tried both Apache::PerlRun and Apache::Registry which same result. > > oh whoops, you did send a test case. i think the problem is > that mod_perl > only clears the Perl side of %ENV, so the underlying C > environ array is > not modified. if we do that than other problems pop up. the best > approach for the moment is to use: > > local $ENV{FOO1} = 'foo1'; > > print `dump_env`; >
RE: env in background process
On Tue, 15 Aug 2000, Niraj Sheth wrote: > so why dump_env is getting both? > If I either uncomment "local %ENV = %ENV;" in script or put "%ENV = ();" > in PerlCleanupHandler then dump_env is working fine. > I tried both Apache::PerlRun and Apache::Registry which same result. oh whoops, you did send a test case. i think the problem is that mod_perl only clears the Perl side of %ENV, so the underlying C environ array is not modified. if we do that than other problems pop up. the best approach for the moment is to use: local $ENV{FOO1} = 'foo1'; print `dump_env`;
Re: env in background process
On Mon, 14 Aug 2000, Niraj Sheth wrote: > Hi, > > I am having very strange problem with environment variables. > > >From Apache::PerlRun script(cgi) I am setting env and firing background > process .. > system("$command &") (or print `$command &`;) > > now looks like environment variable being persistence b/w different > requests ONLY in background process. so it's looks to me that mod_perl > is setting proper "Perl Level" env but failing to reset env at "c level" > or "process level". I know it's sounds very weird. > /perl-status?env is printing correctly but my background process > ($command) is printing few extra env, which i set it in different cgi > script. > > e.g. "script1.pl" is setting $ENV{foo1} = "foo1" and firing print > `command1 &`; > and "script2.pl" is setting $ENV{foo2} = "foo2" and firing print > `command2 &`; > > after few hits both env(foo1 and foo2) are visible to both background > processes. > while /perl-status?env is displaying correctly. > Here command1 and command2(perl scripts) are just printing env > > Apache/1.3.9 (Unix) mod_perl/1.21 with the test case below, i get the expected results: env is missing MOD_PERL all of %ENV should be inherited except for this one. if you have a small test case that i can drop in and run (small like the one below), i'll take a look. my $r = shift; $r->send_http_header; local $ENV{PATH} = '/usr/bin'; $ENV{PACKAGE} = __PACKAGE__; my @env = `env`; my %env; for (@env) { chomp; my($k,$v) = split '='; $env{$k} = $v; } while (my($k,$v) = each %ENV) { next if exists $env{$k}; print "env is missing $k\n"; }
RE: env in background process
On Wed, 23 Aug 2000, Sheth, Niraj wrote: > Didn't get any reply yet on this, so I think i am doing something very > stupid ... i'm still catching up with plenty of unanswered mail in my modperl mailbox, including yours, doing the best i can.
RE: env in background process
Didn't get any reply yet on this, so I think i am doing something very stupid ... Can anyone try it and tell me if gets the same result? Thanks, Niraj > -Original Message- > From: Niraj Sheth [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, August 15, 2000 11:03 AM > To: [EMAIL PROTECTED] > Subject: RE: env in background process > > > Follow up on this. > > script1.pl(set FOO1 env) > === > #!/usr/local/bin/perl > > print "Content-type: text/html\n\n"; > print "PID = $$\n"; > print "SCRIPT1 with FOO1\n"; > > #local %ENV = %ENV; > > $ENV{FOO1} = "foo1"; > print map { "$_ = $ENV{$_}\n"; } sort keys %ENV; > > $command = "dump_env"; > print `$command &`; # put it in the background > > -- end > > script2.pl(set FOO2 env) > === > #!/usr/local/bin/perl > > print "Content-type: text/html\n\n"; > print "PID = $$\n"; > print "SCRIPT1 with FOO2\n"; > > #local %ENV = %ENV; > > $ENV{FOO2} = "foo2"; > print map { "$_ = $ENV{$_}\n"; } sort keys %ENV; > > $command = "dump_env"; > print `$command &`; # put it in the background > > -- end > > dump_env > === > #!/usr/local/bin/perl > > print "$0 @ARGV\n"; > > print map { "$0 $_ = $ENV{$_}\n"; } sort keys %ENV; > > --end > > running "httpd -X" i will get FOO1 and FOO2 both from the print > statement of dum_env. > while script1.pl is ONLY printing FOO1 which is correct as well as > script2.pl is ONLY printing FOO2 which is also correct. > > so why dump_env is getting both? > If I either uncomment "local %ENV = %ENV;" in script or put > "%ENV = ();" > in PerlCleanupHandler then dump_env is working fine. > I tried both Apache::PerlRun and Apache::Registry which same result. > > I would appreciate any help. > > -Niraj > > > -Original Message- > > From: Niraj Sheth [mailto:[EMAIL PROTECTED]] > > Sent: Monday, August 14, 2000 12:10 PM > > To: [EMAIL PROTECTED] > > Subject: env in background process > > > > > > Hi, > > > > I am having very strange problem with environment variables. > > > > >From Apache::PerlRun script(cgi) I am setting env and firing > > background > > process .. > > system("$command &") (or print `$command &`;) > > > > now looks like environment variable being persistence b/w different > > requests ONLY in background process. so it's looks to me > that mod_perl > > > is setting proper "Perl Level" env but failing to reset env > > at "c level" > > or "process level". I know it's sounds very weird. > > /perl-status?env is printing correctly but my background process > > ($command) is printing few extra env, which i set it in > different cgi > > script. > > > > e.g. "script1.pl" is setting $ENV{foo1} = "foo1" and firing print > > `command1 &`; > > and "script2.pl" is setting $ENV{foo2} = "foo2" and firing print > > `command2 &`; > > > > after few hits both env(foo1 and foo2) are visible to both > background > > processes. > > while /perl-status?env is displaying correctly. > > Here command1 and command2(perl scripts) are just printing env > > > > Apache/1.3.9 (Unix) mod_perl/1.21 > > Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: > > Platform: > > osname=solaris, osvers=2.6, archname=sun4-solaris > > uname='sunos nlsun268 5.6 generic_105181-14 sun4u sparc > > sunw,ultra-4 > > ' > > hint=recommended, useposix=true, d_sigaction=define > > usethreads=undef useperlio=undef d_sfio=undef > > Compiler: > > cc='gcc', optimize='-O', gccversion=2.8.1 > > cppflags='-I/usr/local/include' > > ccflags ='-I/usr/local/include' > > stdchar='unsigned char', d_stdstdio=define, usevfork=false > > intsize=4, longsize=4, ptrsize=4, doublesize=8 > > d_longlong=define, longlongsize=8, d_longdbl=define, > > longdblsize=16 > > alignbytes=8, usemymalloc=y, prototype=define > > Linker and Libraries: > > ld='gcc', ldflags =' -L/usr/local/lib' > > libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib > > libs=-lsocket -lnsl -ldl -lm -lc -lcrypt > > libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a > > Dynamic Linking: > > dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' > > cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib' > > > > > > Any comments? > > > > Thanks, > > Niraj > > >
RE: env in background process
Follow up on this. script1.pl(set FOO1 env) === #!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "PID = $$\n"; print "SCRIPT1 with FOO1\n"; #local %ENV = %ENV; $ENV{FOO1} = "foo1"; print map { "$_ = $ENV{$_}\n"; } sort keys %ENV; $command = "dump_env"; print `$command &`; # put it in the background -- end script2.pl(set FOO2 env) === #!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "PID = $$\n"; print "SCRIPT1 with FOO2\n"; #local %ENV = %ENV; $ENV{FOO2} = "foo2"; print map { "$_ = $ENV{$_}\n"; } sort keys %ENV; $command = "dump_env"; print `$command &`; # put it in the background -- end dump_env === #!/usr/local/bin/perl print "$0 @ARGV\n"; print map { "$0 $_ = $ENV{$_}\n"; } sort keys %ENV; --end running "httpd -X" i will get FOO1 and FOO2 both from the print statement of dum_env. while script1.pl is ONLY printing FOO1 which is correct as well as script2.pl is ONLY printing FOO2 which is also correct. so why dump_env is getting both? If I either uncomment "local %ENV = %ENV;" in script or put "%ENV = ();" in PerlCleanupHandler then dump_env is working fine. I tried both Apache::PerlRun and Apache::Registry which same result. I would appreciate any help. -Niraj > -Original Message- > From: Niraj Sheth [mailto:[EMAIL PROTECTED]] > Sent: Monday, August 14, 2000 12:10 PM > To: [EMAIL PROTECTED] > Subject: env in background process > > > Hi, > > I am having very strange problem with environment variables. > > >From Apache::PerlRun script(cgi) I am setting env and firing > background > process .. > system("$command &") (or print `$command &`;) > > now looks like environment variable being persistence b/w different > requests ONLY in background process. so it's looks to me that mod_perl > is setting proper "Perl Level" env but failing to reset env > at "c level" > or "process level". I know it's sounds very weird. > /perl-status?env is printing correctly but my background process > ($command) is printing few extra env, which i set it in different cgi > script. > > e.g. "script1.pl" is setting $ENV{foo1} = "foo1" and firing print > `command1 &`; > and "script2.pl" is setting $ENV{foo2} = "foo2" and firing print > `command2 &`; > > after few hits both env(foo1 and foo2) are visible to both background > processes. > while /perl-status?env is displaying correctly. > Here command1 and command2(perl scripts) are just printing env > > Apache/1.3.9 (Unix) mod_perl/1.21 > Summary of my perl5 (5.0 patchlevel 5 subversion 3) configuration: > Platform: > osname=solaris, osvers=2.6, archname=sun4-solaris > uname='sunos nlsun268 5.6 generic_105181-14 sun4u sparc > sunw,ultra-4 > ' > hint=recommended, useposix=true, d_sigaction=define > usethreads=undef useperlio=undef d_sfio=undef > Compiler: > cc='gcc', optimize='-O', gccversion=2.8.1 > cppflags='-I/usr/local/include' > ccflags ='-I/usr/local/include' > stdchar='unsigned char', d_stdstdio=define, usevfork=false > intsize=4, longsize=4, ptrsize=4, doublesize=8 > d_longlong=define, longlongsize=8, d_longdbl=define, > longdblsize=16 > alignbytes=8, usemymalloc=y, prototype=define > Linker and Libraries: > ld='gcc', ldflags =' -L/usr/local/lib' > libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib > libs=-lsocket -lnsl -ldl -lm -lc -lcrypt > libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a > Dynamic Linking: > dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' ' > cccdlflags='-fPIC', lddlflags='-G -L/usr/local/lib' > > > Any comments? > > Thanks, > Niraj >