From nobody Mon Feb 9 01:20:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1646395197; cv=none; d=zohomail.com; s=zohoarc; b=cvxpiYMqXD0kRc8fVJEY0s+e9/E6d444XALzMg1lbdMI/FtEbaGoPVgtj4zXbty8QhQ1y7QgKzg9q1lQ33iykbi9hRs0vVa4cgEcR7EObajtsN53VZM2qbuxQCLs2PHe4UUfI2lcR74qcbGKQj12TEoDF+esJTZLrUggTccRsSI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646395197; h=Content-Type:Content-Transfer-Encoding:Cc: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=jYUk71hHJIIE+9k9q3hziT3DOL5otXzLZO7z1pTCA2Y=; b=a1LMpV8HY+tKS4IDuj9OKOR4bJc7i78Q+Lx4TE+njVuhQDL7WxBVcpHDJFk9QXgwIQ1ONJvWHNRWZAKd9vJe6HslX1pDZROhSWwiEmVkWw2RG4IRQ0xp84f7m7Ut6fBfUGy7tfMOKZZ/8vPLLoakSjzJegTdhhWcJfKmZm8cXRk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1646395197341520.6526602571884; Fri, 4 Mar 2022 03:59:57 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-395-O2fVxvCsPcS_n8PRvTQ2Yw-1; Fri, 04 Mar 2022 06:59:55 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 194CB51E0; Fri, 4 Mar 2022 11:59:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D72517D3E2; Fri, 4 Mar 2022 11:59:49 +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 9BD121809CB5; Fri, 4 Mar 2022 11:59:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 224BvkxV028875 for ; Fri, 4 Mar 2022 06:57:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 75FF02B4AC; Fri, 4 Mar 2022 11:57:46 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.39.194.222]) by smtp.corp.redhat.com (Postfix) with ESMTP id CC0EF2B450; Fri, 4 Mar 2022 11:57:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646395196; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=jYUk71hHJIIE+9k9q3hziT3DOL5otXzLZO7z1pTCA2Y=; b=TfxPxHudSbgi1BkaQCgBC1rvKF5BEFccE02RMYz7Urdy0vYbcjUyVjgZQyZNYar9AgKSLT XkQbbaToaI2jJRbfhpNdSFCAFgvjxrkLiYxLrRvmNTRXVX+Nmi+eQnxjIltDMzAUqQrT+e LGApqSQnxb11j+gbWBl9lgnAdLrPW/4= X-MC-Unique: O2fVxvCsPcS_n8PRvTQ2Yw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Subject: [PATCH 3/4] os-posix: refactor code handling the -chroot argument Date: Fri, 4 Mar 2022 11:56:56 +0000 Message-Id: <20220304115657.3177925-4-berrange@redhat.com> In-Reply-To: <20220304115657.3177925-1-berrange@redhat.com> References: <20220304115657.3177925-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , libvir-list@redhat.com, Stefan Weil , Hanna Reitz , Gerd Hoffmann , Paolo Bonzini , Eric Blake 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.16 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) X-ZM-MESSAGEID: 1646395198230100001 Change the change_root() function so that it takes its input as parameters instead of relying on static global variables. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- os-posix.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/os-posix.c b/os-posix.c index 5a127feee2..30da1a1491 100644 --- a/os-posix.c +++ b/os-posix.c @@ -188,19 +188,16 @@ static void change_process_uid(uid_t uid, gid_t gid, = const char *name) } } =20 -static void change_root(void) +static void change_root(const char *root) { - if (chroot_dir) { - if (chroot(chroot_dir) < 0) { - error_report("chroot failed"); - exit(1); - } - if (chdir("/")) { - error_report("not able to chdir to /: %s", strerror(errno)); - exit(1); - } + if (chroot(root) < 0) { + error_report("chroot failed"); + exit(1); + } + if (chdir("/")) { + error_report("not able to chdir to /: %s", strerror(errno)); + exit(1); } - } =20 void os_daemonize(void) @@ -267,7 +264,9 @@ void os_setup_post(void) } } =20 - change_root(); + if (chroot_dir) { + change_root(chroot_dir); + } if (user_uid !=3D -1 && user_gid !=3D -1) { change_process_uid(user_uid, user_gid, user_name); } --=20 2.34.1