From patchwork Wed Feb 26 15:20:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Andryuk X-Patchwork-Id: 11406571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2322713A4 for ; Wed, 26 Feb 2020 15:22:21 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F139821D7E for ; Wed, 26 Feb 2020 15:22:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RHmDNteO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F139821D7E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org 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 X-Inumbo-ID: 9672249c-58ab-11ea-aba8-bc764e2007e4 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) 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) 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) 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 += xen-init-dom0 ifeq ($(CONFIG_Linux),y) PROGS += init-xenstore-domain +PROGS += cmp-fd-file-inode endif XEN_INIT_DOM0_OBJS = 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 .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 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 = strtoul(argv[1], NULL, 0); + + ret = fstat(fd, &fd_statbuf); + if (ret) { + return 1; + } + + ret = stat(argv[2], &file_statbuf); + if (ret) { + return 1; + } + + if (fd_statbuf.st_ino == file_statbuf.st_ino) + return 0; + else + return 1; +}