From nobody Thu Nov 6 01:09:01 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538296754573843.0415294463369; Sun, 30 Sep 2018 01:39:14 -0700 (PDT) Received: from localhost ([::1]:54347 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6XFw-0000uU-SV for importer@patchew.org; Sun, 30 Sep 2018 04:39:12 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41320) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g6WrE-0002CO-Tr for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g6WrE-0000I0-6i for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:40 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:34101) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g6WrD-0000GX-W3 for qemu-devel@nongnu.org; Sun, 30 Sep 2018 04:13:40 -0400 Received: by mail-wr1-x42a.google.com with SMTP id z4-v6so9104162wrb.1 for ; Sun, 30 Sep 2018 01:13:39 -0700 (PDT) Received: from 640k.lan (94-36-187-248.adsl-ull.clienti.tiscali.it. [94.36.187.248]) by smtp.gmail.com with ESMTPSA id u76-v6sm11369194wmd.10.2018.09.30.01.13.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 01:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=x01hBqLh3EUAje9UjtWV7GyAdmgRTo3bQ2kbg9s+14U=; b=Emi+/z+PhZyMRINVX5AoDiPVNVSJ3Fl5ajFqmQ1EGypM/EP+F7RPqd0Td7JvFTsXDD tBMHMiJFO6KEuMBwMDVNmLlAo3Vlbo2G8cDn02Xf4zCaf+pz8qpzzAqYizgzOkyWRv+x k1W5esrDi+jHq1s1zal4BzdK0dnblcO1NjVnJQGSmAyWCYFA+6K/OI7OplOd63LPJf0P O1Poi2N/fwUhqaj4G2686LVP/lxfrrOh8CzpnSzZ7f9AEi7PwFEFABrxDdHguJ4goPEr zppDSdWh5wjLAkJhl/acXBw3i61gxL2tQjlH8Dz4y8uuBgo3Y63k0IusLKxYcxWwiGiH koQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=x01hBqLh3EUAje9UjtWV7GyAdmgRTo3bQ2kbg9s+14U=; b=oi4KsNKX1mC4O2TCmxqxI08G+L4xaZRUXwQTFGMSq34BmdZTrqIrIS7suMie3Dugpe HsmziPw+tFyC55RyM5S86oQVy98qsb2HKZut30yIJewjLblu1JjCHz3AggSASHOuJyN2 /p+hEWVoHBtDx0Xlnj5WpwVbFvrAEU67WIOS6w+cL/OiQ5uhpaRgCw6X9jerSmfpsTT3 x5N3+/YgmDyXTEKVwCmB4SH7I61np+nTcr/FzNki6QAhTt0dqAyo6NIqt2MTYxYLiTbe s0seAAzGjplWXL8q5Bo891GdLJlNpoLk7izaxw6mVn6Bo/GXFjJlZiPgNqtzPUxzmcox xWQA== X-Gm-Message-State: ABuFfojh17ftI9UkC+VeW+qJyvGXO9YwbuPs5w2+hnCqhkf76Sw3zESC 6c+VvRHoxS5A8OjWkCBs7X2oO9zE X-Google-Smtp-Source: ACcGV63axxEGpAhGMVGwz9x4hzElvUH6kHqsNdQAQv4lk0DAFrUYkidJ6Y7Rl6t5Z8dwPNS2fnSfDQ== X-Received: by 2002:a5d:4a12:: with SMTP id m18-v6mr3717872wrq.278.1538295218752; Sun, 30 Sep 2018 01:13:38 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sun, 30 Sep 2018 10:12:19 +0200 Message-Id: <1538295197-23704-22-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> References: <1538295197-23704-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42a Subject: [Qemu-devel] [PULL 21/79] util: use fcntl() for qemu_write_pidfile() locking X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 RDKM_2 RSF_0 Z_629925259 SPT_0 From: Marc-Andr=C3=A9 Lureau Daniel Berrang=C3=83=C2=A9 suggested to use fcntl() locks rather than lockf= (). 'man lockf': On Linux, lockf() is just an interface on top of fcntl(2) locking. Many other systems implement lockf() in this way, but note that POSIX.1 leaves the relationship between lockf() and fcntl(2) locks unspecified. A portable application should probably avoid mixing calls to these interfaces. IOW, if its just a shim around fcntl() on many systems, it is clearer if we just use fcntl() directly, as we then know how fcntl() locks will behave if they're on a network filesystem like NFS. Suggested-by: Daniel P. Berrang=C3=83=C2=A9 Signed-off-by: Marc-Andr=C3=83=C2=A9 Lureau Message-Id: <20180831145314.14736-3-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini Signed-off-by: Marc-Andr=C3=A9 Lureau --- util/oslib-posix.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/util/oslib-posix.c b/util/oslib-posix.c index 0e3ab9d..fbd0dc8 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -95,6 +95,11 @@ bool qemu_write_pidfile(const char *path, Error **errp) =20 while (1) { struct stat a, b; + struct flock lock =3D { + .l_type =3D F_WRLCK, + .l_whence =3D SEEK_SET, + .l_len =3D 0, + }; =20 fd =3D qemu_open(path, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR); if (fd =3D=3D -1) { @@ -107,7 +112,7 @@ bool qemu_write_pidfile(const char *path, Error **errp) goto fail_close; } =20 - if (lockf(fd, F_TLOCK, 0) < 0) { + if (fcntl(fd, F_SETLK, &lock)) { error_setg_errno(errp, errno, "Cannot lock pid file"); goto fail_close; } --=20 1.8.3.1