From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:43484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjDA0-0006Yb-Fu for qemu-devel@nongnu.org; Fri, 06 Jan 2012 12:00:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RjD9u-0002i7-Ur for qemu-devel@nongnu.org; Fri, 06 Jan 2012 12:00:56 -0500 Received: from e1.ny.us.ibm.com ([32.97.182.141]:38268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjD9t-0002hM-MM for qemu-devel@nongnu.org; Fri, 06 Jan 2012 12:00:49 -0500 Received: from /spool/local by e1.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 6 Jan 2012 12:00:47 -0500 Received: from d03av06.boulder.ibm.com (d03av06.boulder.ibm.com [9.17.195.245]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q06H0ihg279020 for ; Fri, 6 Jan 2012 12:00:44 -0500 Received: from d03av06.boulder.ibm.com (loopback [127.0.0.1]) by d03av06.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q06H0gSr003629 for ; Fri, 6 Jan 2012 10:00:42 -0700 Message-ID: <4F0728BA.6020106@linux.vnet.ibm.com> Date: Fri, 06 Jan 2012 11:00:42 -0600 From: Michael Roth MIME-Version: 1.0 References: <4F062390.6070007@intellilink.co.jp> <4F063DD2.3080104@linux.vnet.ibm.com> <20120106105619.GG14293@redhat.com> In-Reply-To: <20120106105619.GG14293@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] GuestAgent: PIDFILE remains when daemon start fails List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Daniel P. Berrange" Cc: Kazuo Tanaka , "MATSUDA, Daiki" , qemu-devel@nongnu.org, Luiz Capitulino On 01/06/2012 04:56 AM, Daniel P. Berrange wrote: > On Thu, Jan 05, 2012 at 06:18:26PM -0600, Michael Roth wrote: >> On 01/05/2012 04:26 PM, MATSUDA, Daiki wrote: >>> Hi, all. >>> >>> I am trying QEMU Guest Agent and encountered a small bug. It is that the >>> PIDFILE remains when daemon start fails. And maybe forgotton to g_free(). >>> >>> MATSUDA, Daiki >>> >> >> Thanks for the patch. There was some contention in the past about >> whether or not to clean up pidfiles when there was abnormal >> termination, but personally I like this approach better. > > Yep, this still leaves open the problem of pidfile cleanup when the > daemon crashes. For libvirtd we recently switched over to a crash-safe > pidfile acquisition design, that uses fcntl(F_SETLK) to maintain > exclusive access over the pidfile. With this you don't need to worry > about forgetting to unlink() on termination, since the POSIX lock is > automatically released when process exits (or crashes). Yup, we did the same at some point via lockf(). An argument was made that stale PID files from unresolved crashes should stick around, so we dropped it. I think we should re-evaluate that decision...libvirt taking the same approach is pretty good precedence for me. I don't expect to have state from crashed programs interrupting attempts to restart them, it's more an unpleasant surprise than a feature, I think. In any case, we should clean PID files when we know/report the reason for the exit, at least. So the patches are good in that regard, but unecessary if we go back to the F_SETLK approach, which I'd prefer. > > If you're interested in copying the algorithm libvirt uses for pidfiles > then look at the virPidFileAcquirePath() function, starting line 308, > and also corresponding virPidFileReleasePath() to (optionally) call > on shutdown: > > http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/util/virpidfile.c;hb=HEAD > > Regards, > Daniel