From owner-freebsd-arch@FreeBSD.ORG Tue Aug 23 09:42:35 2005 Return-Path: X-Original-To: freebsd-arch@freebsd.org Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id C14A416A41F; Tue, 23 Aug 2005 09:42:35 +0000 (GMT) (envelope-from PeterJeremy@optushome.com.au) Received: from mail15.syd.optusnet.com.au (mail15.syd.optusnet.com.au [211.29.132.196]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1DDD043D49; Tue, 23 Aug 2005 09:42:34 +0000 (GMT) (envelope-from PeterJeremy@optushome.com.au) Received: from cirb503493.alcatel.com.au (c220-239-19-236.belrs4.nsw.optusnet.com.au [220.239.19.236]) by mail15.syd.optusnet.com.au (8.12.11/8.12.11) with ESMTP id j7N9gRBI006630 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Tue, 23 Aug 2005 19:42:28 +1000 Received: from cirb503493.alcatel.com.au (localhost.alcatel.com.au [127.0.0.1]) by cirb503493.alcatel.com.au (8.12.10/8.12.10) with ESMTP id j7N9gRSR038969; Tue, 23 Aug 2005 19:42:27 +1000 (EST) (envelope-from pjeremy@cirb503493.alcatel.com.au) Received: (from pjeremy@localhost) by cirb503493.alcatel.com.au (8.12.10/8.12.9/Submit) id j7N9gQCo038968; Tue, 23 Aug 2005 19:42:26 +1000 (EST) (envelope-from pjeremy) Date: Tue, 23 Aug 2005 19:42:26 +1000 From: Peter Jeremy To: Pawel Jakub Dawidek Message-ID: <20050823094226.GD37107@cirb503493.alcatel.com.au> References: <20050822213028.GB4812@garage.freebsd.pl> <430A8F1A.6090607@freebsd.org> <20050823081758.GB47261@garage.freebsd.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050823081758.GB47261@garage.freebsd.pl> User-Agent: Mutt/1.4.2i Cc: FreeBSD-arch Subject: Re: New library: libpidfile. X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Aug 2005 09:42:35 -0000 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