diff options
| author | Bruce M Simpson <bms@FreeBSD.org> | 2006-08-02 13:21:44 +0000 |
|---|---|---|
| committer | Bruce M Simpson <bms@FreeBSD.org> | 2006-08-02 13:21:44 +0000 |
| commit | 6b04b7f63eaf6cc7667499aa94233ff5df4016ae (patch) | |
| tree | 0791e0ece41cc45403d6ff8a4e262c718440b1e7 /usr.bin/logger/logger.c | |
| parent | d8f709386078afc65c470b4c4fe4d6506ac687fa (diff) | |
Notes
Diffstat (limited to 'usr.bin/logger/logger.c')
| -rw-r--r-- | usr.bin/logger/logger.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/usr.bin/logger/logger.c b/usr.bin/logger/logger.c index 45665068b1ab..b706f0d47092 100644 --- a/usr.bin/logger/logger.c +++ b/usr.bin/logger/logger.c @@ -63,7 +63,7 @@ __FBSDID("$FreeBSD$"); 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 { @@ -89,14 +89,15 @@ int 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; @@ -119,6 +120,9 @@ main(int argc, char *argv[]) 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; @@ -147,11 +151,11 @@ main(int argc, char *argv[]) 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++ = ' '; @@ -160,10 +164,10 @@ main(int argc, char *argv[]) } } 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); } @@ -171,7 +175,7 @@ main(int argc, char *argv[]) * 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; @@ -189,9 +193,9 @@ logmessage(int pri, char *host, char *buf) 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); error = getaddrinfo(host, "514", &hints, &res); } if (error) @@ -282,7 +286,8 @@ static void 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]\n" + " [message ...]" ); exit(1); } |
