Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 23 Aug 2005 19:42:26 +1000
From:      Peter Jeremy <PeterJeremy@optushome.com.au>
To:        Pawel Jakub Dawidek <pjd@freebsd.org>
Cc:        FreeBSD-arch <freebsd-arch@freebsd.org>
Subject:   Re: New library: libpidfile.
Message-ID:  <20050823094226.GD37107@cirb503493.alcatel.com.au>
In-Reply-To: <20050823081758.GB47261@garage.freebsd.pl>
References:  <20050822213028.GB4812@garage.freebsd.pl> <430A8F1A.6090607@freebsd.org> <20050823081758.GB47261@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help
Firstly, I think that this is useful.  Writing code to correctly
ensure that no more than one copy of a process is running is very easy
to get wrong - and I've seen lots of examples of how not to do it.

On Tue, 2005-Aug-23 10:17:58 +0200, Pawel Jakub Dawidek wrote:
>In my first concept (when it was part of libutil) I allocated memory
>to store needed informations, because I didn't wanted to use preallocated
>memory (someone linking libutil doesn't have to use pidfile
>functionality).

Since there's an initialisation function, why not just malloc whatever
memory you need?  You can either store the pointer in a local static
or have pidfile_open() return it as an opaque pointer that the user
has to pass into other pidfile_XXX functions.

>It also now has 4 functions, which makes it a good candidate of small,
>nice, lightweight library:)

IMHO, 4 functions is too small.  I would prefer to have a smaller
number of larger libraries and think this belongs in an existing
library - eg libutil.  Whilst this may form a nice lightweight
library, if everyone wrote small, lightweight libraries, linking
an application would require a mile-long command line.

Can I suggest two enhancements:
1) Allow NULL to be passed to pidfile_open() to indicate that the
   pidfile should be in /var/run/PROCESS_NAME.pid (and/or if the
   name doesn't include any '/' then default to /var/run)
2) Write a wrapper function that calls pidfile_open() and if it's
   successful, exec's the rest of the command line.

-- 
Peter Jeremy



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050823094226.GD37107>