qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jason Schlauch (JIRA)" <qpid-...@incubator.apache.org>
Subject [jira] Commented: (QPID-2367) Early Initialization of File Descriptors Conflicts With Daemon Best Practices
Date Mon, 01 Feb 2010 21:38:18 GMT

    [ https://issues.apache.org/jira/browse/QPID-2367?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12828278#action_12828278
] 

Jason Schlauch commented on QPID-2367:
--------------------------------------

Yes, you don't need to handle anything other than stdout, stdin, and stderr.  However, for
whatever reason, boilerplate daemon code often suggests (and goes on to implement) closing
all file descriptors.  So perhaps "best practice" wasn't quite accurate, and "common practice"
or "it was in the code you inherited" might be better.

I handled this by simply changing the daemon code to close only stdout, stdin, and stderr.
 Finding the error, however, took up a fair chunk of time.  Some defensive coding in the QPID
client might save others the same trouble.

For example, could you simply check if the fd was open before attempting to use it (and reopen
it if it's not)?

> Early Initialization of File Descriptors Conflicts With Daemon Best Practices
> -----------------------------------------------------------------------------
>
>                 Key: QPID-2367
>                 URL: https://issues.apache.org/jira/browse/QPID-2367
>             Project: Qpid
>          Issue Type: Improvement
>          Components: C++ Client
>    Affects Versions: 0.5
>         Environment: Linux (possibly all UNIX), c++, g++
>            Reporter: Jason Schlauch
>
> At least one file descriptor (in qpid/sys/epoll/EpollPoller.*) in the c++ client is global
and declared as static.  In programs linked against the c++ qpid libs g++ generates code for
allocation and, more importantly, initialization of these descriptors that occurs before main().
 You can confirm this with gdb by breakpointing both the initialization and main() (the initialization
break is hit first).
> On the other hand, the canonical recipe for creating a UNIX daemon calls for the closing
of all open file descriptors after fork()ing (where the fork() certainly occurs after main()).
 While not an absolute requirement, closing all open file descriptors is considered a best
practice.  A loop to close all descriptors is also common in boilerplate daemon creation code
and has undoubtedly been cut-and-pasted into numerous daemons.
> The net effect is that the typical daemon will close the file descriptor opened before
main() in the c++ client library.  In the case of the epoll code this manifests as an inability
to connect to the broker.
> A fix for this would be to defer the initialization of the file descriptor (perhaps via
the Singleton pattern or a move of the variables into a class member).

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:dev-subscribe@qpid.apache.org


Mime
View raw message