Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/syslogd improve error handling.
details: https://anonhg.NetBSD.org/src/rev/08eece46cb87
branches: trunk
changeset: 779267:08eece46cb87
user: christos <christos%NetBSD.org@localhost>
date: Tue May 15 01:22:50 2012 +0000
description:
improve error handling.
diffstat:
usr.sbin/syslogd/syslogd.c | 32 +++++++++++++++++---------------
1 files changed, 17 insertions(+), 15 deletions(-)
diffs (142 lines):
diff -r 767ecb1974e9 -r 08eece46cb87 usr.sbin/syslogd/syslogd.c
--- a/usr.sbin/syslogd/syslogd.c Mon May 14 21:14:14 2012 +0000
+++ b/usr.sbin/syslogd/syslogd.c Tue May 15 01:22:50 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: syslogd.c,v 1.106 2012/03/28 17:39:33 christos Exp $ */
+/* $NetBSD: syslogd.c,v 1.107 2012/05/15 01:22:50 christos Exp $ */
/*
* Copyright (c) 1983, 1988, 1993, 1994
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) 4/4/94";
#else
-__RCSID("$NetBSD: syslogd.c,v 1.106 2012/03/28 17:39:33 christos Exp $");
+__RCSID("$NetBSD: syslogd.c,v 1.107 2012/05/15 01:22:50 christos Exp $");
#endif
#endif /* not lint */
@@ -471,7 +471,7 @@
if (funixsize == 0)
logpath_add(&LogPaths, &funixsize,
&funixmaxsize, _PATH_LOG);
- funix = (int *)malloc(sizeof(int) * funixsize);
+ funix = malloc(sizeof(*funix) * funixsize);
if (funix == NULL) {
logerror("Couldn't allocate funix descriptors");
die(0, 0, NULL);
@@ -505,9 +505,10 @@
(void) SSL_library_init();
OpenSSL_add_all_digests();
/* OpenSSL PRNG needs /dev/urandom, thus initialize before chroot() */
- if (!RAND_status())
+ if (!RAND_status()) {
+ errno = 0;
logerror("Unable to initialize OpenSSL PRNG");
- else {
+ } else {
DPRINTF(D_TLS, "Initializing PRNG\n");
}
#endif /* (!defined(DISABLE_TLS) && !defined(DISABLE_SIGN)) */
@@ -526,7 +527,7 @@
* All files are open, we can drop privileges and chroot
*/
DPRINTF(D_MISC, "Attempt to chroot to `%s'\n", root);
- if (chroot(root)) {
+ if (chroot(root) == -1) {
logerror("Failed to chroot to `%s'", root);
die(0, 0, NULL);
}
@@ -2194,7 +2195,9 @@
&& (f->f_type != F_TLS)
&& (f->f_type != F_PIPE)
&& (f->f_type != F_FILE)) {
- logerror("Warning: unexpected message in buffer");
+ errno = 0;
+ logerror("Warning: unexpected message type %d in buffer",
+ f->f_type);
DELREF(buffer);
return;
}
@@ -2332,8 +2335,8 @@
if ((f->f_file = p_open(f->f_un.f_pipe.f_pname,
&f->f_un.f_pipe.f_pid)) < 0) {
f->f_type = F_UNUSED;
+ logerror("%s", f->f_un.f_pipe.f_pname);
message_queue_freeall(f);
- logerror("%s", f->f_un.f_pipe.f_pname);
break;
} else if (!qentry) /* prevent recursion */
SEND_QUEUE(f);
@@ -2362,8 +2365,8 @@
if ((f->f_file = p_open(f->f_un.f_pipe.f_pname,
&f->f_un.f_pipe.f_pid)) < 0) {
f->f_type = F_UNUSED;
+ logerror("%s", f->f_un.f_pipe.f_pname);
message_queue_freeall(f);
- logerror("%s", f->f_un.f_pipe.f_pname);
break;
}
if (writev(f->f_file, iov, v - iov) < 0) {
@@ -3801,6 +3804,7 @@
error = getaddrinfo(f->f_un.f_forw.f_hname, "syslog", &hints,
&res);
if (error) {
+ errno = 0;
logerror("%s", gai_strerror(error));
break;
}
@@ -3954,8 +3958,8 @@
hints.ai_socktype = SOCK_DGRAM;
error = getaddrinfo(hostname, "syslog", &hints, &res);
if (error) {
+ errno = 0;
logerror("%s", gai_strerror(error));
- errno = 0;
die(0, 0, NULL);
}
@@ -4029,7 +4033,6 @@
int pfd[2], nulldesc, i;
pid_t pid;
char *argv[4]; /* sh -c cmd NULL */
- char errmsg[200];
if (pipe(pfd) == -1)
return -1;
@@ -4084,10 +4087,8 @@
*/
if (fcntl(pfd[1], F_SETFL, O_NONBLOCK) == -1) {
/* This is bad. */
- (void) snprintf(errmsg, sizeof(errmsg),
- "Warning: cannot change pipe to pid %d to "
+ logerror("Warning: cannot change pipe to pid %d to "
"non-blocking.", (int) pid);
- logerror("%s", errmsg);
}
*rpid = pid;
return pfd[1];
@@ -4112,7 +4113,6 @@
p = malloc(sizeof(*p));
if (p == NULL) {
- errno = 0;
logerror("panic: out of memory!");
exit(1);
}
@@ -4641,6 +4641,7 @@
return false;
q = *p += strlen(keyword);
if (!(q = strchr(*p, '"'))) {
+ errno = 0;
logerror("unterminated \"\n");
return false;
}
@@ -4665,6 +4666,7 @@
while (isspace((unsigned char)**p))
*p += 1;
if (**p != '=') {
+ errno = 0;
logerror("expected \"=\" in file %s, line %d", file, line);
return false;
}
Home |
Main Index |
Thread Index |
Old Index