bin/54026: [patch] Add support for non-standard ports to
/usr/bin/logger
Oliver Fromme
olli at secnetix.de
Wed Jul 2 07:50:16 PDT 2003
>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 <olli at secnetix.de>
>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:
More information about the freebsd-bugs
mailing list