summaryrefslogtreecommitdiffstats
path: root/usr.sbin/syslogd
diff options
context:
space:
mode:
authorbluhm <bluhm@openbsd.org>2017-04-05 21:55:31 +0000
committerbluhm <bluhm@openbsd.org>2017-04-05 21:55:31 +0000
commit6545c74a765c2beb1d18f04f35cb2df8f9c5b444 (patch)
treec0e61149b820fb4f6a5c820ed5fddd6a65f5f722 /usr.sbin/syslogd
parentThe function logmsg() was used to generate local messages and to (diff)
downloadwireguard-openbsd-6545c74a765c2beb1d18f04f35cb2df8f9c5b444.tar.xz
wireguard-openbsd-6545c74a765c2beb1d18f04f35cb2df8f9c5b444.zip
As we did not have nice log functions before, ttymsg() had to return
the error string. Log the message when the error happens and make the function void. OK millert@
Diffstat (limited to 'usr.sbin/syslogd')
-rw-r--r--usr.sbin/syslogd/syslogd.c10
-rw-r--r--usr.sbin/syslogd/syslogd.h4
-rw-r--r--usr.sbin/syslogd/ttymsg.c56
3 files changed, 30 insertions, 40 deletions
diff --git a/usr.sbin/syslogd/syslogd.c b/usr.sbin/syslogd/syslogd.c
index 00bd99da3e3..6cedc3fe075 100644
--- a/usr.sbin/syslogd/syslogd.c
+++ b/usr.sbin/syslogd/syslogd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslogd.c,v 1.238 2017/04/05 21:30:04 bluhm Exp $ */
+/* $OpenBSD: syslogd.c,v 1.239 2017/04/05 21:55:31 bluhm Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
@@ -2068,7 +2068,7 @@ void
wallmsg(struct filed *f, struct iovec *iov)
{
struct utmp ut;
- char utline[sizeof(ut.ut_line) + 1], *p;
+ char utline[sizeof(ut.ut_line) + 1];
static int reenter; /* avoid calling ourselves */
FILE *uf;
int i;
@@ -2087,8 +2087,7 @@ wallmsg(struct filed *f, struct iovec *iov)
strncpy(utline, ut.ut_line, sizeof(utline) - 1);
utline[sizeof(utline) - 1] = '\0';
if (f->f_type == F_WALL) {
- if ((p = ttymsg(iov, 6, utline)) != NULL)
- log_warnx("%s", p);
+ ttymsg(iov, 6, utline);
continue;
}
/* should we send the message to this user? */
@@ -2097,8 +2096,7 @@ wallmsg(struct filed *f, struct iovec *iov)
break;
if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
UT_NAMESIZE)) {
- if ((p = ttymsg(iov, 6, utline)) != NULL)
- log_warnx("%s", p);
+ ttymsg(iov, 6, utline);
break;
}
}
diff --git a/usr.sbin/syslogd/syslogd.h b/usr.sbin/syslogd/syslogd.h
index f85b7f938ea..358c66c5043 100644
--- a/usr.sbin/syslogd/syslogd.h
+++ b/usr.sbin/syslogd/syslogd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: syslogd.h,v 1.28 2017/04/05 11:31:45 bluhm Exp $ */
+/* $OpenBSD: syslogd.h,v 1.29 2017/04/05 21:55:31 bluhm Exp $ */
/*
* Copyright (c) 2003 Anil Madhavapeddy <anil@recoil.org>
@@ -37,7 +37,7 @@ int priv_getnameinfo(struct sockaddr *, socklen_t, char *, size_t);
/* Terminal message */
#define TTYMSGTIME 1 /* timeout used by ttymsg */
#define TTYMAXDELAY 256 /* max events in ttymsg */
-char *ttymsg(struct iovec *, int, char *);
+void ttymsg(struct iovec *, int, char *);
/* File descriptor send/recv */
void send_fd(int, int);
diff --git a/usr.sbin/syslogd/ttymsg.c b/usr.sbin/syslogd/ttymsg.c
index 96fc9876afe..b8100173d35 100644
--- a/usr.sbin/syslogd/ttymsg.c
+++ b/usr.sbin/syslogd/ttymsg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ttymsg.c,v 1.14 2017/04/05 11:31:45 bluhm Exp $ */
+/* $OpenBSD: ttymsg.c,v 1.15 2017/04/05 21:55:31 bluhm Exp $ */
/* $NetBSD: ttymsg.c,v 1.3 1994/11/17 07:17:55 jtc Exp $ */
/*
@@ -60,37 +60,35 @@ void ttycb(int, short, void *);
/*
* Display the contents of a uio structure on a terminal.
* Schedules an event if write would block, waiting up to TTYMSGTIME
- * seconds. Returns pointer to error string on unexpected error;
- * string is not newline-terminated. Various "normal" errors are ignored
- * (exclusive-use, lack of permission, etc.).
+ * seconds.
*/
-char *
+void
ttymsg(struct iovec *iov, int iovcnt, char *utline)
{
static char device[MAXNAMLEN] = _PATH_DEV;
- static char ebuf[ERRBUFSIZE];
int cnt, fd;
size_t left;
ssize_t wret;
struct iovec localiov[6];
- if (iovcnt < 0 || (size_t)iovcnt > nitems(localiov))
- return ("too many iov's (change code in syslogd/ttymsg.c)");
+ if (iovcnt < 0 || (size_t)iovcnt > nitems(localiov)) {
+ log_warnx("too many iov's (change code in syslogd/ttymsg.c)");
+ return;
+ }
/*
* Ignore lines that start with "ftp" or "uucp".
*/
if ((strncmp(utline, "ftp", 3) == 0) ||
(strncmp(utline, "uucp", 4) == 0))
- return (NULL);
+ return;
(void) strlcpy(device + sizeof(_PATH_DEV) - 1, utline,
sizeof(device) - (sizeof(_PATH_DEV) - 1));
if (strchr(device + sizeof(_PATH_DEV) - 1, '/')) {
/* A slash is an attempt to break security... */
- (void) snprintf(ebuf, sizeof(ebuf), "'/' in \"%s\"",
- device);
- return (ebuf);
+ log_warnx("'/' in tty device \"%s\"", device);
+ return;
}
/*
@@ -98,11 +96,9 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline)
* if not running as root; not an error.
*/
if ((fd = priv_open_tty(device)) < 0) {
- if (errno == EBUSY || errno == EACCES)
- return (NULL);
- (void) snprintf(ebuf, sizeof(ebuf),
- "%s: %s", device, strerror(errno));
- return (ebuf);
+ if (errno != EBUSY && errno != EACCES)
+ log_warn("priv_open_tty device \"%s\"", device);
+ return;
}
left = 0;
@@ -136,9 +132,9 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline)
struct timeval to;
if (tty_delayed >= TTYMAXDELAY) {
- (void) snprintf(ebuf, sizeof(ebuf),
- "%s: too many delayed writes", device);
- goto error;
+ log_warnx("tty device \"%s\": %s",
+ device, "too many delayed writes");
+ break;
}
log_debug("ttymsg delayed write");
if (iov != localiov) {
@@ -147,9 +143,9 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline)
iov = localiov;
}
if ((td = malloc(sizeof(*td))) == NULL) {
- (void) snprintf(ebuf, sizeof(ebuf),
- "%s: malloc: %s", device, strerror(errno));
- goto error;
+ log_warn("allocate delay tty device \"%s\"",
+ device);
+ break;
}
td->td_length = 0;
if (left > MAXLINE)
@@ -169,23 +165,19 @@ ttymsg(struct iovec *iov, int iovcnt, char *utline)
to.tv_sec = TTYMSGTIME;
to.tv_usec = 0;
event_add(&td->td_event, &to);
- return (NULL);
+ return;
}
/*
* We get ENODEV on a slip line if we're running as root,
* and EIO if the line just went away.
*/
- if (errno == ENODEV || errno == EIO)
- break;
- (void) snprintf(ebuf, sizeof(ebuf),
- "%s: %s", device, strerror(errno));
- error:
- (void) close(fd);
- return (ebuf);
+ if (errno != ENODEV && errno != EIO)
+ log_warn("writev tty device \"%s\"", device);
+ break;
}
(void) close(fd);
- return (NULL);
+ return;
}
void