From nobody Wed Feb 11 02:07:14 2026 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=1667389444; cv=none; d=zohomail.com; s=zohoarc; b=PDZ7H3CPCU0hg9ahE1XOAkiAGfaOppdtHuOF4yVdSXq/94P4goGEx8eRtGhD/yeHMScGLuaiJkpIYdGuIPsdL8o9AwMBg3rNk4Df5iDByUXEsbYsZReAJ8CvVl5zPCLhM0PDjn+vkcVKL6CBL/WkEfGfl1AscvjG12em7mfbh+A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667389444; 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=9rn09GQMUOF2ydOhkJImYso5UybJw5X/9JLC4pgsyc8=; b=L+i5s8A7YuFNhq3aSOODegiZcCBCYc+bhWv1Hu/ZDHI3kBKA7OIwGPE8sBW8TL9NnfaMgyYlqxyHg/dvmDw3NJkQv8MPsJ1hbs/c32hQWDLsZKQRUD6I/T6PK2XOlYv7cfgC61q9H4EJELygMIyBkIdlT6nVHhrxWIqoJAD/wx0= 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 1667389444111729.9178621966425; Wed, 2 Nov 2022 04:44:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oqC8R-0005HK-MJ; Wed, 02 Nov 2022 07:42:19 -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 1oqC7t-00059I-Jy for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41: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 1oqC7r-0005Kf-7T for qemu-devel@nongnu.org; Wed, 02 Nov 2022 07:41:44 -0400 Received: from mail-ej1-f70.google.com (mail-ej1-f70.google.com [209.85.218.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-167-SltbX5WxOzCZyo6AzfMn3w-1; Wed, 02 Nov 2022 07:41:41 -0400 Received: by mail-ej1-f70.google.com with SMTP id hq18-20020a1709073f1200b007ade8dd3494so3477498ejc.2 for ; Wed, 02 Nov 2022 04:41:41 -0700 (PDT) Received: from avogadro.local ([2001:b07:add:ec09:c399:bc87:7b6c:fb2a]) by smtp.gmail.com with ESMTPSA id m27-20020a170906259b00b0077016f4c6d4sm5329879ejb.55.2022.11.02.04.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 04:41:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667389302; 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=9rn09GQMUOF2ydOhkJImYso5UybJw5X/9JLC4pgsyc8=; b=e+2tKXrLBtLxBGjhaEvlzi79DO2XjbHhI+DxwjXP1GDxznQug7ySilFfvXwdbXrMpNQNhn u2JBMz/m2T9P+s3pCrqCGPUBXjoM1JD4AR8kiSsu7GCwuqQ7gnN6/hmeO/O1pX0J9jSVE9 /mzJuh1GEYwmcmf6b2TGAWNeD+EoiwE= X-MC-Unique: SltbX5WxOzCZyo6AzfMn3w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=9rn09GQMUOF2ydOhkJImYso5UybJw5X/9JLC4pgsyc8=; b=6jBxixp7eeCfJ0daRGkV4EzjiEz8z1BmC5gwkasewQ+MLd4WJyE0UFcVEgIrfWV0DF yHFj2h4V6mhjitLQZfBuUVJT0us2mEWLphQNEoJ2Rq9JCExdkB0W5aqMZ2pRQqsjVgW+ FcT5h8pj73f5lCHxBTcZIZXErQ4J7e8WR2BYS3gVrrJCCJsWM6wdXJ2TDQFIx1o9KZIV 3JbGKWgKJwCP7RkN91jkMXMMe/vRysJ5on72ZE0Ip4csSCrWa99slKAQRoMn+Yl7zF5J nFZ5QyXONiF9Oltai10lp/9gFOnQkghVM1kVvkegH0ZK5z36SY7uW49s56FEPQPkTDyO MiBA== X-Gm-Message-State: ACrzQf0N60WrbqWwz2o6Vhik4YhYDp6sUXbzdG06ccif04HSm7Hwq3pf pqs4i+7iAVTlm8NWqXU8uo/ZsDNPN21zC0Zvn6xKqzScNOC09Y7aVg/+2bmoVJb9Tmw7DNMZeGE AQed/L83PtG2QnDui7eYgA/4SQ6DcywQ7izulsRpr3hzBAGLFfVRSUL64OURV7j+BLAA= X-Received: by 2002:a17:907:b16:b0:7ad:855b:c08c with SMTP id h22-20020a1709070b1600b007ad855bc08cmr23565671ejl.667.1667389299510; Wed, 02 Nov 2022 04:41:39 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5EBYlLU0PEqjhSZ0gRiOuYy2bH/tA7NBwtPf8185P3mXcxH04ZaA5ayzLJMC5nYH771SezQA== X-Received: by 2002:a17:907:b16:b0:7ad:855b:c08c with SMTP id h22-20020a1709070b1600b007ad855bc08cmr23565652ejl.667.1667389299273; Wed, 02 Nov 2022 04:41:39 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Greg Kurz , richard.henderson@linaro.org Subject: [PULL 4/5] util/log: Close per-thread log file on thread termination Date: Wed, 2 Nov 2022 12:41:24 +0100 Message-Id: <20221102114125.58902-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102114125.58902-1-pbonzini@redhat.com> References: <20221102114125.58902-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: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1.048, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667389445798100003 Content-Type: text/plain; charset="utf-8" From: Greg Kurz When `-D ${logfile} -d tid` is passed, qemu_log_trylock() creates a dedicated log file for the current thread and opens it. The corresponding file descriptor is cached in a __thread variable. Nothing is done to close the corresponding file descriptor when the thread terminates though and the file descriptor is leaked. The issue was found during code inspection and reproduced manually. Fix that with an atexit notifier. Fixes: 4e51069d6793 ("util/log: Support per-thread log files") Cc: richard.henderson@linaro.org Signed-off-by: Greg Kurz Message-Id: <20221021105734.555797-1-groug@kaod.org> Signed-off-by: Paolo Bonzini --- util/log.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/log.c b/util/log.c index d6eb0378c3a3..39866bdaf2fa 100644 --- a/util/log.c +++ b/util/log.c @@ -42,6 +42,7 @@ static QemuMutex global_mutex; static char *global_filename; static FILE *global_file; static __thread FILE *thread_file; +static __thread Notifier qemu_log_thread_cleanup_notifier; =20 int qemu_loglevel; static bool log_append; @@ -77,6 +78,12 @@ static int log_thread_id(void) #endif } =20 +static void qemu_log_thread_cleanup(Notifier *n, void *unused) +{ + fclose(thread_file); + thread_file =3D NULL; +} + /* Lock/unlock output. */ =20 FILE *qemu_log_trylock(void) @@ -93,6 +100,8 @@ FILE *qemu_log_trylock(void) return NULL; } thread_file =3D logfile; + qemu_log_thread_cleanup_notifier.notify =3D qemu_log_thread_cl= eanup; + qemu_thread_atexit_add(&qemu_log_thread_cleanup_notifier); } else { rcu_read_lock(); /* --=20 2.38.1