Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Perl's open() interface (and for that matter the underlying UNIX/Linux open(2) interface) don't allow you to specify a particular file descriptor.

Ah, my mistake. I was confused by the fact that C's fdopen(3) is on the same man-page as fopen(3). "fdopen" is mentioned in perldoc -f open when discussing open's '>&=6' syntax. I saw fopen(path, mode) and fdopen(fd, mode) and conflated the two's capabilities. (open a FILE* given a path, and open a FILE* given an fd number).

The usual way to handle this would be keep creating handles until the descriptor reaches the desired number.

Hmm. Looking at the source for sslclient, it seems the strategy is:

  1. Close fd's 6 and 7.
  2. Open a pipe.
  3. fd_move the pipe's ends to 6 and 7.

fd_move is a qmail-ism, apparently. It uses fcntl(current-fd,F_DUPFD,desired-fd) behind the scenes.

Note also that the parent should be creating a couple of pipes using the pipe() function to create the connections between parent and child.

Oops, yes. Thanks. Forgot in my for-this-node example that parent's "in" is child's "out" and vice versa.

For the curious, perldoc perlipc also suggests that my case warrants $SIG{PIPE} = 'IGNORE'; and $SIG{CHLD} = sub { }; # do something to handle a dead child

In reply to Re: Open a file on a specific file descriptor? by benizi
in thread Open a file on a specific file descriptor? by benizi

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2022-09-24 18:57 GMT
Find Nodes?
    Voting Booth?
    I prefer my indexes to start at:

    Results (115 votes). Check out past polls.