From nobody Sun Feb 8 05:41:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1616092182; cv=none; d=zohomail.com; s=zohoarc; b=Lwv11rjO+Zga4+rEaMi+A0d4v4aGkzTNas/Cbq0MvfRc0CbGsY/z9gSWbXnquBnVG1SvKYqgls91gNt83PxpplAgpI5mHXd1McMhk7nNu3A2TRnSawLILfeOyTW+tWgJtOO1+FEpMfL1KkE0ejgo5ra4wjZptOhAQ/GuIC5za68= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616092182; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1aN77Q3DhyYqzdpe7QV3EnOaN/xcHD0r0/5c15bI6Zw=; b=n64YU4RooYLvcJqroBa4uQn2XhFxeN+mthtHTTBC+GH+YHvectNMhvknU4RhfuvwP7pZrYuED04OWqPsxJoQkIy81244QVEKw+O3r5sQjX22Gi91CTQUxm7TrB1CFLI2lyV6Fxg21a5aihPHQVmsL4vJoeRNz6dXXQVTcgrF7K4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1616092182796549.6052953695917; Thu, 18 Mar 2021 11:29:42 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-520-RDdD-T1qOF6C342mSOUHPA-1; Thu, 18 Mar 2021 14:29:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 83678108BD10; Thu, 18 Mar 2021 18:29:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14DC160C13; Thu, 18 Mar 2021 18:29:30 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 66C2C4BB7C; Thu, 18 Mar 2021 18:29:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12IITQ6F017212 for ; Thu, 18 Mar 2021 14:29:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7556760CD7; Thu, 18 Mar 2021 18:29:26 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-115-61.ams2.redhat.com [10.36.115.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B1DC60938; Thu, 18 Mar 2021 18:29:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616092181; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=1aN77Q3DhyYqzdpe7QV3EnOaN/xcHD0r0/5c15bI6Zw=; b=a+sz0Xq7FivLIZAx5yV/zypksPcFdCiUIMQr7L4RJdFay2UclhWH0ROK4/mRSYe8K5zVvl zjDxgspvkovUrqjdpLL58nsNzE4n9x9EtpoDlzY2N4+0vxXC5zJoQgmZHHBCpOrif64F5b bbT4E6vpFBLIfOKBk3w0w+hYB5jMbNQ= X-MC-Unique: RDdD-T1qOF6C342mSOUHPA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/2] build: convert the run script to use Python Date: Thu, 18 Mar 2021 18:29:17 +0000 Message-Id: <20210318182918.352240-2-berrange@redhat.com> In-Reply-To: <20210318182918.352240-1-berrange@redhat.com> References: <20210318182918.352240-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) This fits with the goal of eliminating non-Python scripting languages, and makes forthcoming changes far easier. Signed-off-by: Daniel P. Berrang=C3=A9 --- run.in | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/run.in b/run.in index 6ddf5fc58f..99c67c586a 100644 --- a/run.in +++ b/run.in @@ -1,6 +1,6 @@ -#!/bin/sh +#!/usr/bin/env python3 # libvirt 'run' programs locally script -# Copyright (C) 2012-2013 Red Hat, Inc. +# Copyright (C) 2012-2021 Red Hat, Inc. # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -40,35 +40,42 @@ # #---------------------------------------------------------------------- =20 +import os +import os.path +import random +import sys + # Function to intelligently prepend a path to an environment variable. # See https://stackoverflow.com/a/9631350 -prepend() -{ - eval $1=3D"$2\${$1:+:\$$1}" -} +def prepend(env, varname, extradir): + if varname in os.environ: + env[varname] =3D extradir + ":" + env[varname] + else: + env[varname] =3D extradir + +here =3D "@abs_builddir@" =20 -# Find this script. -b=3D@abs_builddir@ +if len(sys.argv) < 2: + print("syntax: %s BINARY [ARGS...]" % sys.argv[0], file=3Dsys.stderr) + sys.exit(1) =20 -prepend LD_LIBRARY_PATH "$b/src" -export LD_LIBRARY_PATH +prog =3D sys.argv[1] +args =3D sys.argv[1:] +env =3D os.environ =20 -prepend PKG_CONFIG_PATH "$b/src" -export PKG_CONFIG_PATH =20 -prepend PATH "$b/tools" -export PATH +prepend(env, "LD_LIBRARY_PATH", os.path.join(here, "src")) +prepend(env, "PKG_CONFIG_PATH", os.path.join(here, "src")) +prepend(env, "PATH", os.path.join(here, "tools")) =20 # Ensure that any 3rd party apps using libvirt.so from the build tree get # files resolved to the build/source tree too. Typically useful for langua= ge # bindings running tests against non-installed libvirt. -LIBVIRT_DIR_OVERRIDE=3D1 -export LIBVIRT_DIR_OVERRIDE +env["LIBVIRT_DIR_OVERRIDE"] =3D "1" =20 # This is a cheap way to find some use-after-free and uninitialized # read problems when using glibc. -random_val=3D"$(awk 'BEGIN{srand(); print 1+int(255*rand())}' < /dev/null)" -export MALLOC_PERTURB_=3D$random_val +env["MALLOC_PERTURB_"] =3D "%d" % random.randint(1, 255) =20 # Run the program. -exec "$@" +os.execve(prog, args, env) --=20 2.30.2