From nobody Tue May 7 05:19:59 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1582730504; cv=none; d=zohomail.com; s=zohoarc; b=D/9yqxQ4zRiKoRtl0Zr+o0P5gK+Smwd86HNS++hcxtgl5KPnEi5zxKYwGX7Qcgt7KG80yJ/So29WCR5gy8Uvo1mmRe/1ERuUBkYtZjbW9qL9Eos3CZsiUTL9LVJyPksZhqjuiFoXEkDp6zXS9UluIL6d8SWFB1PRXIq2FZXs+DA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582730504; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=kjS+2ErQ4GPIg5y6TlhZb+e8aTdIssrh0SZH3CZ3IMI=; b=gwQwzBu7Lv1gLL00M2ovvjXumlzukUdkZqaGGrHEdKqni0oGGZKxz3T8a12htA5JqDKZlw4codIj43e8TyI5WNMZxugOmpATny7pQiBdeWuOpx+MUUAwtbuJ2gQFAGxxwq/iFR3g4sr069nkpyXmJIrfu4daufPPJCJRD5RsUFI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 158273050439319.137824747720515; Wed, 26 Feb 2020 07:21:44 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUc-0001Au-GC; Wed, 26 Feb 2020 15:20:58 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUb-0001Ao-N2 for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 15:20:57 +0000 Received: from mail-qt1-x842.google.com (unknown [2607:f8b0:4864:20::842]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 9672249c-58ab-11ea-aba8-bc764e2007e4; Wed, 26 Feb 2020 15:20:57 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id v25so2484321qto.7 for ; Wed, 26 Feb 2020 07:20:57 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id q196sm327187qke.80.2020.02.26.07.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 07:20:56 -0800 (PST) X-Inumbo-ID: 9672249c-58ab-11ea-aba8-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lygCv0fXeRA8hLfYhPykOOLRebIgfRLYlOPXtqIcsWk=; b=RHmDNteOlXSU6OHAFYOZ/9CR346ldplcfXkIjlwa+1onSg+RiDDAujlgu/Jp60AlmQ aQBJSBRkI4lnLX0+lM6P1j0Phv5qUBNiTsKzTWcHLqTiNRdhbYnp1PMLUm3ErzG3+LBq EaOVswD7Ah/NqWnbtbegQNCz/EGbbWHTI/XABBzwls252l02Wj3N8YOF0TCOItgj9brU ZjrMOxqZHzhlXYNH3w2TbUFDD8pl7PwaV9UO6ud7KW4lNqgTY58PEzeSa95kUSCA0aek mM4vTyexUKmZpP4ZWWC9xH9aAXdgmxtVPc4uJT7UjEH/xZsR4ViDbamKVCu6s1Y2cwhE g+tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lygCv0fXeRA8hLfYhPykOOLRebIgfRLYlOPXtqIcsWk=; b=Z/THKy94ca4R0UXxhq63ljUzU5Lz6kZfwo1hXnkYoy+YWKAHDxpuEeAz8rf7LUDRFm LWWP3WHMZVgJPcbYEaqOOQkUyosnIJnqZJSxhUAhilelkThxhJUos5dxDcKSiipLSwHN /WdAwK9NJgw0tklo3/+91iCkf2VffGSdc8wsOSxMyznDJiczgpyfT/bwxVPTU5dUQtyn 5PLPz/8xyL4aYv8S4AR+CarWb1K7tTDc5n6/PTslMJINKdjb0canuMcYhYBFh+SQEbR8 UzaORNBkibXOUPT10g9yV1B6TLuUyuQu12+x9gIeyH3vDL2zByv6tP3OwQ065Rr8C9lx cWZQ== X-Gm-Message-State: APjAAAWO+C7PNNH3XOW5JyboTQhseSNeP0ciE3p6MLFEFo8KknmBfvqJ f/xbk4/L6RdHqzt9BGcTiwohIRoL X-Google-Smtp-Source: APXvYqy60CO4ZMzSohLAXfZS9PCwcJYwNKm//tr3S7l65LFbTZ9Imic4Yr+HQkHenpRIAuUfRqKuBg== X-Received: by 2002:ac8:4711:: with SMTP id f17mr5404744qtp.160.1582730456832; Wed, 26 Feb 2020 07:20:56 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Date: Wed, 26 Feb 2020 10:20:12 -0500 Message-Id: <20200226152013.12200-2-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200226152013.12200-1-jandryuk@gmail.com> References: <20200226152013.12200-1-jandryuk@gmail.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/2] tools/helpers: Introduce cmp-fd-file-inode utility X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) This is a C implementation of the perl code inside of locking.sh to check that the locked file descriptor and lock file share the same inode and therefore match. One change from the perl version is replacing printing "y" on success with exit values of 0 (shell True) and 1 (shell False). Requiring perl is a large dependency for the single use, so a dedicated utility removes that dependency for systems that otherwise would not install perl. Signed-off-by: Jason Andryuk --- .gitignore | 1 + tools/helpers/Makefile | 3 +++ tools/helpers/cmp-fd-file-inode.c | 43 +++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 tools/helpers/cmp-fd-file-inode.c diff --git a/.gitignore b/.gitignore index 4ca679ddbc..897f878eef 100644 --- a/.gitignore +++ b/.gitignore @@ -164,6 +164,7 @@ tools/fuzz/x86_instruction_emulator/x86-emulate.[ch] tools/helpers/_paths.h tools/helpers/init-xenstore-domain tools/helpers/xen-init-dom0 +tools/helpers/cmp-fd-file-inode tools/hotplug/common/hotplugpath.sh tools/hotplug/FreeBSD/rc.d/xencommons tools/hotplug/FreeBSD/rc.d/xendriverdomain diff --git a/tools/helpers/Makefile b/tools/helpers/Makefile index f759528322..7daf5c46ca 100644 --- a/tools/helpers/Makefile +++ b/tools/helpers/Makefile @@ -8,6 +8,7 @@ include $(XEN_ROOT)/tools/Rules.mk PROGS +=3D xen-init-dom0 ifeq ($(CONFIG_Linux),y) PROGS +=3D init-xenstore-domain +PROGS +=3D cmp-fd-file-inode endif =20 XEN_INIT_DOM0_OBJS =3D xen-init-dom0.o init-dom-json.o @@ -40,12 +41,14 @@ install: all $(INSTALL_PROG) xen-init-dom0 $(DESTDIR)$(LIBEXEC_BIN) ifeq ($(CONFIG_Linux),y) $(INSTALL_PROG) init-xenstore-domain $(DESTDIR)$(LIBEXEC_BIN) + $(INSTALL_PROG) cmp-fd-file-inode $(DESTDIR)$(LIBEXEC_BIN) endif =20 .PHONY: uninstall uninstall: ifeq ($(CONFIG_Linux),y) rm -f $(DESTDIR)$(LIBEXEC_BIN)/init-xenstore-domain + rm -f $(DESTDIR)$(LIBEXEC_BIN)/cmp-fd-file-inode endif rm -f $(DESTDIR)$(LIBEXEC_BIN)/xen-init-dom0 =20 diff --git a/tools/helpers/cmp-fd-file-inode.c b/tools/helpers/cmp-fd-file-= inode.c new file mode 100644 index 0000000000..886ea888ed --- /dev/null +++ b/tools/helpers/cmp-fd-file-inode.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +void usage(const char * prog) +{ + fprintf(stderr, +"%s \n" +"Checks that the open file descriptor (referenced by number) has the same\= n" +"inode as the filename.\n" +"Returns 0 on match and 1 on non-match\n", prog); +} + +int main(int argc, char *argv[]) +{ + struct stat fd_statbuf, file_statbuf; + int ret; + int fd; + + if (argc < 3) { + usage(argv[0]); + return 1; + } + + fd =3D strtoul(argv[1], NULL, 0); + + ret =3D fstat(fd, &fd_statbuf); + if (ret) { + return 1; + } + + ret =3D stat(argv[2], &file_statbuf); + if (ret) { + return 1; + } + + if (fd_statbuf.st_ino =3D=3D file_statbuf.st_ino) + return 0; + else + return 1; +} --=20 2.24.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Tue May 7 05:19:59 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1582730499; cv=none; d=zohomail.com; s=zohoarc; b=DvjWV+usU37hP5Q3Ve5Pcbz1ija+bOaShifurqdO1ecy3iDi98p3a/jpP118qGzJ4W4NF3RhBmn5xnct3Vtm9IEWVGi2aCO+WpIqFFa7qLVyM081ixs2EARTUn3tVL9DLOI4Nqy/1LPa5mgTgR6z4XiJp/ys0RQePURvk6rcREw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582730499; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=AzpbDroNSOfbV2EhTlJ8CfVzm80i7DQ9zq05iAUxmuc=; b=ACwDIyWknsKP2KZ6q4OZNCERbM0eZaxrumkvISEN4J/k5xw1u/fmZ35LuaOJAvWjqXDsZkwMr1c1YfBec8DwjS9czehAmgih2OzlFLnY6cMZ5H3Io8X7yB02jyWOnRXnDb23dkKX0OxSw9YZO01115S+KTyYrhEWLm+8gT2HqNk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1582730499734744.708532967336; Wed, 26 Feb 2020 07:21:39 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUh-0001CK-Ph; Wed, 26 Feb 2020 15:21:03 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j6yUg-0001C9-MU for xen-devel@lists.xenproject.org; Wed, 26 Feb 2020 15:21:02 +0000 Received: from mail-qt1-x841.google.com (unknown [2607:f8b0:4864:20::841]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 97d1ba78-58ab-11ea-a490-bc764e2007e4; Wed, 26 Feb 2020 15:20:59 +0000 (UTC) Received: by mail-qt1-x841.google.com with SMTP id r5so2480833qtt.9 for ; Wed, 26 Feb 2020 07:20:59 -0800 (PST) Received: from pm2-ws13.praxislan02.com ([2001:470:8:67e:ba27:ebff:fee8:ce27]) by smtp.gmail.com with ESMTPSA id q196sm327187qke.80.2020.02.26.07.20.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Feb 2020 07:20:58 -0800 (PST) X-Inumbo-ID: 97d1ba78-58ab-11ea-a490-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VFOAd65lQswkmbzdAMYJGUSVTalFZ80HbsJPAnnzq2k=; b=Qy+LmqcnrO4tFK9DKfrKCg5Xis7lwdWKVieMep9iDcrcSHJ2Jpvhaz9JsSc+6qxkhv 3JWWZUBFyGe728K9iYsFiFzQ6B5kgvFoB/UVaOaP2jIxVRomPkq1y6sBVk4zyUfHTKcf 8f+j8NeauX6qJ3g2J7J46aYdnVZbE5ROYGAWY+gdHvuKLzAzcuSVF+XgCauVRpGwOk5l x3p2NYqzUzhUgtSp+7OEP/g+/yqpd1BzVrxUAXfnXi2WQQlwm1tSLd8wvtjU7wNfLn6N qAenp6eU1BfcwKbmGFPYKb1z2I1hnaLahBjMCJU+ed+oqQz/PXRKw5loICccv5uaV5VM GaAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VFOAd65lQswkmbzdAMYJGUSVTalFZ80HbsJPAnnzq2k=; b=OimENtyiGpT/VDy5nnjuyVCseCvHGac0LrB2tN/afUP9/jtJ4KUAQ1bgbuSsC3dLgw wcnnWi64DodHKbP2TRPXEe8ubgzdnbIjNHtOFFqG7UCjO2ThQRYayDY4VYSTa4Qm4OqM Vz+oFvtgjSm72dVE+GoZrW1aQ0qpxMX6Rq6m1B10jZRfts0L9M6LEXczXLmO5F7n3rBP bMDMSVk57L7vjvHueNMqBht+9jRG7NbdM0LfkBAAtUv8npXcqksa8wxl/kaxl3YQd3Yi /tljjNZ0ASC8DaICnFvUd69K9rzzyWtiCGTidfxf9nNrYSJP6ayd00yq687du7tTp12k JoiQ== X-Gm-Message-State: APjAAAVODoJ65JMxYRAKA1UlrfXYvFl8Oc2CBKGkCxeGkogA3bj4Ab+y Ko8PbdNaGwxZQdPazZV23KqvQhC6 X-Google-Smtp-Source: APXvYqxKwRrFeHXykdEtDwbAPXl/JpTWF8CC8F9DYXFbHDP37dpEi7+p/90GZQv8TsCu4GHmv/9csw== X-Received: by 2002:ac8:7101:: with SMTP id z1mr5242193qto.333.1582730459173; Wed, 26 Feb 2020 07:20:59 -0800 (PST) From: Jason Andryuk To: xen-devel@lists.xenproject.org Date: Wed, 26 Feb 2020 10:20:13 -0500 Message-Id: <20200226152013.12200-3-jandryuk@gmail.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200226152013.12200-1-jandryuk@gmail.com> References: <20200226152013.12200-1-jandryuk@gmail.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 2/2] Linux/locking.sh: Use cmp-fd-file-inode for lock check X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Ian Jackson , Wei Liu , Jason Andryuk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Replace perl with cmp-fd-file-inode when checking that the lock file descriptor and lockfile inodes match. Signed-off-by: Jason Andryuk --- tools/hotplug/Linux/locking.sh | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tools/hotplug/Linux/locking.sh b/tools/hotplug/Linux/locking.sh index c6a7e96ff9..de468c4bb5 100644 --- a/tools/hotplug/Linux/locking.sh +++ b/tools/hotplug/Linux/locking.sh @@ -50,14 +50,8 @@ claim_lock() # actually a synthetic symlink in /proc and we aren't # guaranteed that our stat(2) won't lose the race with an # rm(1) between reading the synthetic link and traversing the - # file system to find the inum. Perl is very fast so use that. - rightfile=3D$( perl -e ' - open STDIN, "<&'$_lockfd'" or die $!; - my $fd_inum =3D (stat STDIN)[1]; die $! unless defined $fd_inu= m; - my $file_inum =3D (stat $ARGV[0])[1]; - print "y\n" if $fd_inum eq $file_inum; - ' "$_lockfile" ) - if [ x$rightfile =3D xy ]; then break; fi + # file system to find the inum. + if cmp-fd-file-inode $_lockfd $_lockfile ; then break; fi # Some versions of bash appear to be buggy if the same # $_lockfile is opened repeatedly. Close the current fd here. eval "exec $_lockfd<&-" --=20 2.24.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel