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

Srinivas Eeda srinivas.eeda at oracle.com
Fri Nov 12 16:29:10 PST 2010


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.



More information about the Ocfs2-tools-devel mailing list