aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/logger
diff options
context:
space:
mode:
authorEdwin Groothuis <edwin@FreeBSD.org>2011-04-08 12:33:07 +0000
committerEdwin Groothuis <edwin@FreeBSD.org>2011-04-08 12:33:07 +0000
commit81280940454754571e8e75da2bc43d7e3397e8b1 (patch)
tree86b3dc031e96de4f6d8ee73d54fc1aa1d53886cb /usr.bin/logger
parent8b2aa22d8fe82a6fa1d3b7bc572e5e2361c67ea3 (diff)
downloadsrc-81280940454754571e8e75da2bc43d7e3397e8b1.tar.gz
src-81280940454754571e8e75da2bc43d7e3397e8b1.zip
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
Notes
Notes: svn path=/head/; revision=220448
Diffstat (limited to 'usr.bin/logger')
-rw-r--r--usr.bin/logger/logger.13
-rw-r--r--usr.bin/logger/logger.c21
2 files changed, 15 insertions, 9 deletions
diff --git a/usr.bin/logger/logger.1 b/usr.bin/logger/logger.1
index fd7f72aa94ec..ed893f394e33 100644
--- a/usr.bin/logger/logger.1
+++ b/usr.bin/logger/logger.1
@@ -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
diff --git a/usr.bin/logger/logger.c b/usr.bin/logger/logger.c
index bab54ce0e908..68828ed4fc94 100644
--- a/usr.bin/logger/logger.c
+++ b/usr.bin/logger/logger.c
@@ -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, const char *svcname, const char *buf)
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;