From patchwork Fri Jan 27 13:34:05 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 138224 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 00DE3B6EFE for ; Sat, 28 Jan 2012 00:33:14 +1100 (EST) Received: from localhost ([::1]:55266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqlvS-0008Cr-WD for incoming@patchwork.ozlabs.org; Fri, 27 Jan 2012 08:33:11 -0500 Received: from eggs.gnu.org ([140.186.70.92]:59325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqlvF-0007nM-S4 for qemu-devel@nongnu.org; Fri, 27 Jan 2012 08:33:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RqlvA-0004dl-8x for qemu-devel@nongnu.org; Fri, 27 Jan 2012 08:32:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58191) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqlvA-0004db-2K; Fri, 27 Jan 2012 08:32:52 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q0RDWoJ9006110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 27 Jan 2012 08:32:50 -0500 Received: from lacos-laptop.usersys.redhat.com (dhcp-1-169.brq.redhat.com [10.34.1.169]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q0RDWm9G029788; Fri, 27 Jan 2012 08:32:49 -0500 From: Laszlo Ersek To: qemu-devel@nongnu.org, qemu-trivial@nongnu.org, armbru@redhat.com Date: Fri, 27 Jan 2012 14:34:05 +0100 Message-Id: <1327671245-5231-1-git-send-email-lersek@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2] keep the PID file locked for the lifetime of the process X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The lockf() call in qemu_create_pidfile() aims at ensuring mutual exclusion. We shouldn't close the pidfile on success (as introduced by commit 1bbd1592), because that drops the lock as well [1]: "File locks shall be released on first close by the locking process of any file descriptor for the file." Coverity may complain again about the leaked file descriptor; let's worry about that later. v1->v2: - add reference to 1bbd1592 - explain the intentional fd leak in the source [1] http://pubs.opengroup.org/onlinepubs/9699919799/functions/lockf.html Signed-off-by: Laszlo Ersek Reviewed-by: Markus Armbruster --- os-posix.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/os-posix.c b/os-posix.c index 5c437ca..e3ed497 100644 --- a/os-posix.c +++ b/os-posix.c @@ -348,6 +348,6 @@ int qemu_create_pidfile(const char *filename) return -1; } - close(fd); + /* keep pidfile open & locked forever */ return 0; }