Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

File::MMagic Woes

by Anonymous Monk
on Aug 09, 2000 at 19:12 UTC ( [id://27059]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am currently useing the File::MMagic module to get the type of file without using the standard file command.

The program runs as a server forking processes as it gets a new connection. After running the checktype_filename method once or twice the output becomes inacurate. (i.e. pdf != text/plain)
The seerver also spits out these error messages:
Bad Offset/Type at line 1. 'ng From: message/rfc822
Bad Offset/Type at line 1. 'X transcript text'
Invalid type 'video/unknown' at line 1

I can run an example programing in single exicution and it works fine each time, but in this mode it just does not work. Is there something that I am missing? or is this a baddly written module?

Replies are listed 'Best First'.
RE: File::MMagic Woes (Fork and use vars)
by Russ (Deacon) on Aug 09, 2000 at 20:56 UTC
    Looking in the File::MMagic source, I see this (edited for relevance):
    use vars qw( $dataLoc ); sub new{ $dataLoc = $fh->tell() if (! defined $dataLoc); }
    Question: since $dataLoc is a package-scope variable and will only be initialized once, would this cause problems when forked?

    I wrote some quick and dirty sample code which does, indeed go wrong if I use File::MMagic. I assume Anonymous Monk is using use. If I require File::MMagic after the fork, it seems to work fine.

    So, question to Monks-more-experienced-than-I: What happens to package variables when you fork?

    Russ
    Brainbench 'Most Valuable Professional' for Perl

Re: File::MMagic Woes
by koolade (Pilgrim) on Aug 07, 2001 at 20:44 UTC

    I had the same problems when trying to run the script under mod_perl. The problem ends up being the same thing that Russ pointed out.

    The easiest solution (other than fixing File::MMagic) is to use an external magic file when creating a new File::MMagic object. If you do this, File::MMagic won't try the buggy optimization and will read the file each time a new object is called.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://27059]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 07:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found