Tim Pease
4/24/2009 5:19:00 PM
On Fri, Apr 24, 2009 at 10:40 AM, Gary Wright <gwtmp01@mac.com> wrote:
>
> On Apr 24, 2009, at 12:11 PM, James Gray wrote:
>
>> On Apr 24, 2009, at 11:01 AM, Gary Wright wrote:
>>
>>> On Apr 24, 2009, at 11:11 AM, Tim Pease wrote:
>>>>
>>>> This is the standard code to daemonize a process. The use of "exit"
>>>> bothers me slightly, as it will call all "at_exit" handlers in the
>>>> parent. I do not believe this is the desired behavior; the "at_exit"
>>>> handlers will free resources that the daemonized process might need.
>>>
>>> What resources are you talking about? =A0By the time exit is called, th=
e
>>> process has already been duplicated. =A0The child process won't be affe=
cted
>>> by anything the parent does during via at_exit processing (at least
>>> with respect to Ruby object resources).
>>
>> But if that at_exit() handler deletes a file or something=85
>
>
> Well, that is why I put the caveat about 'Ruby object resources'.
> Isn't it fair to assume the at_exit code isn't actively hostile? :-)
>
> If you've got at_exit() code that is trashing external resources that are
> used by a child process, that is a bug to be fixed I think rather than a =
bug
> to be obscured via exit!
>
Yes, I am using an at_exit hook to close out file descriptors used by
loggers. Part of this close out process is writing out some diagnostic
messages to the loggers. These at_exit hooks need to be called when
the child process exits, not when the parent process exits.
The two solutions are:
1) daemonize is the VERY FIRST thing the program should do before any
initialization is run
2) daemonize should use exit! if initialization needs to be performed
before daemonizing
Anyway, it sounds like James is using exit! without ill affect. /me
heads in that direction.
Blessings,
TwP