From callumgibson@optusnet.com.au  Thu Jan 27 05:07:48 2011
Return-Path: <callumgibson@optusnet.com.au>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 8DB0B106564A
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Jan 2011 05:07:48 +0000 (UTC)
	(envelope-from callumgibson@optusnet.com.au)
Received: from fallbackmx09.syd.optusnet.com.au (fallbackmx09.syd.optusnet.com.au [211.29.132.242])
	by mx1.freebsd.org (Postfix) with ESMTP id 2AD448FC14
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Jan 2011 05:07:47 +0000 (UTC)
Received: from mail03.syd.optusnet.com.au (mail03.syd.optusnet.com.au [211.29.132.184])
	by fallbackmx09.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id p0R4vXWN003985
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Jan 2011 15:57:33 +1100
Received: from omma.gibson.athome (c122-106-15-156.rivrw1.nsw.optusnet.com.au [122.106.15.156])
	by mail03.syd.optusnet.com.au (8.13.1/8.13.1) with SMTP id p0R4vTda032567
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 27 Jan 2011 15:57:30 +1100
Received: (qmail 76636 invoked by uid 107); 27 Jan 2011 15:57:29 +1100
Message-Id: <20110127045729.76635.qmail@omma.gibson.athome>
Date: 27 Jan 2011 15:57:29 +1100
From: Callum Gibson <callumgibson@optusnet.com.au>
Reply-To: Callum Gibson <callumgibson@optusnet.com.au>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [patch] logger ignores tag when logging to remote host
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         154324
>Category:       bin
>Synopsis:       [patch] logger(1) ignores tag when logging to remote host
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 27 05:10:06 UTC 2011
>Closed-Date:    Sun Apr 17 21:57:14 UTC 2011
>Last-Modified:  Sun Apr 17 22:00:20 UTC 2011
>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:
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Fri Apr 8 12:04:54 UTC 2011 
Responsible-Changed-Why:  
Callum asked me to look at this one. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154324 
State-Changed-From-To: open->patched 
State-Changed-By: edwin 
State-Changed-When: Fri Apr 8 12:33:25 UTC 2011 
State-Changed-Why:  
Commited to head 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154324 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/154324: commit references a PR
Date: Fri,  8 Apr 2011 12:33:19 +0000 (UTC)

 Author: edwin
 Date: Fri Apr  8 12:33:07 2011
 New Revision: 220448
 URL: http://svn.freebsd.org/changeset/base/220448
 
 Log:
   When specifying the -t option (send tag in front of message), this tag
   should also be forwarded to the remote logging host, not only when the
   logging is done locally.
   
   PR:		bin/154324
   Submitted by:	Callum Gibson <callumgibson@optusnet.com.au>
   MFC after:	1 week
 
 Modified:
   head/usr.bin/logger/logger.1
   head/usr.bin/logger/logger.c
 
 Modified: head/usr.bin/logger/logger.1
 ==============================================================================
 --- head/usr.bin/logger/logger.1	Fri Apr  8 11:08:26 2011	(r220447)
 +++ head/usr.bin/logger/logger.1	Fri Apr  8 12:33:07 2011	(r220448)
 @@ -102,7 +102,8 @@ facility.
  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
 
 Modified: head/usr.bin/logger/logger.c
 ==============================================================================
 --- head/usr.bin/logger/logger.c	Fri Apr  8 11:08:26 2011	(r220447)
 +++ head/usr.bin/logger/logger.c	Fri Apr  8 12:33:07 2011	(r220448)
 @@ -59,7 +59,8 @@ __FBSDID("$FreeBSD$");
  
  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 {
 @@ -137,8 +138,11 @@ main(int argc, char *argv[])
  	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 */
 @@ -149,11 +153,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, 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++ = ' ';
 @@ -162,10 +166,10 @@ main(int argc, char *argv[])
  			}
  		}
  		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);
  }
  
 @@ -173,7 +177,8 @@ main(int argc, char *argv[])
   *  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;
 @@ -217,7 +222,7 @@ logmessage(int pri, const char *host, co
  			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;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: edwin 
State-Changed-When: Sun Apr 17 21:56:13 UTC 2011 
State-Changed-Why:  
MFC done 

http://www.freebsd.org/cgi/query-pr.cgi?pr=154324 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/154324: commit references a PR
Date: Sun, 17 Apr 2011 21:53:09 +0000 (UTC)

 Author: edwin
 Date: Sun Apr 17 21:52:57 2011
 New Revision: 220757
 URL: http://svn.freebsd.org/changeset/base/220757
 
 Log:
   MFC of r220448
   
   When specifying the -t option (send tag in front of message), this tag
   should also be forwarded to the remote logging host, not only when the
   logging is done locally.
   
   PR:             bin/154324
   Submitted by:   Callum Gibson <callumgibson@optusnet.com.au>
 
 Modified:
   stable/8/usr.bin/logger/logger.1
   stable/8/usr.bin/logger/logger.c
 Directory Properties:
   stable/8/usr.bin/logger/   (props changed)
 
 Modified: stable/8/usr.bin/logger/logger.1
 ==============================================================================
 --- stable/8/usr.bin/logger/logger.1	Sun Apr 17 21:11:55 2011	(r220756)
 +++ stable/8/usr.bin/logger/logger.1	Sun Apr 17 21:52:57 2011	(r220757)
 @@ -106,7 +106,8 @@ facility.
  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
 
 Modified: stable/8/usr.bin/logger/logger.c
 ==============================================================================
 --- stable/8/usr.bin/logger/logger.c	Sun Apr 17 21:11:55 2011	(r220756)
 +++ stable/8/usr.bin/logger/logger.c	Sun Apr 17 21:52:57 2011	(r220757)
 @@ -63,7 +63,8 @@ __FBSDID("$FreeBSD$");
  
  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 @@ main(int argc, char *argv[])
  	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 @@ 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, 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 @@ main(int argc, char *argv[])
  			}
  		}
  		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 @@ main(int argc, char *argv[])
   *  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 @@ logmessage(int pri, const char *host, co
  			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;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/154324: commit references a PR
Date: Sun, 17 Apr 2011 21:57:18 +0000 (UTC)

 Author: edwin
 Date: Sun Apr 17 21:57:08 2011
 New Revision: 220758
 URL: http://svn.freebsd.org/changeset/base/220758
 
 Log:
   MFC of r220448
   
   When specifying the -t option (send tag in front of message), this tag
   should also be forwarded to the remote logging host, not only when the
   logging is done locally.
   
   PR:             bin/154324
   Submitted by:   Callum Gibson <callumgibson@optusnet.com.au>
 
 Modified:
   stable/7/usr.bin/logger/logger.1
   stable/7/usr.bin/logger/logger.c
 Directory Properties:
   stable/7/usr.bin/logger/   (props changed)
 
 Modified: stable/7/usr.bin/logger/logger.1
 ==============================================================================
 --- stable/7/usr.bin/logger/logger.1	Sun Apr 17 21:52:57 2011	(r220757)
 +++ stable/7/usr.bin/logger/logger.1	Sun Apr 17 21:57:08 2011	(r220758)
 @@ -106,7 +106,8 @@ facility.
  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
 
 Modified: stable/7/usr.bin/logger/logger.c
 ==============================================================================
 --- stable/7/usr.bin/logger/logger.c	Sun Apr 17 21:52:57 2011	(r220757)
 +++ stable/7/usr.bin/logger/logger.c	Sun Apr 17 21:57:08 2011	(r220758)
 @@ -63,7 +63,8 @@ __FBSDID("$FreeBSD$");
  
  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 @@ main(int argc, char *argv[])
  	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 @@ 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, 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 @@ main(int argc, char *argv[])
  			}
  		}
  		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 @@ main(int argc, char *argv[])
   *  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 @@ logmessage(int pri, const char *host, co
  			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;
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
