You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by RobertCZ <ro...@robert.cz> on 2004/11/22 21:33:22 UTC

Weird file permission problem with File::Temp

-------------8<---------- Start Bug Report ------------8<----------
1. Problem Description:
 
I'm trying to create temp file in PerlFixupHandler using File::Temp, 
write to it, send it to the client and get the temp file automatically 
unlinked upon the end of the request.
I keep getting file permission error.

Relevant part of the handler

use File::Temp ();
$fh = new File::Temp( DIR => '/tmp/aimcache', UNLINK => 1 );

chmod 0777, $fh;
my @ll = split '\n', `ls -la /tmp/aimcache`;
$r->log_error("$_") foreach @ll;

print $fh "test";

$tmpnam = $fh -> filename;
$r -> filename ($tmpnam) ;
return OK;

Error log

[Mon Nov 22 21:34:10 2004] [error] total 8
[Mon Nov 22 21:34:10 2004] [error] drwxrwxrwx   2 apache   apache     36 
Nov 22 21:34 .
[Mon Nov 22 21:34:10 2004] [error] drwxrwxrwt  10 root     root     4096 
Nov 22 20:48 ..
[Mon Nov 22 21:34:10 2004] [error] -rwxrwxrwx   1 apache   apache      0 
Nov 22 21:34 kGs2AahFrA
[Mon Nov 22 21:34:10 2004] [error] Apache::ImageMagick: Write 
/tmp/aimcache/kGs2AahFrA ()
[Mon Nov 22 21:34:10 2004] [error] [client 81.0.228.181] (2)No such file 
or directory: file permissions deny server access: /tmp/aimcache/kGs2AahFrA


 
2. Used Components and their Configuration:
 
*** mod_perl version 1.9916
 
*** using 
/usr/lib/perl5/vendor_perl/5.8.4/i386-linux/Apache2/Apache/BuildConfig.pm
 
*** Makefile.PL options:
  MP_APR_LIB      => aprext
  MP_APXS         => /usr/sbin/apxs2
  MP_COMPAT_1X    => 1
  MP_DEBUG        => 1
  MP_GENERATE_XS  => 1
  MP_INST_APACHE2 => 1
  MP_LIBNAME      => mod_perl
  MP_TRACE        => 1
  MP_USE_DSO      => 3
 
 
*** The httpd binary was not found
 
 
*** (apr|apu)-config linking info
 
 -L/usr/lib -lapr-0 -lrt -lm -lcrypt -lnsl  -lpthread -ldl
 -L/usr/lib -laprutil-0 -lgdbm -ldb-4.1 -lexpat
 
 
 
*** /usr/bin/perl -V
Summary of my perl5 (revision 5 version 8 subversion 4) configuration:
  Platform:
    osname=linux, osvers=2.6.7, archname=i386-linux
    uname='linux knoppix 2.6.7 #2 smp wed jul 28 04:25:36 cest 2004 i686 
intel(r) pentium(r) 4 cpu 3.00ghz genuineintel gnulinux '
    config_args='-des -Darchname=i386-linux -Dcccdlflags=-fPIC 
-Dccdlflags=-rdynamic -Dcc=gcc -Dprefix=/usr -Dvendorprefix=/usr 
-Dsiteprefix=/usr -Dlocincpth=  -Doptimize=-O2 -mcpu=i686 
-fomit-frame-pointer -pipe -Duselargefiles -Dd_semctl_semun 
-Dscriptdir=/usr/bin -Dman1dir=/usr/share/man/man1 
-Dman3dir=/usr/share/man/man3 -Dinstallman1dir=/usr/share/man/man1 
-Dinstallman3dir=/var/tmp/portage/perl-5.8.4-r1/image//usr/share/man/man3 
-Dman1ext=1 -Dman3ext=3pm -Dcf_by=Gentoo -Ud_csh -Di_ndbm -Di_gdbm -Di_db'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef 
usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-fno-strict-aliasing -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64',
    optimize='-O2 -mcpu=i686 -fomit-frame-pointer -pipe',
    cppflags='-DPERL5 -fno-strict-aliasing'
    ccversion='', gccversion='3.3.4 20040623 (Gentoo Linux 3.3.4-r1, 
ssp-3.3.2-2, pie-8.7.6)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', 
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lpthread -lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=/lib/libc-2.3.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.3.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fPIC', lddlflags='-shared -L/usr/local/lib'
 
 
Characteristics of this binary (from libperl):
  Compile-time options: USE_LARGE_FILES
  Built under linux
  Compiled at Oct 12 2004 09:16:58
  %ENV:
    PERL_LWP_USE_HTTP_10="1"
  @INC:
    /etc/perl
    /usr/lib/perl5/site_perl/5.8.4/i386-linux
    /usr/lib/perl5/site_perl/5.8.4
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.4/i386-linux
    /usr/lib/perl5/vendor_perl/5.8.4
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.4/i386-linux
    /usr/lib/perl5/5.8.4
    /usr/local/lib/site_perl
    .
 
 
3. This is the core dump trace: (if you get a core dump):
 
  [CORE TRACE COMES HERE]
 
This report was generated by -e on Mon Nov 22 20:24:42 2004 GMT.
 
-------------8<---------- End Bug Report --------------8<----------

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: Weird file permission problem with File::Temp

