Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 17 Apr 2011 21:52:57 +0000 (UTC)
From:      Edwin Groothuis <edwin@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r220757 - stable/8/usr.bin/logger
Message-ID:  <201104172152.p3HLqvFA050676@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201104172152.p3HLqvFA050676>