From patchwork Wed Jun 21 14:13:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Jackson X-Patchwork-Id: 9801953 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2C29F60329 for ; Wed, 21 Jun 2017 14:16:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CC8A285C4 for ; Wed, 21 Jun 2017 14:16:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11AA3285CC; Wed, 21 Jun 2017 14:16:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E192285C4 for ; Wed, 21 Jun 2017 14:16:47 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNgOv-00052S-Uz; Wed, 21 Jun 2017 14:14:33 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dNgOu-00050j-Ky for xen-devel@lists.xenproject.org; Wed, 21 Jun 2017 14:14:32 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 12/50-03587-84F7A495; Wed, 21 Jun 2017 14:14:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuphkeJIrShJLcpLzFFi42JxWrohUte93iv S4O9qRYvvWyYzOTB6HP5whSWAMYo1My8pvyKBNePdxQtsBf8lKo72vWBpYFwh0sXIySEh4C/x Z/JWJhCbTUBXomnLX7YuRg4OEQEVidt7DUDCzALaEnvXzWUGsYUFHCSuPj3BAmKzCKhKLLq1g x3E5hXwlPh/8TgLxEg5ifPHfzKDjOEU8JJY/MgfxBQCKpl/yg/CVJOYuz4eolFQ4uTMJywQiy QkDr54wTyBkXcWktQsJKkFjEyrGNWLU4vKUot0LfSSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxK TivWS83M3MQJDhgEIdjDOvux/iFGSg0lJlLfc2ytSiC8pP6UyI7E4I76oNCe1+BCjDAeHkgTv oTqgnGBRanpqRVpmDjB4YdISHDxKIrxrSoDSvMUFibnFmekQqVOMuhwLejZ8YRJiycvPS5US5 3UFmSEAUpRRmgc3AhZJlxhlpYR5GYGOEuIpSC3KzSxBlX/FKM7BqCTMe7AGaApPZl4J3KZXQE cwAR3x4ogHyBEliQgpqQbGWJUTSzRPBd1du2npm4XOafs2pc8+a7H7A8OVMtZXSw/cXaMokFE vLb9wekdAvebuS8dvNUjOqmmVvzkjRLJ0e4RyjylnUMySa3al150lqjgCSpbYL418NYs5cf6E pmVPbU/WGj7+zBQeFOWzcKm/Xc/85s6sx1+S9t+Os5YyOPTKKu2Yx/ZJSizFGYmGWsxFxYkAC Y5RNZ8CAAA= X-Env-Sender: prvs=33896ecda=Ian.Jackson@citrix.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1498054469!104192258!1 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 35502 invoked from network); 21 Jun 2017 14:14:31 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-27.messagelabs.com with RC4-SHA encrypted SMTP; 21 Jun 2017 14:14:31 -0000 X-IronPort-AV: E=Sophos;i="5.39,369,1493683200"; d="scan'208";a="428818032" From: Ian Jackson To: Date: Wed, 21 Jun 2017 15:13:55 +0100 Message-ID: <1498054447-11281-4-git-send-email-ian.jackson@eu.citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1498054447-11281-1-git-send-email-ian.jackson@eu.citrix.com> References: <1498054447-11281-1-git-send-email-ian.jackson@eu.citrix.com> MIME-Version: 1.0 Cc: Ian Jackson Subject: [Xen-devel] [OSSTEST PATCH 03/15] ts-syslog-server: New test script X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This is a "complete implementation of the UDP syslog protocol". In fact, the UDP syslog protocol is trivial: the UDP packets contain newline-terminated unix text strings. We can simply chomp them and log them (along with the sending address and port). This script is designed to be run with the new "|" spawn-ts mode: it will keep running until it is reaped. Currently it is not part of any jobs. Signed-off-by: Ian Jackson --- ts-syslog-server | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 ts-syslog-server diff --git a/ts-syslog-server b/ts-syslog-server new file mode 100755 index 0000000..b17c531 --- /dev/null +++ b/ts-syslog-server @@ -0,0 +1,85 @@ +#!/usr/bin/perl -w +# This is part of "osstest", an automated testing framework for Xen. +# Copyright (C) 2009-2013 Citrix Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +use strict; + +unshift @INC, qw(.); +use Osstest; +use Osstest::TestSupport; + +use POSIX; +use Fcntl; +use Socket qw(PF_INET SOCK_DGRAM INADDR_ANY + pack_sockaddr_in unpack_sockaddr_in inet_aton inet_ntoa); + +tsreadconfig(); + +die if @ARGV && $ARGV[0] =~ m/^-/; + +logm("starting syslog server ..."); + +socket S, PF_INET, SOCK_DGRAM, 0 or die $!; + +my $sockname = pack_sockaddr_in(0, inet_aton(controller_ipaddr())); +bind S, $sockname or die $!; +$sockname = getsockname S or die $!; +my ($port,$myaddr) = unpack_sockaddr_in($sockname) or die $!; +$myaddr = inet_ntoa($myaddr); + +store_runvar('syslog_server',"$myaddr:$port"); + +my @fhs = qw(S STDIN); + +foreach my $fh (@fhs) { + my $fl = fcntl($fh, F_GETFL, 0) // die $!; + fcntl($fh, F_SETFL, $fl | O_NONBLOCK) // die $!; +} + +logm("syslog server running on $myaddr:$port"); + +for (;;) { + my $rfds = ''; + foreach my $fh (@fhs) { + vec($rfds, fileno($fh), 1) = 1; + } + my $efds = $rfds; + select($rfds, undef, $efds, undef); + if (vec($rfds, fileno(STDIN), 1)) { + my $d; + my $r = sysread STDIN, $d, 1; + if (defined $r) { + die "read something from stdin!" if $r>0; + last; + } else { + die $! unless $!==EAGAIN || $!==EWOULDBLOCK; + } + } + if (vec($rfds, fileno(S), 1)) { + my $d; + my $sender = recv S, $d, 1024, 0; + if (defined $sender) { + my ($sport,$saddr) = unpack_sockaddr_in($sender) or die $!; + $saddr = inet_ntoa($saddr) // die $!; + chomp $d; + logm("$saddr:$sport $d"); + } else { + die $! unless $!==EAGAIN || $!==EWOULDBLOCK; + } + } +} + +logm("stopping.");