From nobody Mon Feb 9 08:29:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1612179130; cv=none; d=zohomail.com; s=zohoarc; b=ffdB5Jf5nWT8ZRUxs7guESwyRKusv6kn76Ox1Upq8qv1Waol6IWwNy2lTEcYXqJsA/j7S3gHkaLgBnebkxM5qDBgtcUr331fiSScX9K45hT1QDbPaUaUVRFz7QTDojyC+IDSVTPQdCTFFXetKa3mIAjdPCxAdFqEIqZaTdHOeS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612179130; 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=Dar8zKAEdn2CDf5Sw+6co0uKNgb51m/uIgx0ssR9ttM=; b=FrcJyqdouRLWii3tKQcWl9ooZxies1oT8zi3eMVIkzlYp9Tbn+xgktzUJnMKz4Vx5GD6R4GUsVZYWJpd0MfTHi5tscTnD9NwE9C41ObC++gp3arTBPPQTzkR5D08Ro+0oCgPAYC/DvqpOIaAs8q1hHE1YXyvHq+1NmynD1xYo4k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1612179130220934.9442856993293; Mon, 1 Feb 2021 03:32:10 -0800 (PST) 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-67-vhTyMzVsMGqmCuDX_8htlg-1; Mon, 01 Feb 2021 06:28:49 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C043C107ACF9; Mon, 1 Feb 2021 11:28:41 +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 9F7905DA2E; Mon, 1 Feb 2021 11:28:41 +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 6B4EF180954D; Mon, 1 Feb 2021 11:28:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 111BSZ8Y003386 for ; Mon, 1 Feb 2021 06:28:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id A88102C313; Mon, 1 Feb 2021 11:28:35 +0000 (UTC) Received: from work.redhat.com (ovpn-113-167.ams2.redhat.com [10.36.113.167]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9ADF26A90A; Mon, 1 Feb 2021 11:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612179129; 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=Dar8zKAEdn2CDf5Sw+6co0uKNgb51m/uIgx0ssR9ttM=; b=f08I/uVUt17lYZWkPhCsjttxT/cF2Y80wbvVP6yBxlnKdbujtxubrFRqwSF6HM4hpEjS9C VdLmgy6dsWg4M27mDhzspawwlvWNBNi2fQI2cRa/FIQplqB3zGNyVpPgPCYDnZFrv3866Z HYYMXyal91+7bGiOOa7Vh8TmU9WGI2A= X-MC-Unique: vhTyMzVsMGqmCuDX_8htlg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 12/20] commandhelper: Factor out printCwd Date: Mon, 1 Feb 2021 12:27:56 +0100 Message-Id: <20210201112804.144366-13-twiederh@redhat.com> In-Reply-To: <20210201112804.144366-1-twiederh@redhat.com> References: <20210201112804.144366-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa , Tim Wiederhake 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.14 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-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Signed-off-by: Tim Wiederhake Reviewed-by: Peter Krempa --- tests/commandhelper.c | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tests/commandhelper.c b/tests/commandhelper.c index cceeb1a119..ce3f64fc9d 100644 --- a/tests/commandhelper.c +++ b/tests/commandhelper.c @@ -176,10 +176,34 @@ static void printDaemonization(FILE *log, struct Argu= ments *args) fprintf(log, "DAEMON:%s\n", getpgrp() !=3D getppid() ? "yes" : "no"); } =20 +static int printCwd(FILE *log) +{ + char *cwd =3D NULL; + char *display; + + if (!(cwd =3D getcwd(NULL, 0))) + return -1; + + if ((strlen(cwd) > strlen(".../commanddata")) && + (STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata")= )) { + strcpy(cwd, ".../commanddata"); + } + + display =3D cwd; + +# ifdef __APPLE__ + if (strstr(cwd, "/private")) + display =3D cwd + strlen("/private"); +# endif + + fprintf(log, "CWD:%s\n", display); + free(cwd); + return 0; +} + int main(int argc, char **argv) { struct Arguments *args =3D parseArguments(argc, argv); size_t i; - char *cwd; FILE *log =3D fopen(abs_builddir "/commandhelper.log", "w"); int ret =3D EXIT_FAILURE; struct pollfd fds[3]; @@ -201,22 +225,8 @@ int main(int argc, char **argv) { =20 printDaemonization(log, args); =20 - if (!(cwd =3D getcwd(NULL, 0))) + if (printCwd(log) !=3D 0) goto cleanup; - if (strlen(cwd) > strlen(".../commanddata") && - STREQ(cwd + strlen(cwd) - strlen("/commanddata"), "/commanddata")) - strcpy(cwd, ".../commanddata"); -# ifdef __APPLE__ - char *noprivateprefix =3D NULL; - if (strstr(cwd, "/private")) - noprivateprefix =3D cwd + strlen("/private"); - else - noprivateprefix =3D cwd; - fprintf(log, "CWD:%s\n", noprivateprefix); -# else - fprintf(log, "CWD:%s\n", cwd); -# endif - free(cwd); =20 fprintf(log, "UMASK:%04o\n", umask(0)); =20 --=20 2.26.2