FreeBSD Bugzilla – Attachment 9736 Details for
Bug 19821
logger(1) does not log messages to a remote host.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 4.23 KB, created by
nick
on 2000-07-10 14:10:01 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
nick
Created:
2000-07-10 14:10:01 UTC
Size:
4.23 KB
patch
obsolete
>--- logger.c.old Wed Jun 30 12:04:32 1999 >+++ logger.c Wed Jun 30 12:37:40 1999 >@@ -42,9 +42,15 @@ > static char sccsid[] = "@(#)logger.c 8.1 (Berkeley) 6/6/93"; > #endif > static const char rcsid[] = >- "$Id: logger.c,v 1.2.2.3 1997/09/15 08:32:18 jkh Exp $"; >+ "$Id: logger.c,v 1.2 1998/01/29 17:28:54 nick Exp $"; > #endif /* not lint */ > >+#include <sys/types.h> >+#include <sys/uio.h> >+#include <netinet/in.h> >+#include <sys/socket.h> >+#include <netdb.h> >+ > #include <ctype.h> > #include <err.h> > #include <stdio.h> >@@ -57,8 +63,11 @@ > > int decode __P((char *, CODE *)); > int pencode __P((char *)); >+void logmessage __P((int, char *, char *)); > static void usage __P((void)); > >+#define MAXBUF 1024 >+ > /* > * logger -- read and log utility > * >@@ -71,13 +80,13 @@ > char *argv[]; > { > int ch, logflags, pri; >- char *tag, buf[1024]; >+ char *tag, *host, buf[MAXBUF]; > >- tag = NULL; >+ host = tag = NULL; > pri = LOG_NOTICE; > logflags = 0; > unsetenv("TZ"); >- while ((ch = getopt(argc, argv, "f:ip:st:")) != -1) >+ while ((ch = getopt(argc, argv, "f:h:ip:st:")) != -1) > switch((char)ch) { > case 'f': /* file to log */ > if (freopen(optarg, "r", stdin) == NULL) >@@ -95,6 +104,9 @@ > case 't': /* tag */ > tag = optarg; > break; >+ case 'h': >+ host = optarg; /* hostname to deliver to */ >+ break; > case '?': > default: > usage(); >@@ -114,11 +126,11 @@ > for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) { > len = strlen(*argv); > if (p + len > endp && p > buf) { >- syslog(pri, "%s", buf); >+ logmessage(pri, host, buf); > p = buf; > } > if (len > sizeof(buf) - 1) >- syslog(pri, "%s", *argv++); >+ logmessage(pri, host, *argv++); > else { > if (p != buf) > *p++ = ' '; >@@ -127,14 +139,76 @@ > } > } > if (p != buf) >- syslog(pri, "%s", buf); >+ logmessage(pri, host, buf); > } else > while (fgets(buf, sizeof(buf), stdin) != NULL) >- syslog(pri, "%s", buf); >+ logmessage(pri, host, buf); > exit(0); > } > > /* >+ * Send the message to syslog, either on the local host, or on a remote host >+ */ >+void >+logmessage(int pri, char *host, char *buf) >+{ >+ static int sock = -1; >+ static struct sockaddr_in sin; >+ >+ struct msghdr msg; >+ struct iovec iov[1]; >+ ssize_t size; >+ struct in_addr in; >+ struct servent *sp; >+ struct hostent *hp = NULL; >+ char line[MAXBUF + sizeof("<nnnnnnnnnnn>")]; /* int is always < 11 chars */ >+ >+ if (host == NULL) { >+ syslog(pri, "%s", buf); >+ return; >+ } >+ >+ if (sock == -1) { /* set up socket stuff */ >+ if ((sp = getservbyname("syslog", "udp")) == NULL) >+ warnx ("syslog/udp: unknown service"); /* not fatal */ >+ >+ /* resolve hostname */ >+ if (!(inet_aton (host, &in)) && !(hp = gethostbyname(host))) { >+ errx (1, "unknown host: %s", host); >+ } >+ if (hp != NULL) >+ memcpy ((void *)&in.s_addr, hp->h_addr, >+ sizeof(struct in_addr)); >+ >+ /* set up struct sockaddr_in */ >+ sin.sin_family = AF_INET; >+ sin.sin_port = (sp == NULL ? 514 : sp->s_port); >+ memcpy ((void *)&sin.sin_addr, (void *)&in.s_addr, >+ sizeof(struct in_addr)); >+ >+ sock = socket (PF_INET, SOCK_DGRAM, 0); >+ if (sock < 0) >+ errx(1, "socket"); >+ } >+ >+ msg.msg_name = (void *)&sin; >+ msg.msg_namelen = sizeof sin; >+ msg.msg_iov = iov; >+ msg.msg_iovlen = 0; >+ msg.msg_control = 0; >+ msg.msg_controllen = 0; >+ msg.msg_flags = 0; >+ >+ snprintf (line, sizeof (line) - 1, "<%d>%s", pri, buf); >+ >+ iov[msg.msg_iovlen].iov_base = line; >+ iov[msg.msg_iovlen++].iov_len = strlen(line); >+ >+ if (sendmsg (sock, &msg, 0) < strlen(line)) >+ warnx ("sendmsg"); >+} >+ >+/* > * Decode a symbolic name to a numeric value > */ > int >@@ -183,6 +257,6 @@ > usage() > { > (void)fprintf(stderr, >- "usage: logger [-is] [-f file] [-p pri] [-t tag] [message ...]\n"); >+ "usage: logger [-is] [-f file] [-p pri] [-t tag] [-h host] [message ...]\n"); > exit(1); > } >--- logger.1.old Wed Jun 30 12:38:27 1999 >+++ logger.1 Wed Jun 30 12:42:48 1999 >@@ -43,6 +43,7 @@ > .Op Fl f Ar file > .Op Fl p Ar pri > .Op Fl t Ar tag >+.Op Fl h Ar host > .Op Ar message ... > .Sh DESCRIPTION > .Nm Logger >@@ -73,6 +74,10 @@ > .It Fl t Ar tag > Mark every line in the log with the specified > .Ar tag . >+.It Fl h Ar host >+Send the message to the remote system >+.Ar host >+instead of logging it locally. > .It Ar message > Write the message to log; if not specified, and the > .Fl f
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 19821
: 9736