[Ocfs2-tools-devel] [PATCH 2/2] o2hbmonitor: add lockfile

Srinivas Eeda srinivas.eeda at oracle.com
Mon Nov 15 03:30:27 PST 2010


I have sent 2 patches(add lockfile patch and add semaphore patch), so 
please reject one and sob or comment on the other :)

On 11/14/2010 6:32 PM, Tristan Ye wrote:
> Joel Becker wrote:
>> On Fri, Nov 12, 2010 at 04:29:10PM -0800, Srinivas Eeda wrote:
>>> Tristan Ye wrote:
>>>> Srinivas Eeda wrote:
>>>>>> #define O2HB_SEM_MAGIC_KEY    0x4A32594B
>>>>>>
>>>>>> int main()
>>>>>> {
>>>>>>    ...
>>>>>>    daemon();
>>>>>>    semid = semget(O2HB_SEM_MAGIC_KEY, 1, IPC_CREAT|IPC_EXCL);
>>>>>>    if (semid < 0) {
>>>>>>       if (errno = EEXIST)
>>>>>>          syslog(LOG_INFO "o2hbmonitor is already running.\n");
>>>>>>       else
>>>>>>            fprintf(stderr, "failed to get semaphore.\n");
>>>>>>       exit(semid);
>>>>>>    }
>>>>>>    openlog();
>>>>>>    monitor();
>>>>>>    sem_close();
>>>>>> }
>>>>> Tristan,
>>>>> thanks for the review and the suggestions :)
>>>>>
>>>>> If a user kills the process with SIGKILL, then he will be 
>>>>> prevented from spawning another process until he  explicitly  
>>>>> removes the semaphore. I think it adds big inconvenience. If user 
>>>>> explicitly removes the lock file and starts another process, then 
>>>>> it doesn't cause much problems. The likely hood of user sending 
>>>>> SIGKILL signal is much larger than removing the file.
>>>> There is a known solution for the cleanup of shared semaphore 
>>>> resources when process gets terminated abnoramlly.
>>>>
>>>> Simply using 'SEM_UNDO' in semop() should work, kernel takes over 
>>>> the cleanup when process was SIGKILLed.
>>>>
>>> agreed. I made the changes and resent the patches.
>>
>>     Lockfiles are a standard system daemon mechanism.  Sure, you can
>> run two of them if you rm the file, but who cares?  That's not a normal
>> case.
>>     Certainly a semaphore works.  But it doesn't store the pid for
>> the startup scripts ;-)
>
> Make sense, lockfile storing pid could be better for start/stop a daemon.
>
>>
>> Joel
>>
>



More information about the Ocfs2-tools-devel mailing list