From patchwork Wed Dec 4 09:27:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Dingwall X-Patchwork-Id: 11272565 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 205B6109A for ; Wed, 4 Dec 2019 09:37:02 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 057F52053B for ; Wed, 4 Dec 2019 09:37:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 057F52053B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=dingwall.me.uk Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1icR4j-000391-DG; Wed, 04 Dec 2019 09:36:01 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1icR4i-00038v-2v for xen-devel@lists.xenproject.org; Wed, 04 Dec 2019 09:36:00 +0000 X-Inumbo-ID: 78d03f74-1679-11ea-9c09-bc764e2007e4 Received: from know-smtprelay-omc-1.server.virginmedia.net (unknown [80.0.253.65]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 78d03f74-1679-11ea-9c09-bc764e2007e4; Wed, 04 Dec 2019 09:35:56 +0000 (UTC) Received: from mail0.xen.dingwall.me.uk ([82.47.84.47]) by cmsmtp with ESMTPA id cR4diY7jaxs8ecR4eiohNM; Wed, 04 Dec 2019 09:35:56 +0000 X-Originating-IP: [82.47.84.47] X-Authenticated-User: james.dingwall@blueyonder.co.uk X-Spam: 0 X-Authority: v=2.3 cv=L98zvdb8 c=1 sm=1 tr=0 a=0bfgdX8EJi0Cr9X0x0jFDA==:117 a=0bfgdX8EJi0Cr9X0x0jFDA==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=xqWC_Br6kY4A:10 a=pxVhFHJ0LMsA:10 a=5IRWAbXhAAAA:8 a=mRPDriDQJ0hduQnMumMA:9 a=xo7gz2vLY8DhO4BdlxfM:22 Received: from localhost (localhost [IPv6:::1]) by mail0.xen.dingwall.me.uk (Postfix) with ESMTP id E713A159422; Wed, 4 Dec 2019 09:27:41 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at dingwall.me.uk Received: from mail0.xen.dingwall.me.uk ([127.0.0.1]) by localhost (mail0.xen.dingwall.me.uk [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DIq7iu0M9xbk; Wed, 4 Dec 2019 09:27:41 +0000 (UTC) Received: from behemoth.dingwall.me.uk (behemoth.dingwall.me.uk [192.168.1.5]) by dingwall.me.uk (Postfix) with ESMTP id 94175159416; Wed, 4 Dec 2019 09:27:41 +0000 (UTC) Received: by behemoth.dingwall.me.uk (Postfix, from userid 1000) id 9A520140E1B; Wed, 4 Dec 2019 09:27:41 +0000 (UTC) From: james-xen@dingwall.me.uk To: xen-devel@lists.xenproject.org Date: Wed, 4 Dec 2019 09:27:38 +0000 Message-Id: <20191204092739.18177-4-james-xen@dingwall.me.uk> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191204092739.18177-1-james-xen@dingwall.me.uk> References: <20191204092739.18177-1-james-xen@dingwall.me.uk> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfFbKXe4h9U4sHtQw4v3QuvDrKLs+jDlRDl3PnRwK5sYfjFHy2JmrkLM1TmHYBeDkHyYahSKxz7nSwtkpaxoz10vl6jKpDkI8g7/fSb5sl3ujPm6GaAUo TUdmbkj2H5CP9mAeq3gZCFTiETlOaqNPQKOvJRiq/zSnqLu6Y3aVQlyaEOqC9EqLuyFqE2ODdz24l9ZbyL/f2irqFCsAWf1ZdDskZyLI0b9qAoxPzN9TKrWU moZUZs2DrXEmE0UG0+IfZ3sWOjPdsPf+Yxgmchox4lg= Subject: [Xen-devel] [PATCH 3/4] xenstored logging: send trace messages to syslog X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: wei.liu2@citrix.com, ian.jackson@eu.citrix.com, James Dingwall Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: James Dingwall Unconditionally openlog() since we allow tracesyslog to be changed at runtime. Modify the trace() call to send messages to vsyslog() when tracesyslog is enabled. Note some trace() messages come in several calls before the '\n'. This works well when the output is a file stream but may not suit vsyslog() quite as well. Primarily this feature is for xenstored in a stubdom which doesn't wrap the message until '\n' so no attempt to coalesce trace() calls until '\n' is made. (Could trace() use vfprintf() to write to the log file?) --- tools/xenstore/xenstored_core.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tools/xenstore/xenstored_core.c b/tools/xenstore/xenstored_core.c index d0b383becc..5320db2499 100644 --- a/tools/xenstore/xenstored_core.c +++ b/tools/xenstore/xenstored_core.c @@ -89,7 +89,7 @@ static const char *sockmsg_string(enum xsd_sockmsg_type type); char *s = talloc_asprintf(NULL, __VA_ARGS__); \ if (s) { \ trace("%s\n", s); \ - syslog(LOG_ERR, "%s", s); \ + syslog(LOG_ERR, "%s\n", s); \ talloc_free(s); \ } else { \ trace("talloc failure during logging\n"); \ @@ -110,6 +110,12 @@ void trace(const char *fmt, ...) char sbuf[1024]; int ret, dummy; + if (tracesyslog) { + va_start(arglist, fmt); + vsyslog(LOG_DEBUG, fmt, arglist); + va_end(arglist); + } + if (tracefd < 0) return; @@ -1987,10 +1993,9 @@ int main(int argc, char *argv[]) mkdir(xs_daemon_rundir(), 0755); mkdir(xs_daemon_rootdir(), 0755); - if (dofork) { - openlog("xenstored", 0, LOG_DAEMON); + openlog("xenstored", 0, LOG_DAEMON); + if (dofork) daemonize(); - } if (pidfile) write_pidfile(pidfile);