geektron has asked for the wisdom of the Perl Monks concerning the following question:
running a job as root, attempting to overwrite files owned by nobody, did weird stuff ... i can't explain it. i put in a lot of extra -e $filename checks to avoid overwriting the files ... and now the script runs just fine.
so why would this segfault?
note: more code added for completeness:
calling CGI script:
MLSUtils.pmmy $mainImg = $self->query->param('propImg'); my $id = $self->query->param('pId') || $self->param('DBH')->{mysql_insertid}; if ($mainImg) { warn " ( $id ) directory ... " . FINALDIR if DEBUG; my $utils = MLSUtils->new(); my $fsName = $utils->save_to_filesystem( $self->query, FINALDIR, 'propImg +' ); my ( $base, $dir, $suffix ) = fileparse( $fsName, qr{\..*} ); my $newImgName = FINALDIR . "/LG${id}_0" . $suffix; warn "passing $newImgName to resizeImg " if DEBUG; $utils->resizeImg( $fsName, $newImgName, 1 ) or die "Resizing images failed! "; $sth = $self->param('DBH')->prepare( "UPDATE jbg_managed_props SET NumPhotos = 1 WHERE jbgPropertyID = ? " ); $sth->execute($id) if ( !$self->query->param('pId') ); } warn "back from images " if DEBUG;
output in error_logsub resizeImg { my ( $self, $imageName, $newImageName, $mkThumb ) = @_; die("Cannot resize null image value") unless ($imageName); warn "before regex: imageName --> $imageName " if DEBUG; warn "before regex: newImageName --> $newImageName " if DEBUG; my ( $base, $dir, $suffix ) = fileparse( $imageName, qr{\..* +} ); my ( $base2, $dir2, $suffix2 ) = fileparse( $newImageName, qr{\..* +} ); $base2 =~ s/LG/TH/; my $tmpName = IMAGEDIR . '/' . $imageName; my $fileName = $newImageName; my $large = Image::Magick->new() or die "NO IMAGE READ!!!: $!"; my $filesRead = $large->Read($imageName); my $thumb = $large->Clone(); my ( $height, $width ) = $large->Get( 'height', 'width' ); my $reduceWlg = LG_MAX_WIDTH / $width; my $reducePercent = $reduceWlg; my $newH = $height * $reducePercent; my $newW = $width * $reducePercent; warn "new IMG: $fileName " if DEBUG; my $attempts; FILEWRITE: { $attempts++; eval { open( NEWIMG, ">$fileName" ) or die "Can't open new imagefile: ($fileName) $! \n"; binmode(NEWIMG); warn "after OPEN and BINMODE" if DEBUG; ###3 don't forget! Image::Magick functions don't have ret +urn values $large->Resize( height => $newH, width => $newW ) ; # or die "Resizing error: $! \n"; warn "RESIZE worked! " if DEBUG; $large->Write( file => \*NEWIMG ); # or die "Write erro +r: $!\n"; warn "WRITE worked! " if DEBUG; close(NEWIMG); }; warn "trying to write the new file ( $fileName ) failed: $@ " +if ($@); redo FILEWRITE if ( $@ and $attempts < 3 ); } #undef $large; warn "New LG image written" if DEBUG; if ($mkThumb) { my $thumbName = "${dir2}/${base2}${suffix2}"; warn "thumb : $thumbName " if DEBUG; my $reduceWth = TH_MAX_WIDTH / $width; $reducePercent = $reduceWth; $newH = $height * $reducePercent; $newW = $width * $reducePercent; $thumb->Resize( height => $newH, width => $newW ); open( NEWIMG, ">$thumbName" ) or die "Can't open new imagefile: ($thumbName) $! \n"; $thumb->Write( file => \*NEWIMG ); close(NEWIMG); warn "New TH image written" if DEBUG; } warn "exiting sub resizeImg()" if DEBUG; return 1; }
no reason for dying, just death. i have another smaller cron-based script which uses the same ImageUtils lib, and it shows the the segfault ( when run via commandline )[Wed Jul 14 19:10:13 2004] admin.cgi: passing /home/httpd/jbgoodwin.co +m/html/image/LG6_6.jpg to resize img at /home/httpd/jbgoodwin.com/lib +s/AdminFunctions.pm line 394. [Wed Jul 14 19:10:13 2004] admin.cgi: before regex: imageName --> /ho +me/httpd/jbgoodwin.com/html/image/Provance Model living 6.jpg at /ho +me/httpd/jbgoodwin.com/libs/MLSUtils.pm line 84. [Wed Jul 14 19:10:13 2004] admin.cgi: before regex: newImageName --> +/home/httpd/jbgoodwin.com/html/image/LG6_6.jpg at /home/httpd/jbgood +win.com/libs/MLSUtils.pm line 85. [Wed Jul 14 19:10:13 2004] admin.cgi: new IMG: /home/httpd/jbgoodwin. +com/html/image/LG6_6.jpg at /home/httpd/jbgoodwin.com/libs/MLSUtils. +pm line 108. [Wed Jul 14 19:10:13 2004] admin.cgi: after OPEN and BINMODE at /home/ +httpd/jbgoodwin.com/libs/MLSUtils.pm line 119. [Wed Jul 14 19:10:13 2004] admin.cgi: RESIZE worked! at /home/httpd/j +bgoodwin.com/libs/MLSUtils.pm line 123. [Wed Jul 14 19:10:13 2004] admin.cgi: WRITE worked! at /home/httpd/j +bgoodwin.com/libs/MLSUtils.pm line 126. [Wed Jul 14 19:10:13 2004] admin.cgi: New LG image written at /home/ht +tpd/jbgoodwin.com/libs/MLSUtils.pm line 136. [Wed Jul 14 19:10:13 2004] admin.cgi: exiting sub resizeImg() at /home +/httpd/jbgoodwin.com/libs/MLSUtils.pm line 158. [Wed Jul 14 19:10:13 2004] [error] [client 24.173.210.82] Premature en +d of script headers: /home/httpd/jbgoodwin.com/html/admin/admin.cgi
i see the "existing sub resizeImg()" warn, but never the "back from images" warn ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: segfault on writing an image?
by BrowserUk (Patriarch) on Jul 15, 2004 at 00:59 UTC | |
by geektron (Curate) on Jul 15, 2004 at 14:43 UTC | |
|
Re: segfault on writing an image?
by hossman (Prior) on Jul 15, 2004 at 01:44 UTC | |
by geektron (Curate) on Jul 15, 2004 at 14:46 UTC | |
|
Re: segfault on writing an image?
by pbeckingham (Parson) on Jul 14, 2004 at 23:09 UTC | |
by geektron (Curate) on Jul 15, 2004 at 00:24 UTC | |
|
Re: segfault on writing an image?
by iburrell (Chaplain) on Jul 15, 2004 at 17:29 UTC | |
by geektron (Curate) on Jul 15, 2004 at 22:12 UTC |