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

Joel Becker Joel.Becker at oracle.com
Fri Nov 12 16:35:07 PST 2010


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 ;-)

Joel

-- 

"You cannot bring about prosperity by discouraging thrift. You cannot
 strengthen the weak by weakening the strong. You cannot help the wage
 earner by pulling down the wage payer. You cannot further the
 brotherhood of man by encouraging class hatred. You cannot help the
 poor by destroying the rich. You cannot build character and courage by
 taking away a man's initiative and independence. You cannot help men
 permanently by doing for them what they could and should do for
 themselves."
	- Abraham Lincoln 

Joel Becker
Senior Development Manager
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127



More information about the Ocfs2-tools-devel mailing list