From nobody Mon Feb 9 23:40:02 2026 Delivered-To: importer@patchew.org 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; Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1576495107; cv=none; d=zohomail.com; s=zohoarc; b=nr8xEtm2YfVtDna6fhUi493f+4IMPcOEl577dHb+7EsaELMnAcgfd/ElcDoP/3UUgERZ3x4o6CPOu3mwb9b6tcm9XmlZKr4LdK4a5jg7a2X5v1sNdsTHx4+9/SUthIXUBEjkhRQ5iY86oQX5OUHa47IeTSD6us1KMYnzTw1JSuQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576495107; 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=EapHr3pf3XFLFZlU0U22jAMjtMgqM8Xrl+mCmZ4QWKU=; b=jr8yznCp6SxsPqc5YZvQ/TaJ18cfM+8iWh3XHIexjuJnhcbjpd4NR1YWPIBqUYXDQGxwHhVMIPso49pPdhDYTSyTAlwithXeqsErUiD5u9Ek6rRdv9J3C2tnKayrrxkPixUD1HFYxtmnXL042RCge6m/GuGgykpwhzbM7In8OkY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=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 1576495107642667.3014925104858; Mon, 16 Dec 2019 03:18:27 -0800 (PST) Received: from localhost ([::1]:51464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igoOP-0000xM-Op for importer@patchew.org; Mon, 16 Dec 2019 06:18:25 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:50209) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1igoEE-0005XW-OB for qemu-devel@nongnu.org; Mon, 16 Dec 2019 06:07:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1igoED-0003xI-Gc for qemu-devel@nongnu.org; Mon, 16 Dec 2019 06:07:54 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:46134) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1igoED-0003uC-AA for qemu-devel@nongnu.org; Mon, 16 Dec 2019 06:07:53 -0500 Received: by mail-wr1-x443.google.com with SMTP id z7so6668274wrl.13 for ; Mon, 16 Dec 2019 03:07:53 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id u22sm22206820wru.30.2019.12.16.03.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2019 03:07:46 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 573EB1FF9D; Mon, 16 Dec 2019 11:07:33 +0000 (GMT) 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=EapHr3pf3XFLFZlU0U22jAMjtMgqM8Xrl+mCmZ4QWKU=; b=ywpN5YA6aCvHTyEWwS0u5/pYxOTVGI38mdV308SSTsfdYdCFqNkiRzJONqHeQvIcX+ St6hHKunOSzkpdtHTEMgm2+hTv0NK2GIHP4E0YvH5O0+TquOtFi4C+TFC6bD3owOnHQ8 sDNl3lL80pVWkCuTwXnPsebCEL2UIctKVLP/Pn/CbZ2++FU3mDTdq++xf9sJUBk6au0I sIX4mBHcZuP5RigpNU7sY8r/w3XscKmVGnDUi4KdUSURZSHlLHAWslLUVT6P7JUdqHsd UWAvUTjHHhV1SSdsG+AvykT4gh/2ifexeGYP08lcgYUsg0DPRMcQp+P0NQ1HyZOWg9nK P78g== 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=EapHr3pf3XFLFZlU0U22jAMjtMgqM8Xrl+mCmZ4QWKU=; b=KoPS8hwrMbxQ1AA0MNnpsMGjvLnHu9AOPKuACEOXXJ0T+0Iact5g3P7tsxIB/F6seh dI6Q+k+yJeFQMUXsPWkSHo75HXgVXAChObrijj9VfYt3+Jt6k4uFdPfGhlVCltsT9VVY fQZCD/4gUPVcQ9sdAYD3uMdUXf1hwtqpUKVMFduS7rlAExHpYwd4ZpLuWXFm8TFdpeS1 LXPwMSELBgYMc1CRNV72Le0BlDGh5nEyGxLG9BUqVnSDgbLiy88FjV/kBDuDOjjmtWju hAO382lPVvTcgisMVohelsEQCNwqZgLyi0onWBqLbCgNkrdhisnHImIA65fe89Ad/cEn gavw== X-Gm-Message-State: APjAAAUktOFQ3/CCA0dCFJwvTUboNbgv1kQAkhaYrVXytbof1F+iwkSn 8S9jHnrEk+kd37dQSWpGiN2hOQ== X-Google-Smtp-Source: APXvYqwposUjIe7B/3bm7El0RYkM/AZ/pfHVJeqD6KJPTRNrZLCdDQ2fHFxukQOskGqiXYFPyB1i+g== X-Received: by 2002:adf:f803:: with SMTP id s3mr29258255wrp.7.1576494472318; Mon, 16 Dec 2019 03:07:52 -0800 (PST) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v1 13/16] Add a mutex to guarantee single writer to qemu_logfile handle. Date: Mon, 16 Dec 2019 11:07:29 +0000 Message-Id: <20191216110732.24027-14-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191216110732.24027-1-alex.bennee@linaro.org> References: <20191216110732.24027-1-alex.bennee@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: 2a00:1450:4864:20::443 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: fam@euphon.net, berrange@redhat.com, Robert Foley , stefanb@linux.vnet.ibm.com, =?UTF-8?q?Alex=20Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, cota@braap.org, stefanha@redhat.com, marcandre.lureau@redhat.com, pbonzini@redhat.com, aurelien@aurel32.net Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Robert Foley 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 Signed-off-by: Alex Benn=C3=A9e Message-Id: <20191118211528.3221-4-robert.foley@linaro.org> --- util/log.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/util/log.c b/util/log.c index 417d16ec66e..953a66b5a8d 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.20.1