[PATCH] pidfile_check() possible function

Pawel Jakub Dawidek pjd at FreeBSD.org
Tue Jan 17 05:38:10 PST 2006


On Wed, Dec 21, 2005 at 06:41:40PM +0300, Michael Bushkov wrote:
+> Hi!
+> I've made a sample implementation of pidfile_check() function based on pkill's takepid() function. It's interface is like this:
+> int pidfile_check(const char *path, int pidfilelock, pid_t *pidptr);
+> 
+> The patch is here:
+> http://rsu.ru/~bushman/libpidfile.patch
+> 
+> pidfile_check returns 0 if the pidfile owner seems to be active and (-1) otherwise (in case of failure errno would also be set).
+> 
+> The path argument is the path of the pidfile. If pidfilelock is not 0, the function will attempt to lock the file to check if the pidfile owner is currently running. If 
+> pidptr is not NULL and pidfile owner seems to be active, it's pid will be placed in pidptr.

Thanks for the patch.
Some comments:
- There is a missing close(fd) is case of flock() == 0.
- We can avoid reading when pidptr is NULL, right? Now it reads the file
  always, which is not always needed.

I'm not going to commit the patch yet, I'll keep it in mind and commit
when we can find a use for it.

-- 
Pawel Jakub Dawidek                       http://www.wheel.pl
pjd at FreeBSD.org                           http://www.FreeBSD.org
FreeBSD committer                         Am I Evil? Yes, I Am!
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-current/attachments/20060117/598ea5dd/attachment.bin


More information about the freebsd-current mailing list