aboutsummaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorDavid E. O'Brien <obrien@FreeBSD.org>2007-12-11 06:10:10 +0000
committerDavid E. O'Brien <obrien@FreeBSD.org>2007-12-11 06:10:10 +0000
commite7ec0d579b5804c7ccf97a40ec7dd63e02970089 (patch)
treea7dbd95bd5e9b59286c8f6bfeba014189b4c80e0 /usr.sbin
parentc5ace62e4e60d58065e34e9a39af9450741eea2a (diff)
downloadsrc-e7ec0d579b5804c7ccf97a40ec7dd63e02970089.tar.gz
src-e7ec0d579b5804c7ccf97a40ec7dd63e02970089.zip
+ Open ctty in non-blocking mode to avoid hangs during open and close(waiting
for the port to drain). + Handle "*" as a priority properly. + Test what is free'ed. + Dynamically determine length vs. hardcoding it. + Free the previous message buffer (f_prevline) only after logging all the messages and just before the process exit. Also check f_prevline for NULL before using it. + The time displayed is not synchornized with the other log destinations. + Fix a comment. Obtained from: Juniper Networks
Notes
Notes: svn path=/head/; revision=174533
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/syslogd/syslogd.c29
1 files changed, 20 insertions, 9 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 104021f039b2..e06afdec177f 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -955,7 +955,11 @@ logmsg(int pri, const char *msg, const char *from, int flags)
/* log the message to the particular outputs */
if (!Initialized) {
f = &consfile;
- f->f_file = open(ctty, O_WRONLY, 0);
+ /*
+ * Open in non-blocking mode to avoid hangs during open
+ * and close(waiting for the port to drain).
+ */
+ f->f_file = open(ctty, O_WRONLY | O_NONBLOCK, 0);
if (f->f_file >= 0) {
(void)strlcpy(f->f_lasttime, timestamp,
@@ -996,7 +1000,7 @@ logmsg(int pri, const char *msg, const char *from, int flags)
*/
if (no_compress - (f->f_type != F_PIPE) < 1 &&
(flags & MARK) == 0 && msglen == f->f_prevlen &&
- !strcmp(msg, f->f_prevline) &&
+ f->f_prevline && !strcmp(msg, f->f_prevline) &&
!strcasecmp(from, f->f_prevhost)) {
(void)strlcpy(f->f_lasttime, timestamp,
sizeof(f->f_lasttime));
@@ -1066,9 +1070,14 @@ fprintlog(struct filed *f, int flags, const char *msg)
v = iov;
if (f->f_type == F_WALL) {
v->iov_base = greetings;
+ /* The time displayed is not synchornized with the other log
+ * destinations (like messages). Following fragment was using
+ * ctime(&now), which was updating the time every 30 sec.
+ * With f_lasttime, time is synchronized correctly.
+ */
v->iov_len = snprintf(greetings, sizeof greetings,
"\r\n\7Message from syslogd@%s at %.24s ...\r\n",
- f->f_prevhost, ctime(&now));
+ f->f_prevhost, f->f_lasttime);
if (v->iov_len > 0)
v++;
v->iov_base = nul;
@@ -1076,7 +1085,7 @@ fprintlog(struct filed *f, int flags, const char *msg)
v++;
} else {
v->iov_base = f->f_lasttime;
- v->iov_len = 15;
+ v->iov_len = strlen(f->f_lasttime);
v++;
v->iov_base = space;
v->iov_len = 1;
@@ -1144,9 +1153,11 @@ fprintlog(struct filed *f, int flags, const char *msg)
v->iov_base = repbuf;
v->iov_len = snprintf(repbuf, sizeof repbuf,
"last message repeated %d times", f->f_prevcount);
- } else {
+ } else if (f->f_prevline) {
v->iov_base = f->f_prevline;
v->iov_len = f->f_prevlen;
+ } else {
+ return;
}
v++;
@@ -1236,8 +1247,8 @@ fprintlog(struct filed *f, int flags, const char *msg)
if (writev(f->f_file, iov, 7) < 0) {
/*
* If writev(2) fails for potentially transient errors
- * like the * filesystem being full, ignore it.
- * Otherwise remove * this logfile from the list.
+ * like the filesystem being full, ignore it.
+ * Otherwise remove this logfile from the list.
*/
if (errno != ENOSPC) {
int e = errno;
@@ -1304,7 +1315,7 @@ fprintlog(struct filed *f, int flags, const char *msg)
break;
}
f->f_prevcount = 0;
- if (msg)
+ if (wmsg)
free(wmsg);
}
@@ -1831,7 +1842,7 @@ cfline(const char *line, struct filed *f, const char *prog, const char *host)
/* decode priority name */
if (*buf == '*') {
- pri = LOG_PRIMASK + 1;
+ pri = LOG_PRIMASK;
pri_cmp = PRI_LT | PRI_EQ | PRI_GT;
} else {
/* Ignore trailing spaces. */