From patchwork Fri Nov 15 13:10:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robert Foley X-Patchwork-Id: 179496 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp12433228ilf; Fri, 15 Nov 2019 05:12:00 -0800 (PST) X-Google-Smtp-Source: APXvYqwV7a/qdJYdRoEdWSQq4stzvTwsiAQAi0ECL4Okbns3pxLqYTkthEBf2/HR500JVkI/EhPv X-Received: by 2002:a0c:ee8c:: with SMTP id u12mr13167078qvr.170.1573823520822; Fri, 15 Nov 2019 05:12:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573823520; cv=none; d=google.com; s=arc-20160816; b=RxFK3vMYAEY6ed4lYGVXILH+6NWoFFpcJIV2VkRZ47yF7v53tIJ5cOjEZPIiitEyWa Es6aVftmv4xU5QPPqGhG30LYzmgABpBW/rPQpi27R5Mx3xHDBsdk6/c93cNzK5+WCZ0q 5oedp0OCn9W8Q4MmwyAJCMG+TS6AXpad1ZARmadXm/MTNXhBxhyq0Yo1u0NxOXsOS2Fd 02G9MOy4Vm7T7oLZBsibl+1J4Wls+gwoS362Ms/oXrnqYsdqv2vspHl+rlVBsVu/mzc+ ROT4Rci3h1RRV4fadfsy99NGlfyorBVRmZtxlQEuJdbMWwmHgNRsNwrViPnfBgDahehv LgTw== 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:references:in-reply-to :message-id:date:subject:to:from:dkim-signature; bh=YlXtkX/1xb+644dG6zbF+PNq9V+WmAv19VZ33vFg8pI=; b=BSNuSOqcAzDYFkz2bD/XHyIe8CtcF42xaxK+FegS2xl0wAehUg2lBxc+7b2chWNfXi 0B3CWJauaBfjEXLqDU7y+Y4YtxECowUmKdAM3ubWG91iuGFWrmkJts19idRmAmGe+z+I R2D+hK6S3nWWv56DfFEH3Llh8i4pnuWfHjN8XYGgg3oTW379fa7GpEzLFpXY9UiCRxxv tbuW4E2477uObkoOUX7XgH6K3KHn9fQV9Xi8+7SYtJWPSQAdT8LSHk83+1/s2Gf7e41J yOiLulZlyicR8kPbfH6H4/XhXXUQKLLavxaMo0nDcak7ie8aE0k1lohkuvZlBaTRepSr HSZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=RsSj9gUh; 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 j64si5402035qkf.279.2019.11.15.05.12.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Nov 2019 05:12:00 -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=RsSj9gUh; 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]:39056 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVbOJ-0004ZH-Tm for patch@linaro.org; Fri, 15 Nov 2019 08:11:59 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49440) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iVbO2-0004TG-2I for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iVbNx-0004Oy-6g for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:41 -0500 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]:42118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iVbNx-0004Oa-1K for qemu-devel@nongnu.org; Fri, 15 Nov 2019 08:11:37 -0500 Received: by mail-pl1-x641.google.com with SMTP id j12so4641045plt.9 for ; Fri, 15 Nov 2019 05:11:36 -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; bh=YlXtkX/1xb+644dG6zbF+PNq9V+WmAv19VZ33vFg8pI=; b=RsSj9gUhivxTJkHSr+Ptto0VCdQhnuD4ABejmu1BpfVu+bl+ZAoLY2uLJNC1IE3eZp 09pIgCx6/ZxuyuouSIxAgK6mOb+VeyLoLLUrMUuL0WZ5qhsqiqr1mN/xJbPXHIkM3EfY QwyxCCH2PTftcwAgD0sREuaj+QImYd0AdJZ1eAAdgP7duj7LSqaYMc5nk+sjqMKuOqVX +m3xjcGdaa/7fbq7dwnpkqHwRSx+J9l9ddp6VV8ItC8ALI6s3tMJNdavuqozlFOb0lST S/R4Ni5ipqO6AFN/yAdNsMn6mL+wqZnpAGVyU8dlJujBcIFg44PFg0xz3zgTGktrJyQH /NLQ== 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; bh=YlXtkX/1xb+644dG6zbF+PNq9V+WmAv19VZ33vFg8pI=; b=hFmGb0rz55MjoyOCXDRBk9QCHdgGx89OIYAym2v87khEroQCdrZ9T9f6r5SA3inFRr YP9GDDQy4I7wbQPF8TUr7YD1X9PoJST4QJoihNSBJeHvmNA2i1E1RfDd2XUopACYLMym rDi4ccUoBcDoy4szYpoSXkNflOw5PGLx/u5hFluWNK/UKj6rwKlu+YJMG/nTcX3IwJyY o4mfweaT/CJkYU2HAixzrcp/gTERwZtCIKP6AahJntGeazsTxeBlqaulubFw/70Qci9j yZFZH0lQnCqnHTgGDGrLPJU3j8lYI3nnBoC8uptBl5eYyN86gcBFUxuzOoA4fvw22v/d tDbg== X-Gm-Message-State: APjAAAXd5PFLv6G4s9GvXe2iOWa0r5XKvrskEFC55ze+f63KQPFlUrC+ IYvjncGABSCzDFdw138afGHUTEY2h/8= X-Received: by 2002:a17:902:9a04:: with SMTP id v4mr15261685plp.192.1573823495736; Fri, 15 Nov 2019 05:11:35 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 05:11:35 -0800 (PST) From: Robert Foley To: qemu-devel@nongnu.org Subject: [PATCH v2 2/6] Cleaned up flow of code in qemu_set_log(), to simplify and clarify. Date: Fri, 15 Nov 2019 08:10:36 -0500 Message-Id: <20191115131040.2834-3-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> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::641 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 some explanation of the reasoning behind the branches. Signed-off-by: Robert Foley --- v2 - This is new in patch v2. --- util/log.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) -- 2.17.1 Reviewed-by: Alex Bennée diff --git a/util/log.c b/util/log.c index 4316fe74ee..417d16ec66 100644 --- a/util/log.c +++ b/util/log.c @@ -54,12 +54,25 @@ static bool log_uses_own_buffers; /* enable or disable low levels log */ void qemu_set_log(int log_flags) { + bool need_to_open_file = false; qemu_loglevel = log_flags; #ifdef CONFIG_TRACE_LOG qemu_loglevel |= LOG_TRACE; #endif - if (!qemu_logfile && - (is_daemonized() ? logfilename != NULL : qemu_loglevel)) { + /* + * In all cases we only log if qemu_loglevel is set. + * Also: + * If not daemonized we will always log either to stderr + * or to a file (if there is a logfilename). + * If we are daemonized, + * we will only log if there is a logfilename. + */ + if (qemu_loglevel && (!is_daemonized() || logfilename)) { + need_to_open_file = true; + } + if (qemu_logfile && !need_to_open_file) { + qemu_log_close(); + } else if (!qemu_logfile && need_to_open_file) { if (logfilename) { qemu_logfile = fopen(logfilename, log_append ? "a" : "w"); if (!qemu_logfile) { @@ -93,10 +106,6 @@ void qemu_set_log(int log_flags) log_append = 1; } } - if (qemu_logfile && - (is_daemonized() ? logfilename == NULL : !qemu_loglevel)) { - qemu_log_close(); - } } void qemu_log_needs_buffers(void)