Add the ability to log to an arbitrary udp port as well as the

standard syslog port. This allows syslog to easily export lines of interest to
an external logging system.
This commit is contained in:
Julian Elischer 2006-04-17 20:12:35 +00:00
parent 6a4d12ad81
commit be389c75f0
2 changed files with 43 additions and 6 deletions

View File

@ -337,6 +337,9 @@ sign).
Selected messages are forwarded to the
.Xr syslogd 8
program on the named host.
If a port number is added after a colon
.Pq ':'
then that port will be used as the destination port rather than the usual syslog port.
.It
A comma separated list of users.
Selected messages are written to those users

View File

@ -1154,12 +1154,19 @@ fprintlog(struct filed *f, int flags, const char *msg)
f->f_time = now;
switch (f->f_type) {
int port;
case F_UNUSED:
dprintf("\n");
break;
case F_FORW:
dprintf(" %s\n", f->f_un.f_forw.f_hname);
port = (int)ntohs(((struct sockaddr_in *)
(f->f_un.f_forw.f_addr->ai_addr))->sin_port);
if (port != 514) {
dprintf(" %s:%d\n", f->f_un.f_forw.f_hname, port);
} else {
dprintf(" %s\n", f->f_un.f_forw.f_hname);
}
/* check for local vs remote messages */
if (strcasecmp(f->f_prevhost, LocalHostName))
l = snprintf(line, sizeof line - 1,
@ -1658,6 +1665,7 @@ init(int signo)
Initialized = 1;
if (Debug) {
int port;
for (f = Files; f; f = f->f_next) {
for (i = 0; i <= LOG_NFACILITIES; i++)
if (f->f_pmask[i] == INTERNAL_NOPRI)
@ -1676,7 +1684,14 @@ init(int signo)
break;
case F_FORW:
printf("%s", f->f_un.f_forw.f_hname);
port = (int)ntohs(((struct sockaddr_in *)
(f->f_un.f_forw.f_addr->ai_addr))->sin_port);
if (port != 514) {
printf("%s:%d",
f->f_un.f_forw.f_hname, port);
} else {
printf("%s", f->f_un.f_forw.f_hname);
}
break;
case F_PIPE:
@ -1881,13 +1896,32 @@ cfline(const char *line, struct filed *f, const char *prog, const char *host)
switch (*p) {
case '@':
(void)strlcpy(f->f_un.f_forw.f_hname, ++p,
sizeof(f->f_un.f_forw.f_hname));
{
char *tp;
/*
* scan forward to see if there is a port defined.
* so we can't use strlcpy..
*/
i = sizeof(f->f_un.f_forw.f_hname);
tp = f->f_un.f_forw.f_hname;
p++;
while (*p && (*p != ':') && (i-- > 0)) {
*tp++ = *p++;
}
*tp = '\0';
}
/* See if we copied a domain and have a port */
if (*p == ':')
p++;
else
p = NULL;
memset(&hints, 0, sizeof(hints));
hints.ai_family = family;
hints.ai_socktype = SOCK_DGRAM;
error = getaddrinfo(f->f_un.f_forw.f_hname, "syslog", &hints,
&res);
error = getaddrinfo(f->f_un.f_forw.f_hname,
p ? p: "syslog", &hints, &res);
if (error) {
logerror(gai_strerror(error));
break;