From nobody Thu Nov 28 10:42:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1694137082; cv=none; d=zohomail.com; s=zohoarc; b=S79kcSMdAMLphqCOEceDKfd7Lf8fh9rqavbl/cYtr1RSF4dZlDI6ZnBq3qoNZ9NTIzingIQBg6Y7cSJYZPo07ws+9k2QMZg6rfhytXnP6p2xXMWnqoZPqyFX3UbnEFZKlB+LkkYa3up51Zi2BDla+3nulnZ6EwNOxgWZhiTp8Xo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1694137082; 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=ZJNuuaCbNsUMHmTTdY8oCUznspz2tWW1RL2/pUYQEtM=; b=UQzQCzNuM0zGORcvyIKi4PtDVUgDIsAJwLBAbB3ATyu4zpgpFKdTGU5OTg8G7cqYjo8T7BCBy095FHkadx0fZaJ1A66BLBXXzcgFfd+QbfR23z8e0Z0xIGQ3LeI8DrJNmcZWq4qx6/GrlTtLdKitx2BoIlb+d/IMYjkHHTuygdo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1694137082938858.9344024592622; Thu, 7 Sep 2023 18:38:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qeQQA-000070-M1; Thu, 07 Sep 2023 21:36:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ8-000061-Vo for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:28 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qeQQ5-0007vl-Io for qemu-devel@nongnu.org; Thu, 07 Sep 2023 21:36:28 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-446-ahgntnL3MPKegEPnF7aQbA-1; Thu, 07 Sep 2023 21:36:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 690EB181792D; Fri, 8 Sep 2023 01:36:19 +0000 (UTC) Received: from green.redhat.com (unknown [10.2.16.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id C033B40C2070; Fri, 8 Sep 2023 01:36:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694136985; h=from:from: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; bh=ZJNuuaCbNsUMHmTTdY8oCUznspz2tWW1RL2/pUYQEtM=; b=huiLsrJp07x+Uqa3JwUcxknv7AG9ZhSYIJuYNi70PUDryulSVQ6otBAB+wJ872jkJ9ia31 cCWvfVy/3GjJ8A5AZXtBv45h/83ylb7OjGb2jzVrq3vq7KoTd/ALNiNdkXujRMSnFHnbU+ fRfHguxARqKqt60dzYDWlX2CN9t+jUY= X-MC-Unique: ahgntnL3MPKegEPnF7aQbA-1 From: Eric Blake To: qemu-devel@nongnu.org Cc: "Denis V. Lunev" , Kevin Wolf , Vladimir Sementsov-Ogievskiy , Hanna Reitz , Mike Maslenkin , qemu-block@nongnu.org (open list:Network Block Dev...) Subject: [PULL 12/13] qemu-nbd: Restore "qemu-nbd -v --fork" output Date: Thu, 7 Sep 2023 20:35:48 -0500 Message-ID: <20230908013535.990731-27-eblake@redhat.com> In-Reply-To: <20230908013535.990731-15-eblake@redhat.com> References: <20230908013535.990731-15-eblake@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1694137083782100003 Content-Type: text/plain; charset="utf-8" From: "Denis V. Lunev" Closing stderr earlier is good for daemonized qemu-nbd under ssh earlier, but breaks the case where -v is being used to track what is happening in the server, as in iotest 233. When we know we are verbose, we should preserve original stderr and restore it once the setup stage is done. This commit restores the original behavior with -v option. In this case original output inside the test is kept intact. Reported-by: Kevin Wolf Signed-off-by: Denis V. Lunev CC: Eric Blake CC: Vladimir Sementsov-Ogievskiy CC: Hanna Reitz CC: Mike Maslenkin Fixes: 5c56dd27a2 ("qemu-nbd: fix regression with qemu-nbd --fork run over = ssh") Message-ID: <20230906093210.339585-7-den@openvz.org> Reviewed-by: Eric Blake Tested-by: Eric Blake Signed-off-by: Eric Blake --- qemu-nbd.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 7c4e22def17..1cdc41ed292 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -255,18 +255,23 @@ struct NbdClientOpts { char *device; char *srcpath; SocketAddress *saddr; + int stderr; bool fork_process; bool verbose; }; -static void nbd_client_release_pipe(void) +static void nbd_client_release_pipe(int old_stderr) { /* Close stderr so that the qemu-nbd process exits. */ - if (dup2(STDOUT_FILENO, STDERR_FILENO) < 0) { + if (dup2(old_stderr, STDERR_FILENO) < 0) { error_report("Could not release pipe to parent: %s", strerror(errno)); exit(EXIT_FAILURE); } + if (old_stderr !=3D STDOUT_FILENO && close(old_stderr) < 0) { + error_report("Could not release qemu-nbd: %s", strerror(errno)); + exit(EXIT_FAILURE); + } } #if HAVE_NBD_DEVICE @@ -332,7 +337,7 @@ static void *nbd_client_thread(void *arg) fprintf(stderr, "NBD device %s is now connected to %s\n", opts->device, opts->srcpath); } else { - nbd_client_release_pipe(); + nbd_client_release_pipe(opts->stderr); } if (nbd_client(fd) < 0) { @@ -597,6 +602,7 @@ int main(int argc, char **argv) .device =3D NULL, .srcpath =3D NULL, .saddr =3D NULL, + .stderr =3D STDOUT_FILENO, }; #ifdef CONFIG_POSIX @@ -951,6 +957,16 @@ int main(int argc, char **argv) close(stderr_fd[0]); + /* Remember parent's stderr if we will be restoring it. */ + if (opts.verbose /* fork_process is set */) { + opts.stderr =3D dup(STDERR_FILENO); + if (opts.stderr < 0) { + error_report("Could not dup original stderr: %s", + strerror(errno)); + exit(EXIT_FAILURE); + } + } + ret =3D qemu_daemon(1, 0); saved_errno =3D errno; /* dup2 will overwrite error below */ @@ -1181,7 +1197,7 @@ int main(int argc, char **argv) } if (opts.fork_process) { - nbd_client_release_pipe(); + nbd_client_release_pipe(opts.stderr); } state =3D RUNNING; --=20 2.41.0