From patchwork Wed Aug 8 23:04:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 955273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41m6RV5fJWz9s3Z for ; Thu, 9 Aug 2018 09:05:10 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1D0E9CEF; Wed, 8 Aug 2018 23:05:07 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id A466ECC4 for ; Wed, 8 Aug 2018 23:05:05 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 4F31D174 for ; Wed, 8 Aug 2018 23:05:04 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 7949220002; Wed, 8 Aug 2018 23:05:00 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Wed, 8 Aug 2018 16:04:56 -0700 Message-Id: <20180808230456.2491-1-blp@ovn.org> X-Mailer: git-send-email 2.16.1 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ilya Maximets , Ben Pfaff Subject: [ovs-dev] [PATCH] tests: Don't log to syslog during tests. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Until now, "make check" generated a huge amount of output to syslog. This commit suppresses it. CC: Ilya Maximets Signed-off-by: Ben Pfaff Acked-by: Ilya Maximets --- NEWS | 2 ++ lib/automake.mk | 2 ++ lib/syslog-null.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/syslog-null.h | 22 ++++++++++++++++++++ lib/vlog.c | 12 +++++++++-- lib/vlog.man | 7 ++++++- lib/vlog.xml | 11 +++++++++- tests/atlocal.in | 4 ++++ 8 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 lib/syslog-null.c create mode 100644 lib/syslog-null.h diff --git a/NEWS b/NEWS index 7875f6673e34..ae21340e9046 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,7 @@ Post-v2.10.0 --------------------- + - The environment variable OVS_SYSLOG_METHOD, if set, is now used + as the default syslog method. v2.10.0 - xx xxx xxxx diff --git a/lib/automake.mk b/lib/automake.mk index fb43aa1413b2..63e9d72ac18a 100644 --- a/lib/automake.mk +++ b/lib/automake.mk @@ -280,6 +280,8 @@ lib_libopenvswitch_la_SOURCES = \ lib/syslog-direct.h \ lib/syslog-libc.c \ lib/syslog-libc.h \ + lib/syslog-null.c \ + lib/syslog-null.h \ lib/syslog-provider.h \ lib/table.c \ lib/table.h \ diff --git a/lib/syslog-null.c b/lib/syslog-null.c new file mode 100644 index 000000000000..9dbd13911c21 --- /dev/null +++ b/lib/syslog-null.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2015, 2016 Nicira, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "syslog-null.h" + +#include + +#include "compiler.h" +#include "syslog-provider.h" +#include "util.h" + +static void syslog_null_open(struct syslogger *this, int facility); +static void syslog_null_log(struct syslogger *this, int pri, const char *msg); + +static struct syslog_class syslog_null_class = { + syslog_null_open, + syslog_null_log, +}; + +struct syslog_null { + struct syslogger parent; +}; + +/* This function creates object that delegate all logging to null's + * syslog implementation. */ +struct syslogger * +syslog_null_create(void) +{ + struct syslog_null *this = xmalloc(sizeof *this); + + this->parent.class = &syslog_null_class; + this->parent.prefix = ""; + + return &this->parent; +} + +static void +syslog_null_open(struct syslogger *this OVS_UNUSED, int facility OVS_UNUSED) +{ + /* Nothing to do. */ +} + +static void +syslog_null_log(struct syslogger *this OVS_UNUSED, int pri OVS_UNUSED, + const char *msg OVS_UNUSED) +{ + /* Nothing to do. */ +} diff --git a/lib/syslog-null.h b/lib/syslog-null.h new file mode 100644 index 000000000000..0f7731dc4dcc --- /dev/null +++ b/lib/syslog-null.h @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2015 Nicira, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SYSLOG_NULL_H +#define SYSLOG_NULL_H 1 + +struct syslogger *syslog_null_create(void); + +#endif /* syslog-null.h */ diff --git a/lib/vlog.c b/lib/vlog.c index bf5fd88ba9e8..01cfdc5d3d2d 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -39,6 +39,7 @@ #include "svec.h" #include "syslog-direct.h" #include "syslog-libc.h" +#include "syslog-null.h" #include "syslog-provider.h" #include "timeval.h" #include "unixctl.h" @@ -584,7 +585,9 @@ vlog_set_syslog_method(const char *method) return; } - if (!strcmp(method, "libc")) { + if (!strcmp(method, "null")) { + syslogger = syslog_null_create(); + } else if (!strcmp(method, "libc")) { syslogger = syslog_libc_create(); } else if (!strncmp(method, "udp:", 4) || !strncmp(method, "unix:", 5)) { syslogger = syslog_direct_create(method); @@ -778,7 +781,12 @@ vlog_init(void) * log anything before calling ovsthread_once_done() will deadlock. */ atomic_read_explicit(&log_facility, &facility, memory_order_relaxed); if (!syslogger) { - syslogger = syslog_libc_create(); + char *env = getenv("OVS_SYSLOG_METHOD"); + if (env && env[0]) { + vlog_set_syslog_method(env); + } else { + syslogger = syslog_libc_create(); + } } syslogger->class->openlog(syslogger, facility ? facility : LOG_DAEMON); ovsthread_once_done(&once); diff --git a/lib/vlog.man b/lib/vlog.man index 674528d79aae..bad80e3d2771 100644 --- a/lib/vlog.man +++ b/lib/vlog.man @@ -83,7 +83,7 @@ Specify \fImethod\fR how syslog messages should be sent to syslog daemon. Following forms are supported: .RS .IP \(bu -\fBlibc\fR, use libc \fBsyslog()\fR function. This is the default behavior. +\fBlibc\fR, use libc \fBsyslog()\fR function. Downside of using this options is that libc adds fixed prefix to every message before it is actually sent to the syslog daemon over \fB/dev/log\fR UNIX domain socket. @@ -103,4 +103,9 @@ to listen on the specified UDP port, accidental iptables rules could be interfering with local syslog traffic and there are some security considerations that apply to UDP sockets, but do not apply to UNIX domain sockets. +.IP \(bu +\fBnull\fR, discards all messages logged to syslog. .RE +.IP +The default is taken from the \fBOVS_SYSLOG_METHOD\fR environment +variable; if it is unset, the default is \fBlibc\fR. diff --git a/lib/vlog.xml b/lib/vlog.xml index 70f88b3a6652..c3afc0492314 100644 --- a/lib/vlog.xml +++ b/lib/vlog.xml @@ -114,7 +114,7 @@
  • libc, to use the libc syslog() function. - This is the default behavior. Downside of using this options is that + Downside of using this options is that libc adds fixed prefix to every message before it is actually sent to the syslog daemon over /dev/log UNIX domain socket.
  • @@ -139,6 +139,15 @@ local syslog traffic and there are some security considerations that apply to UDP sockets, but do not apply to UNIX domain sockets. + +
  • + null, to discard all messages logged to syslog. +
+ +

+ The default is taken from the OVS_SYSLOG_METHOD environment + variable; if it is unset, the default is libc. +

diff --git a/tests/atlocal.in b/tests/atlocal.in index 0f4a6ca33758..a86de8bc1b90 100644 --- a/tests/atlocal.in +++ b/tests/atlocal.in @@ -212,3 +212,7 @@ unset NO_PROXY # Avoid OVN environment variables leaking in from external environment. unset OVN_NB_DB unset OVN_SB_DB + +# Prevent logging to syslog during tests. +OVS_SYSLOG_METHOD=null +export OVS_SYSLOG_METHOD