From nobody Sun Nov 24 22:38:16 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=1720087254; cv=none; d=zohomail.com; s=zohoarc; b=I1fHrCSo3AsUP0ypg8NPrSNEuD2LxFR/z0tWstWNNIi5qPpgjh/sBv9ddqaa40PQ704GzYyQh6eVCzn1hjofQntse2V/QboDZLZE1m1F3jkNRx26lWfchFo7bnwpVMYgDbN8cs9NjRDSCU8iSz4HXNYyzgvjXTTdMIPBz5Wns6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1720087254; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=7MkRViG8QZ36KoPeTrYQRb9R5sxJAqGeAW3NIdlDUcY=; b=OjRtNvyoz/p2V/VsidBMLegTsuDnVX+wJYhNOygm4IXpvuQ4/S/abCtIPGYoA7KX7bX9cFQ7iKKPFiDcEZhiI5zONBwRMnsVLCFcMW2KNbhOknZ2PT0lzaR030irmG4h1CL8BgORm0Fdcd6bXJ0KVikZvsIX5/MHKywFOWsv2y8= 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 1720087254675253.98127140505915; Thu, 4 Jul 2024 03:00:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sPJEs-00077u-Fh; Thu, 04 Jul 2024 05:58:54 -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 1sPJEk-0006up-Dz for qemu-devel@nongnu.org; Thu, 04 Jul 2024 05:58:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sPJEi-00088i-Oj for qemu-devel@nongnu.org; Thu, 04 Jul 2024 05:58:46 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-65-tNuVtscjOc6-240Cr64Ovg-1; Thu, 04 Jul 2024 05:58:41 -0400 Received: by mail-wr1-f69.google.com with SMTP id ffacd0b85a97d-367990a5796so328071f8f.1 for ; Thu, 04 Jul 2024 02:58:41 -0700 (PDT) Received: from avogadro.local ([151.95.101.29]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3675a103366sm17879438f8f.102.2024.07.04.02.58.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jul 2024 02:58:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1720087123; 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=7MkRViG8QZ36KoPeTrYQRb9R5sxJAqGeAW3NIdlDUcY=; b=Urkq4L4IQ2uprxgwuu/HXJLuY0vCp6j/8Ya+pqWPKAn7lErARkj2wVrwUwGnuSP/OTDzzn stFvaJtMCeFcu4THV6u6lV9hKtTfw1JNA3ZRUF8obAwOU3a6JZIBlEMwHttoYn6WZ3kD/+ /X1vhKWc0yH0EImCSbZQ0UILceS1f2w= X-MC-Unique: tNuVtscjOc6-240Cr64Ovg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720087120; x=1720691920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7MkRViG8QZ36KoPeTrYQRb9R5sxJAqGeAW3NIdlDUcY=; b=wE9Q+VN4sUvT7XAjP+/kA8prsI8ptUwxdi6LsQhwRqz0nSkqbbp0YmAY7isVSc0Pr9 uxTARjvDRRQajxKHhnf4PoYHqca3OeXAYTOJsFcaoguwW6OnkzEhzGCemHrq+lCJUFQJ HtWBaOK247nlKuBpQZXBG+2SgNr9j63TrwOI3/NKqF92+BfGmioAYHQcSqvDRcbWZI7t 1X3pMZIt958Y4U0BX4w84knrIKF1oVRN0A37lJgtKbIxPXQTM/xEFYxrasPiLgYOFRWq c1lNUrRQQ1CCuGiR93LTEtcZoHr8TEscHseFg8PX/vcGcKvaTfwb1Y7gtkukMBQKV/sT rRyQ== X-Gm-Message-State: AOJu0YzRZ1bJW7ujvM//twM1m2RcuDR9873r/pULzXRfW/NBtgJGPIZ9 A5RtVLjarUXr046OCCRimzEP7hF0xwNSIDq8PbMrWNhz3ndVqcf6F+r6OoP91tAsYxVy8Ne9XVD ucPLK155SAjQT+2VLMg/K7S+YgBYpyGrrOk7ubf1JwQTti5Npy+GCa8bybrXmlvPsKMtmMi69mV npoV9l27Gu7oqFsTSclwYbsKlDZ0X4XGW1Xsfq X-Received: by 2002:a5d:5265:0:b0:367:9ce3:1667 with SMTP id ffacd0b85a97d-3679dd3c4eemr791563f8f.15.1720087120022; Thu, 04 Jul 2024 02:58:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGeWQQn67J2uNHzR8rJjJIkc2KFIzrg2kotGZayvEsJHFaCKCLm0Ujp2E8Z28vRLJSuY4OYwg== X-Received: by 2002:a5d:5265:0:b0:367:9ce3:1667 with SMTP id ffacd0b85a97d-3679dd3c4eemr791554f8f.15.1720087119695; Thu, 04 Jul 2024 02:58:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Maxim Mikityanskiy Subject: [PULL 14/16] char-stdio: Restore blocking mode of stdout on exit Date: Thu, 4 Jul 2024 11:58:04 +0200 Message-ID: <20240704095806.1780273-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240704095806.1780273-1-pbonzini@redhat.com> References: <20240704095806.1780273-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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.129.124; envelope-from=pbonzini@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_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: 1720087256528100003 Content-Type: text/plain; charset="utf-8" From: Maxim Mikityanskiy qemu_chr_open_fd() sets stdout into non-blocking mode. Restore the old fd flags on exit to avoid breaking unsuspecting applications that run on the same terminal after qemu and don't expect to get EAGAIN. While at at, also ensure term_exit is called once (at the moment it's called both from char_stdio_finalize() and as the atexit() hook. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2423 Signed-off-by: Maxim Mikityanskiy Link: https://lore.kernel.org/r/20240703190812.3459514-1-maxtram95@gmail.com Signed-off-by: Paolo Bonzini --- chardev/char-stdio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/chardev/char-stdio.c b/chardev/char-stdio.c index 3c648678ab1..b960ddd4e4c 100644 --- a/chardev/char-stdio.c +++ b/chardev/char-stdio.c @@ -41,6 +41,7 @@ /* init terminal so that we can grab keys */ static struct termios oldtty; static int old_fd0_flags; +static int old_fd1_flags; static bool stdio_in_use; static bool stdio_allow_signal; static bool stdio_echo_state; @@ -50,6 +51,8 @@ static void term_exit(void) if (stdio_in_use) { tcsetattr(0, TCSANOW, &oldtty); fcntl(0, F_SETFL, old_fd0_flags); + fcntl(1, F_SETFL, old_fd1_flags); + stdio_in_use =3D false; } } =20 @@ -102,6 +105,7 @@ static void qemu_chr_open_stdio(Chardev *chr, =20 stdio_in_use =3D true; old_fd0_flags =3D fcntl(0, F_GETFL); + old_fd1_flags =3D fcntl(1, F_GETFL); tcgetattr(0, &oldtty); if (!g_unix_set_fd_nonblocking(0, true, NULL)) { error_setg_errno(errp, errno, "Failed to set FD nonblocking"); --=20 2.45.2