From patchwork Fri Nov 15 13:10:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 179497 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp12435610ilf; Fri, 15 Nov 2019 05:14:14 -0800 (PST) X-Google-Smtp-Source: APXvYqwyuCLZ5eVn7XhOwm90VtgwZr6N1UwGHJLRGHZxAq5bFm/iv6s1GghljkDTnHeZYsC788/1 X-Received: by 2002:a05:620a:1672:: with SMTP id d18mr12728288qko.408.1573823654098; Fri, 15 Nov 2019 05:14:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573823654; cv=none; d=google.com; s=arc-20160816; b=JL90M9DPYcR4JuOSCB2N1XatqhSBiad8Ett1P5pmLpAOGKQd3DHgm5ACRk2Fb3sjzk Bmn681GHfGS7wbTSt2X//C6MKmpYhRKiIERdvv9/CY/JYBRRJxdgymnTgzcZCIvZTP7f GHAcUkhgQO/7P8flgqiCusBkVcsd4As89F+9X0RVfwlLetXipaMdLc9jfmTxvEhtvOf3 OFDe1ELXD9AGH6Nse4iOzNt2a4Q3yRb8PyV/AQhA8Pn130jEcbRvhjpYUvGyuDZ0srtO gSW28h1Cx5VUWyP/5OzMsaxta2yAi6mbu/eqeJLwR9FAtSwBfPgHGPLDlSuP2JYNW4ic eCHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=jRenRuOm4Z6evRvZHH+d3jhAxtFeu++eNMWL2guRWVY=; b=c7HbJ5Acw8EdIyLZS7auNU72BoDW+IZNwAUtiC2FxI90r8lhRlysKo6mMLovMFm0EN lQs+VXp5hqmM8Yfbg4yyh9wnzhEqjd92VPsdNKvw8H/ZkUe43n/f+mNzrwK61ASLajpI 8Y8hovJnpKiAGOQcjCAFI/6yxg1n9YTyTuklYk7GgGFIGsmYQGlqvd+BpgEU1e47Luv9 25Nm6XQjPZVR66Wt+SB0A1hwYAXwJ75Yf5yW/VJHy6VOIzDP/zLqHidGOrGxxjnEPfln rzuLkvXuR3mmfzqMYq0j8gKZNVLB9h9zoguPKzhIWP6C8Ac21/XmAgWTPNZnuNBiRTF3 QgpQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h2GbYr87; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id m17si449084qtn.277.2019.11.15.05.14.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Nov 2019 05:14:14 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=h2GbYr87; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39092 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVbQT-00074X-LD for patch@linaro.org; Fri, 15 Nov 2019 08:14:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49432) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVbO0-0004Q8-4C for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iVbNy-0004PT-VE for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:40 -0500 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]:39836) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iVbNy-0004PG-OD for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:38 -0500 Received: by mail-pg1-x543.google.com with SMTP id 29so6007121pgm.6 for ; Fri, 15 Nov 2019 05:11:38 -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=jRenRuOm4Z6evRvZHH+d3jhAxtFeu++eNMWL2guRWVY=; b=h2GbYr87HvO2wfQxpXY34QBWwuM8HUUdVpXw7rgKxdKL+VHHTjcogthG3kC6Go6i9e G9TPtMxTaJrt74cd+XuTwEJo34l5uSkwJj8HWdQIbOjbgEO1kcsmJ9FgCcVv/0NqwqMO Lw6sjH5C86mZTbPacRlkG1TLgPkwmwUAUg9bQAnGvhrhqvmXQkP26ZmoTGaGcNZar4gF WgieA3KkqKbOZCr3V/m+9q/mbqPeRZywAma+k9wCQu7hxBKnH1IMHGNnwRgQSLbiGOda 6eMcuS7ZBFkGewxTIs5yC8H30p/I0VPE1z1rORuTvUFoNc+TgNP9WPkPmlIEGRlSHYYX KUxg== 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=jRenRuOm4Z6evRvZHH+d3jhAxtFeu++eNMWL2guRWVY=; b=V5IObTb2ChuUHnkssaBeoxWX8sKs/HZsZomB9h2yK7QKuEhbtCovzx0LrXP/+n945p Q1wY8FubtJwSdZTXmR9NNr2EwD9Dn3Is3u6mxMqDMgMyGqERkmhfSoe7h/bvd3VHycA4 wmJHGUBpryZ+YUEcM8/gfM1fqckBfyYJMIecgyRvUSA/UflfafOjhXuiwaKGp6KThFEJ 3O4ePyuIvtqsoGL1uu5lcCATnX1qk951oqe28lTd3W7KDVR4r75uJA4E2VJsmYlNJ2o/ Ncdsz5Ok5Wq8LN6Ll1gllbpusyUX4iOFMDkVf8XZwKdEIgnSm62Xzg5dzBKC4l7qtbcA F2iQ== X-Gm-Message-State: APjAAAVm751K2r7jqQyzliUfXFglC0Qk6pbEFxkD8HiOjjJ22UY8IM6F Qabd5SgLAM400NG8s8Vpj9S9odImQeI= X-Received: by 2002:a63:fe4d:: with SMTP id x13mr15657215pgj.82.1573823497512; Fri, 15 Nov 2019 05:11:37 -0800 (PST) Received: from Rfoley-MA01.usrd.futurewei.com ([12.111.81.71]) by smtp.gmail.com with ESMTPSA id w138sm12007249pfc.68.2019.11.15.05.11.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 05:11:36 -0800 (PST) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 3/6] Add a mutex to guarantee single writer to qemu_logfile handle. Date: Fri, 15 Nov 2019 08:10:37 -0500 Message-Id: <20191115131040.2834-4-robert.foley@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191115131040.2834-1-robert.foley@linaro.org> References: <20191115131040.2834-1-robert.foley@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::543 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: peter.puhov@linaro.org, alex.bennee@linaro.org, robert.foley@linaro.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Also added qemu_logfile_init() for initializing the logfile mutex. Signed-off-by: Robert Foley --- v2 - In qemu_set_log() moved location of mutex lock/unlock due to cleanup changes. --- v1 - changed qemu_logfile_init() to use __constructor__. --- util/log.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) -- 2.17.1 Reviewed-by: Alex Bennée diff --git a/util/log.c b/util/log.c index 417d16ec66..91ebb5c924 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" static char *logfilename; +static QemuMutex qemu_logfile_mutex; FILE *qemu_logfile; int qemu_loglevel; static int log_append = 0; @@ -49,6 +51,11 @@ int qemu_log(const char *fmt, ...) return ret; } +static void __attribute__((__constructor__)) qemu_logfile_init(void) +{ + qemu_mutex_init(&qemu_logfile_mutex); +} + static bool log_uses_own_buffers; /* enable or disable low levels log */ @@ -70,7 +77,10 @@ void qemu_set_log(int log_flags) if (qemu_loglevel && (!is_daemonized() || logfilename)) { need_to_open_file = true; } + g_assert(qemu_logfile_mutex.initialized); + 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 +115,7 @@ void qemu_set_log(int log_flags) #endif log_append = 1; } + qemu_mutex_unlock(&qemu_logfile_mutex); } } @@ -240,12 +251,15 @@ void qemu_log_flush(void) /* Close the log file */ void qemu_log_close(void) { + g_assert(qemu_logfile_mutex.initialized); + qemu_mutex_lock(&qemu_logfile_mutex); if (qemu_logfile) { if (qemu_logfile != stderr) { fclose(qemu_logfile); } qemu_logfile = NULL; } + qemu_mutex_unlock(&qemu_logfile_mutex); } const QEMULogItem qemu_log_items[] = {