Posted by RobertCZ <ro...@robert.cz>.
RobertCZ wrote:

> Stas Bekman wrote:
>
>> RobertCZ wrote:
>>
>>> I'm trying to create temp file in PerlFixupHandler using File::Temp, 
>>> write to it, send it to the client and get the temp file 
>>> automatically unlinked upon the end of the request.
>>> I keep getting file permission error.
>>
>> 2) you said:
>> $fh = new File::Temp( DIR => '/tmp/aimcache', UNLINK => 1 );
>> so by the time the response phase comes, the file is not there anymore.
>>
>> instead you could use the approach explained here:
>> http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlCleanupHandler 
>>
>> or simply use the response phase and sendfile() to send the contents.
>
>
> This *|cleanup_register()|* trick works great, thank you very much, I 
> have spent way too much time on this thing...
>
> I'm not sure why Gerald Richter uses PerlFixupHandler but I guess he 
> has his reason, so I don't want to fool with it. (it's 
> Apache::ImageMagick module I'm trying to port)
>
> I have however one more question (I've posted this in other email, but 
> it's related): In this FixupHandler when I create a new file and use 
> it with $r -> filename ($tmpnam) ,  Apache still thinks size is that 
> of the originally requested file. Is there a way to change it? Thanks 
> again.


Geoff  just answered, so just for the archives:

>well, you message is sufficiently vague since I don't have the
>Apache::ImageMagick code handy :)
>
>but I suspect that you mean that the module sets $r->filename and with mp1
>the new filename's stat info is updated, but with mp2 it is not?  if so,
>yes, this is proper - mp1 did magic behind the scenes for you.
>
>with mp2 you need to update the stat info yourself each time you update
>$r->filename. something like this:
>
>  $r->filename($newfile);
>  $r->finfo(APR::Finfo::stat($newfile, APR::FINFO_NORM, $r->pool));
>  
>


Re: Weird file permission problem with File::Temp

Posted by RobertCZ <ro...@robert.cz>.
Stas Bekman wrote:

> RobertCZ wrote:
>
>> I'm trying to create temp file in PerlFixupHandler using File::Temp, 
>> write to it, send it to the client and get the temp file 
>> automatically unlinked upon the end of the request.
>> I keep getting file permission error.
>
> 2) you said:
> $fh = new File::Temp( DIR => '/tmp/aimcache', UNLINK => 1 );
> so by the time the response phase comes, the file is not there anymore.
>
> instead you could use the approach explained here:
> http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlCleanupHandler 
>
> or simply use the response phase and sendfile() to send the contents.


This *|cleanup_register()|* trick works great, thank you very much, I 
have spent way too much time on this thing...

I'm not sure why Gerald Richter uses PerlFixupHandler but I guess he has 
his reason, so I don't want to fool with it. (it's Apache::ImageMagick 
module I'm trying to port)

I have however one more question (I've posted this in other email, but 
it's related): In this FixupHandler when I create a new file and use it 
with $r -> filename ($tmpnam) ,  Apache still thinks size is that of the 
originally requested file. Is there a way to change it? Thanks again.

- Robert



Re: Weird file permission problem with File::Temp

Posted by Stas Bekman <st...@stason.org>.
RobertCZ wrote:
> -------------8<---------- Start Bug Report ------------8<----------
> 1. Problem Description:
> 
> I'm trying to create temp file in PerlFixupHandler using File::Temp, 
> write to it, send it to the client and get the temp file automatically 
> unlinked upon the end of the request.
> I keep getting file permission error.
> 
> Relevant part of the handler
> 
> use File::Temp ();
> $fh = new File::Temp( DIR => '/tmp/aimcache', UNLINK => 1 );

> chmod 0777, $fh;

don't forget to check the success of this operation.

> my @ll = split '\n', `ls -la /tmp/aimcache`;
> $r->log_error("$_") foreach @ll;
> 
> print $fh "test";
> 
> $tmpnam = $fh -> filename;
> $r -> filename ($tmpnam) ;
> return OK;
> 
> Error log
> 
> [Mon Nov 22 21:34:10 2004] [error] total 8
> [Mon Nov 22 21:34:10 2004] [error] drwxrwxrwx   2 apache   apache     36 
> Nov 22 21:34 .
> [Mon Nov 22 21:34:10 2004] [error] drwxrwxrwt  10 root     root     4096 
> Nov 22 20:48 ..
> [Mon Nov 22 21:34:10 2004] [error] -rwxrwxrwx   1 apache   apache      0 
> Nov 22 21:34 kGs2AahFrA
> [Mon Nov 22 21:34:10 2004] [error] Apache::ImageMagick: Write 
> /tmp/aimcache/kGs2AahFrA ()
> [Mon Nov 22 21:34:10 2004] [error] [client 81.0.228.181] (2)No such file 
> or directory: file permissions deny server access: /tmp/aimcache/kGs2AahFrA

1) make sure your httpd.conf is configured to serve from /tmp/aimcache

2) you said:
$fh = new File::Temp( DIR => '/tmp/aimcache', UNLINK => 1 );

so by the time the response phase comes, the file is not there anymore.

instead you could use the approach explained here:
http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlCleanupHandler

or simply use the response phase and sendfile() to send the contents.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html