summaryrefslogtreecommitdiff
path: root/sbin/pflogd
diff options
context:
space:
mode:
authorCan Erkin Acar <canacar@cvs.openbsd.org>2004-01-15 20:10:44 +0000
committerCan Erkin Acar <canacar@cvs.openbsd.org>2004-01-15 20:10:44 +0000
commit925241ffb71a8c50f24fb0b27f8283fd918ece56 (patch)
tree1c3fdaf251366c1d888d6a573a7638e508c8f2bb /sbin/pflogd
parented808d35e669774367956852513c83ed8599bcbd (diff)
Synchronize with syslogd privsep: When reading a new command fails,
terminate the loop instead of exiting directly, suggested by avsm@ Also get rid of trailing comma in enum, makes lint(1) happier, from Andrey Matveev andrushock at korovino dot net
Diffstat (limited to 'sbin/pflogd')
-rw-r--r--sbin/pflogd/privsep.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/sbin/pflogd/privsep.c b/sbin/pflogd/privsep.c
index 7a7844b6d7e..0eb244ba35a 100644
--- a/sbin/pflogd/privsep.c
+++ b/sbin/pflogd/privsep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.c,v 1.4 2003/10/22 19:53:15 deraadt Exp $ */
+/* $OpenBSD: privsep.c,v 1.5 2004/01/15 20:10:43 canacar Exp $ */
/*
* Copyright (c) 2003 Can Erkin Acar
@@ -41,7 +41,7 @@
enum cmd_types {
PRIV_SET_SNAPLEN, /* set the snaplength */
- PRIV_OPEN_LOG, /* open logfile for appending */
+ PRIV_OPEN_LOG /* open logfile for appending */
};
static int priv_fd = -1;
@@ -51,6 +51,7 @@ volatile sig_atomic_t gotsig_chld = 0;
static void sig_pass_to_chld(int);
static void sig_chld(int);
+static int may_read(int, void *, size_t);
static void must_read(int, void *, size_t);
static void must_write(int, void *, size_t);
static int set_snaplen(int snap);
@@ -119,7 +120,8 @@ priv_init(void)
close(socks[1]);
while (!gotsig_chld) {
- must_read(socks[0], &cmd, sizeof(int));
+ if (may_read(socks[0], &cmd, sizeof(int)))
+ break;
switch (cmd) {
case PRIV_SET_SNAPLEN:
logmsg(LOG_DEBUG,
@@ -230,6 +232,28 @@ sig_chld(int sig)
gotsig_chld = 1;
}
+/* Read all data or return 1 for error. */
+static int
+may_read(int fd, void *buf, size_t n)
+{
+ char *s = buf;
+ ssize_t res, pos = 0;
+
+ while (n > pos) {
+ res = read(fd, s + pos, n - pos);
+ switch (res) {
+ case -1:
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ case 0:
+ return (1);
+ default:
+ pos += res;
+ }
+ }
+ return (0);
+}
+
/* Read data with the assertion that it all must come through, or
* else abort the process. Based on atomicio() from openssh. */
static void