<?xml version="1.0" encoding="windows-1252"?>
<node id="841193" title="Re^4: Proc::PID::File problem generating pid files, or: does it matter where a pid file lives?" created="2010-05-22 13:36:07" updated="2010-05-22 13:36:07">
<type id="11">
note</type>
<author id="630906">
proceng</author>
<data>
<field name="doctext">
&lt;blockquote&gt;Are you aware that this still has a race condition? You run a lot of tests in step 1, most of those tests involve system calls. Step 2 has two system calls. Each and every system call may cause a task switch to a malicious program that -- with a little bit of luck and good timing -- can change what you checked for in step 1, causing the following steps to fail rather unexpectedly. And each and every system call may cause a task switch to a second instance fighting for the PID file.&lt;/blockquote&gt;
Alexander:&lt;br&gt;
Yes, I am &lt;em&gt;quite&lt;/em&gt; aware that there may be a race condition (but also that the condition &lt;em&gt;may be rare&lt;/em&gt;).  Since many of the steps, by their nature, &lt;em&gt;can not be atomic&lt;/em&gt;, that is a chance that is taken.  I would rather know &lt;em&gt;before&lt;/em&gt; attempting to connect to a database (for example) that it &lt;em&gt;could be in an inconsistent state&lt;/em&gt; due to an abnormal termination.  While everything may work right, simply knowing &lt;strong&gt;about the problem&lt;/strong&gt; can go a long way to preventing it from happening in the future.&lt;p&gt;
Many of the options (like the daemontools that you note), do &lt;em&gt;the same things that I describe&lt;/em&gt; (just masking them from the programmer).&lt;br&gt;
While you are correct that &lt;strike&gt;many&lt;/strike&gt;some daemons do not need certain functions, that &lt;em&gt;does not mean&lt;/em&gt; that they do not have their place.  Add to that the fact that packages such as daemontools have their own built in set of limitations:
&lt;blockquote&gt;System requirements&lt;br&gt;
daemontools works &lt;strong&gt;only&lt;/strong&gt; under UNIX.&lt;/blockquote&gt;
and that they require &lt;em&gt;an extra installation step&lt;/em&gt; to accomplish &lt;em&gt;the same goal&lt;/em&gt;, and you can see that it is useful to know &lt;strong&gt;what is being done and why&lt;/strong&gt;.&lt;p&gt;
In my opinion, when you &lt;em&gt;have to adjust&lt;/em&gt; to another's decisions (and add complexity at the same time), it is not necessarily a good thing.</field>
<field name="root_node">
841112</field>
<field name="parent_node">
841182</field>
</data>
</node>
