Date: 27 Jan 2011 15:57:29 +1100 From: Callum Gibson <callumgibson@optusnet.com.au> To: FreeBSD-gnats-submit@FreeBSD.org Subject: bin/154324: [patch] logger ignores tag when logging to remote host Message-ID: <20110127045729.76635.qmail@omma.gibson.athome> Resent-Message-ID: <201101270510.p0R5A7vx092067@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 154324 >Category: bin >Synopsis: [patch] logger ignores tag when logging to remote host >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Thu Jan 27 05:10:06 UTC 2011 >Closed-Date: >Last-Modified: >Originator: Callum Gibson >Release: FreeBSD 8.1-STABLE i386 >Organization: >Environment: System: FreeBSD omma 8.1-STABLE FreeBSD 8.1-STABLE #13: Wed Sep 22 07:42:16 EST 2010 root@omma:/usr/local/obj/usr/src/sys/OMMA i386 >Description: If you log to a remote host with logger(1) using the -h flag, it will ignore the tag supplied with -t. The default tag prefix of login name also isn't honoured. Additionally, openlog is always called even though this is only relevant when logging to the local machine with the syslog(3) interface. The supplied patch addresses both of these issues. I've also updated the manpage to note the default tag. Patch is versus RELENG_8 but applies cleanly against HEAD as at r216370. >How-To-Repeat: Log to a remote host and note the absence of the tag supplied with -t in the resulting log entry. eg. logger -h loghost -t HELLO some message >Fix: --- usr.bin/logger/logger.c.orig 2009-08-03 18:13:06.000000000 +1000 +++ usr.bin/logger/logger.c 2011-01-27 14:55:30.000000000 +1100 @@ -63,7 +63,8 @@ int decode(char *, CODE *); int pencode(char *); -static void logmessage(int, const char *, const char *, const char *); +static void logmessage(int, const char *, const char *, const char *, + const char *); static void usage(void); struct socks { @@ -140,8 +141,11 @@ argc -= optind; argv += optind; + if (tag == NULL) + tag = getlogin(); /* setup for logging */ - openlog(tag ? tag : getlogin(), logflags, 0); + if (host == NULL) + openlog(tag, logflags, 0); (void) fclose(stdout); /* log input line if appropriate */ @@ -152,11 +156,11 @@ for (p = buf, endp = buf + sizeof(buf) - 2; *argv;) { len = strlen(*argv); if (p + len > endp && p > buf) { - logmessage(pri, host, svcname, buf); + logmessage(pri, tag, host, svcname, buf); p = buf; } if (len > sizeof(buf) - 1) - logmessage(pri, host, svcname, *argv++); + logmessage(pri, tag, host, svcname, *argv++); else { if (p != buf) *p++ = ' '; @@ -165,10 +169,10 @@ } } if (p != buf) - logmessage(pri, host, svcname, buf); + logmessage(pri, tag, host, svcname, buf); } else while (fgets(buf, sizeof(buf), stdin) != NULL) - logmessage(pri, host, svcname, buf); + logmessage(pri, tag, host, svcname, buf); exit(0); } @@ -176,7 +180,8 @@ * Send the message to syslog, either on the local host, or on a remote host */ void -logmessage(int pri, const char *host, const char *svcname, const char *buf) +logmessage(int pri, const char *tag, const char *host, const char *svcname, + const char *buf) { static struct socks *socks; static int nsock = 0; @@ -220,7 +225,7 @@ errx(1, "socket"); } - if ((len = asprintf(&line, "<%d>%s", pri, buf)) == -1) + if ((len = asprintf(&line, "<%d>%s: %s", pri, tag, buf)) == -1) errx(1, "asprintf"); lsent = -1; --- usr.bin/logger/logger.1.orig 2009-08-03 18:13:06.000000000 +1000 +++ usr.bin/logger/logger.1 2011-01-27 15:09:13.000000000 +1100 @@ -106,7 +106,8 @@ The default is ``user.notice.'' .It Fl t Ar tag Mark every line in the log with the specified -.Ar tag . +.Ar tag +rather than the default of current login name. .It Ar message Write the message to log; if not specified, and the .Fl f >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110127045729.76635.qmail>