Perhaps this all just illustrates a pile of bad assumptions I've
been making, but:

I have a perl app that daemonizes itself.  Among it's daemonizing
efforts, it closes all file handles.

My app currently utilizes a third-party perl module, which in turn
makes use of the DATA file handle, as described in perldata(1).
(For all my years of using perl, this was the first I ran into this
mechanism, so it took a while to track down why this perl module
was misbehaving.)

My efforts to come up with a workaround were thwarted by a difficulty
on my part in determining that the DATA file handle was was
compromised.

Attached is a simple perl module, and a test program that fires
it's various methods; it scribble its output to syslog, if you want
to follow along.

The upshot is, when I used POSIX::close to close all file descriptors,
somehow the DATA descriptor remained alive:

- It was defined.
- I could retrieve a file descriptor via fileno().
- I could use seek() and tell() to get/set my filepos.

Only stat() seemed to report that there was something was amiss.

I would have though fileno(), etc, would have also reported problems.

Should they have?

I admit, I've not pawed though and bug lists or change lists to see
if this is different under newer releases...

Example output:

An initial working pass:

  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [info][fileno][4][4]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [info][tell][1333][1333]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [info][eof][][]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: 
[info][stat][2054,32313,33152,1,0,0,0,1364,1288734213,1288734093,1288734093,4096,8][12]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [print_end_data][Random text; 
don't mind me... ]

Then, I close all descriptors, but can still utilize the file handle,
except that I can't read past whatever my filepos was prior to the
descriptor closing:

  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [close_fds]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [seek_data][1333]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [info][fileno][4][4]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [info][tell][1364][1364]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [info][eof][1][1]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [info][stat][][-1]
  Nov  2 21:43:33 10-160-62-45 ./bar.pl[5463]: [print_end_data][<undefined>]

(In this pass the eof() flag is set, because the print_end_data()
method was fired.)

In my test code, if you comment out my use of seek_data(), and then
use _init_DATA, you can see my use of stat() detects this case, and
resets everything.

My environment:

  # perl -v

  This is perl, v5.8.8 built for i386-linux-thread-multi

  # cat /etc/redhat-release
  CentOS release 5.4 (Final)

-- 
Brian Reichert                          <[email protected]>
55 Crystal Ave. #286                    
Derry NH 03038-1725 USA                 BSD admin/developer at large    
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to