From nobody Mon Feb 9 19:30:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1574112181; cv=none; d=zoho.com; s=zohoarc; b=kIg/Hw/MNiDL5Q9+UqVJ4X/74QhPOm7Z24EEY3AIpwBlaSS9e0yWyTEhzS6BLrZMnKM0FB4WYA7o4NI8P4tV/0kXK5UwCSCIqkJ0NlyNFPd+qBrKuVtMoMlZMIRhn/sujEaelmf2DdDIUSLuEBeneaz+y3hrZLRvp4eub3d3TCk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1574112181; 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=wafFGt3nPwzzdj7M9taqKk32I4fEwfJNruFpoO9OReo=; b=FTwK3W7sHW1zRTeslUfr2W/cH4d5dU29TKiPG/tsfvi30/Cazfvu1xgXzZNgdOizvqZ8AgJdVgRFWIiZrc4tPY+FSsc0aqT6HF27RuP/rtkdViG3SFnnKCp7BGFlqN4H+bvev9Hxx6sELsLLSzL16BEnIaqldyZyCo2KffFIvy4= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1574112181185133.38549190518404; Mon, 18 Nov 2019 13:23:01 -0800 (PST) Received: from localhost ([::1]:39666 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWoU7-0008Hq-Pi for importer@patchew.org; Mon, 18 Nov 2019 16:22:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:35796) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iWoNC-00004r-Ox for qemu-devel@nongnu.org; Mon, 18 Nov 2019 16:15:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iWoN8-0005ld-TB for qemu-devel@nongnu.org; Mon, 18 Nov 2019 16:15:50 -0500 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]:36194) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iWoN8-0005kY-NL for qemu-devel@nongnu.org; Mon, 18 Nov 2019 16:15:46 -0500 Received: by mail-pf1-x442.google.com with SMTP id b19so10995878pfd.3 for ; Mon, 18 Nov 2019 13:15:46 -0800 (PST) Received: from Rfoley-MA01.usrd.futurewei.com ([12.111.81.71]) by smtp.gmail.com with ESMTPSA id v15sm22301728pfe.44.2019.11.18.13.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Nov 2019 13:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wafFGt3nPwzzdj7M9taqKk32I4fEwfJNruFpoO9OReo=; b=jgIhSQ3gsl9P1WMR7CPp4cIm+p+ZNAWIu6ZTkVkou/VM4I6v1aKIcJteFNx4VOhmFQ Mbpky3kMuv6GtSBaOZsumq/q9BmgutMIHjQsn3d5h0pE6bTLpssX+d+NYixyK6Ocw/rp 6dySDXZLqeXbh+55Kyh5NQCf63mM36/vNGIJ92fW6h4NdAMxXpAh+9vRayRnP03Ont0D VBhKf8Wc1uirhyaBlY3Qc6N2Yo/iyK/iDjywekwbAYWC7H+jPMUcxrINfFeWfiAkZZDB CfmW6bRtLljv2RjFl+Qz0c2ceQEIcdDmwGc2dKr+gHFcYW8EA3ld0w7TZxsFGj1MPkqJ /+ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wafFGt3nPwzzdj7M9taqKk32I4fEwfJNruFpoO9OReo=; b=Ncq3j9MvkfaZR4VQ5MGtaxFzARcps8IyBCAjW1WekW4ZN+Wez4caRMD2mjc0Crr4BY 0j0etJcZZKzKU6JgwCIcHBDR9Ym660LNmRAzSCF3KevUYjJM3dsvS/T0pqXUfSvyp4g3 A45HxNos4caa1fDi5F777PMQWjVApTJVwWGZmIj9U4+Ne89WkT4RFIyBB5AUw2rWfGpc gJI15JMYFDXyeHU8ij/l7o+i+BVQ8jDS4jpvhg8YaIz3u7ZlCcTb95eU1x6BfMKJSywP U6ED08xMkFPYkj7JyYPo4ATfhgEIfr5TljiRhNDm1hlKlvDyPVfdLMqBhtPSCXz8ARUN N9Ew== X-Gm-Message-State: APjAAAU8KDETdh2hg1uKCUqP2zkyT0EMu1fqUw8mEGLefrg2NsfRvTgr 7my7lu7MZkKGejqI18iK71PicP83VbU= X-Google-Smtp-Source: APXvYqwvNNEx4k70oPxbLrC1UnD3YPJQci6bNKDgbRCpd0kUlHvfGtzxIXkq+XWg0EvwyQhJLt64ww== X-Received: by 2002:a65:628f:: with SMTP id f15mr1498253pgv.91.1574111745415; Mon, 18 Nov 2019 13:15:45 -0800 (PST) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v3 3/6] Add a mutex to guarantee single writer to qemu_logfile handle. Date: Mon, 18 Nov 2019 16:15:25 -0500 Message-Id: <20191118211528.3221-4-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191118211528.3221-1-robert.foley@linaro.org> References: <20191118211528.3221-1-robert.foley@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::442 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard.henderson@linaro.org, alex.bennee@linaro.org, robert.foley@linaro.org, peter.puhov@linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Also added qemu_logfile_init() for initializing the logfile mutex. Note that inside qemu_set_log() we needed to add a pair of qemu_mutex_unlock() calls in order to avoid a double lock in qemu_log_close(). This unavoidable temporary ugliness will be cleaned up in a later patch in this series. Signed-off-by: Robert Foley Reviewed-by: Alex Benn=C3=A9e --- v3 - Removed assert that mutex is initialized. =20 We will rely on the constructor. - Also added details in the commit message regarding the=20 temporary ugliness that will be cleaned up in a later patch. --- v2 - In qemu_set_log() moved location of mutex lock/unlock=20 due to cleanup changes. --- v1 - changed qemu_logfile_init() to use __constructor__. --- util/log.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/log.c b/util/log.c index 417d16ec66..953a66b5a8 100644 --- a/util/log.c +++ b/util/log.c @@ -24,8 +24,10 @@ #include "qapi/error.h" #include "qemu/cutils.h" #include "trace/control.h" +#include "qemu/thread.h" =20 static char *logfilename; +static QemuMutex qemu_logfile_mutex; FILE *qemu_logfile; int qemu_loglevel; static int log_append =3D 0; @@ -49,6 +51,11 @@ int qemu_log(const char *fmt, ...) return ret; } =20 +static void __attribute__((__constructor__)) qemu_logfile_init(void) +{ + qemu_mutex_init(&qemu_logfile_mutex); +} + static bool log_uses_own_buffers; =20 /* enable or disable low levels log */ @@ -70,7 +77,9 @@ void qemu_set_log(int log_flags) if (qemu_loglevel && (!is_daemonized() || logfilename)) { need_to_open_file =3D true; } + qemu_mutex_lock(&qemu_logfile_mutex); if (qemu_logfile && !need_to_open_file) { + qemu_mutex_unlock(&qemu_logfile_mutex); qemu_log_close(); } else if (!qemu_logfile && need_to_open_file) { if (logfilename) { @@ -105,6 +114,7 @@ void qemu_set_log(int log_flags) #endif log_append =3D 1; } + qemu_mutex_unlock(&qemu_logfile_mutex); } } =20 @@ -240,12 +250,14 @@ void qemu_log_flush(void) /* Close the log file */ void qemu_log_close(void) { + qemu_mutex_lock(&qemu_logfile_mutex); if (qemu_logfile) { if (qemu_logfile !=3D stderr) { fclose(qemu_logfile); } qemu_logfile =3D NULL; } + qemu_mutex_unlock(&qemu_logfile_mutex); } =20 const QEMULogItem qemu_log_items[] =3D { --=20 2.17.1