From owner-freebsd-bugs@FreeBSD.ORG Wed Jul 2 07:50:15 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D0DF237B405 for ; Wed, 2 Jul 2003 07:50:10 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id D823744015 for ; Wed, 2 Jul 2003 07:50:08 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h62Eo8Up051605 for ; Wed, 2 Jul 2003 07:50:08 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h62Eo83c051604; Wed, 2 Jul 2003 07:50:08 -0700 (PDT) Resent-Date: Wed, 2 Jul 2003 07:50:08 -0700 (PDT) Resent-Message-Id: <200307021450.h62Eo83c051604@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Oliver Fromme Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id DD38A37B401 for ; Wed, 2 Jul 2003 07:46:36 -0700 (PDT) Received: from lurza.secnetix.de (lurza.secnetix.de [212.66.1.130]) by mx1.FreeBSD.org (Postfix) with ESMTP id 00E5A43FAF for ; Wed, 2 Jul 2003 07:46:36 -0700 (PDT) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (cncvkb@localhost [127.0.0.1]) by lurza.secnetix.de (8.12.8p1/8.12.8) with ESMTP id h62EkWB5061035; Wed, 2 Jul 2003 16:46:32 +0200 (CEST) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.12.8p1/8.12.8/Submit) id h62EkWua061034; Wed, 2 Jul 2003 16:46:32 +0200 (CEST) Message-Id: <200307021446.h62EkWua061034@lurza.secnetix.de> Date: Wed, 2 Jul 2003 16:46:32 +0200 (CEST) From: Oliver Fromme To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 cc: Oliver Fromme Subject: bin/54026: [patch] Add support for non-standard ports to /usr/bin/logger X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Oliver Fromme List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Jul 2003 14:50:16 -0000 >Number: 54026 >Category: bin >Synopsis: [patch] Add support for non-standard ports to /usr/bin/logger >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Wed Jul 02 07:50:06 PDT 2003 >Closed-Date: >Last-Modified: >Originator: Oliver Fromme >Release: FreeBSD 5-current and 4-stable >Organization: secnetix GmbH & Co. KG, http://www.secnetix.de/ >Environment: The patch applies FreeBSD 5-current (HEAD), but it should also apply to 4-stable. >Description: This patch adds a new option -P to /usr/bin/logger which can be used to override the default port ("syslog" / 514). (Background: I had to patch logger because I needed that feature on a server farm, in order to send log messages from various places to a collection of jailed syslog-ng daemons on a log server, which -- of course -- listen on several non-standard ports.) >How-To-Repeat: n/a >Fix: --- src/usr.bin/logger/logger.c.orig Wed Jul 2 15:24:26 2003 +++ src/usr.bin/logger/logger.c Wed Jul 2 15:55:21 2003 @@ -62,7 +62,7 @@ int decode(char *, CODE *); int pencode(char *); -static void logmessage(int, char *, char *); +static void logmessage(int, char *, char *, char *); static void usage(void); struct socks { @@ -88,14 +88,15 @@ main(int argc, char *argv[]) { int ch, logflags, pri; - char *tag, *host, buf[1024]; + char *tag, *host, *svcname, buf[1024]; tag = NULL; host = NULL; + svcname = "syslog"; pri = LOG_USER | LOG_NOTICE; logflags = 0; unsetenv("TZ"); - while ((ch = getopt(argc, argv, "46Af:h:ip:st:")) != -1) + while ((ch = getopt(argc, argv, "46Af:h:iP:p:st:")) != -1) switch((char)ch) { case '4': family = PF_INET; @@ -118,6 +119,9 @@ case 'i': /* log process id also */ logflags |= LOG_PID; break; + case 'P': /* service name or port number */ + svcname = optarg; + break; case 'p': /* priority */ pri = pencode(optarg); break; @@ -146,11 +150,11 @@ for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) { len = strlen(*argv); if (p + len > endp && p > buf) { - logmessage(pri, host, buf); + logmessage(pri, host, svcname, buf); p = buf; } if (len > sizeof(buf) - 1) - logmessage(pri, host, *argv++); + logmessage(pri, host, svcname, *argv++); else { if (p != buf) *p++ = ' '; @@ -159,10 +163,10 @@ } } if (p != buf) - logmessage(pri, host, buf); + logmessage(pri, host, svcname, buf); } else while (fgets(buf, sizeof(buf), stdin) != NULL) - logmessage(pri, host, buf); + logmessage(pri, host, svcname, buf); exit(0); } @@ -170,7 +174,7 @@ * Send the message to syslog, either on the local host, or on a remote host */ void -logmessage(int pri, char *host, char *buf) +logmessage(int pri, char *host, char *svcname, char *buf) { static struct socks *socks; static int nsock = 0; @@ -188,9 +192,9 @@ memset(&hints, 0, sizeof(hints)); hints.ai_family = family; hints.ai_socktype = SOCK_DGRAM; - error = getaddrinfo(host, "syslog", &hints, &res); + error = getaddrinfo(host, svcname, &hints, &res); if (error == EAI_SERVICE) { - warnx ("syslog/udp: unknown service"); /* not fatal */ + warnx ("%s/udp: unknown service", svcname); /* not fatal */ error = getaddrinfo(host, "514", &hints, &res); } if (error) @@ -280,7 +284,7 @@ usage(void) { (void)fprintf(stderr, "usage: %s\n", - "logger [-46Ais] [-f file] [-h host] [-p pri] [-t tag] [message ...]" + "logger [-46Ais] [-f file] [-h host] [-P port] [-p pri] [-t tag] [message ...]" ); exit(1); } --- src/usr.bin/logger/logger.1.orig Wed Jul 2 15:32:15 2003 +++ src/usr.bin/logger/logger.1 Wed Jul 2 16:12:29 2003 @@ -43,6 +43,7 @@ .Op Fl 46Ais .Op Fl f Ar file .Op Fl h Ar host +.Op Fl P Ar port .Op Fl p Ar pri .Op Fl t Ar tag .Op Ar message ... @@ -82,6 +83,16 @@ Send the message to the remote system .Ar host instead of logging it locally. +.It Fl P Ar port +Send the message to the specified +.Ar port +number on a remote system, +which can be specified as a service name +or as a decimal number. +The default is ``syslog''. +If an unknown service name is used, +.Nm +prints a warning and falls back to port 514. .It Fl p Ar pri Enter the message with the specified priority. The priority may be specified numerically or as a ``facility.level'' >Release-Note: >Audit-Trail: >Unformatted: