summaryrefslogtreecommitdiff
path: root/tools/notify-dns-slaves.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/notify-dns-slaves.c')
-rw-r--r--tools/notify-dns-slaves.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/tools/notify-dns-slaves.c b/tools/notify-dns-slaves.c
index e2c3325..65e5a5a 100644
--- a/tools/notify-dns-slaves.c
+++ b/tools/notify-dns-slaves.c
@@ -725,41 +725,48 @@ static void
stdin_callback (int fd, int type, void *arg)
{
char *line;
- int num;
+ int num, rc;
assert (fd == 0);
- num = read (fd, stdin_buffer + stdin_offset, LINE_LENGTH - stdin_offset);
- if (num < 0) {
+ rc = read (fd, stdin_buffer + stdin_offset, LINE_LENGTH - stdin_offset);
+ if (rc < 0) {
if (errno == EAGAIN || errno == EINTR)
return;
warningx ("couldn't read from stdin");
input_complete = 1;
- } else if (num == 0) {
+ } else if (rc == 0) {
debug ("input closed");
input_complete = 1;
} else {
- stdin_offset += num;
+ stdin_offset += rc;
+ assert (stdin_offset <= LINE_LENGTH);
}
do {
- line = strchr (stdin_buffer, '\n');
+ line = memchr (stdin_buffer, '\n', stdin_offset);
+
+ if (line) {
+ num = (line - stdin_buffer) + 1;
- if (!line && input_complete)
+ } else if (!line && input_complete) {
line = stdin_buffer + stdin_offset;
+ num = line - stdin_buffer;
- if (!line && stdin_offset >= LINE_LENGTH) {
+ } else if (!line && stdin_offset >= LINE_LENGTH) {
warningx ("input line too long");
line = stdin_buffer + LINE_LENGTH;
- }
+ num = LINE_LENGTH;
- if (!line) /* Wait for more data */
+ } else {
+ /* Wait for more data */
break;
+ }
*line = 0;
- num = (line + 1) - stdin_buffer;
process_stdin_line (stdin_buffer);
+ assert (stdin_offset >= num);
stdin_offset = stdin_offset - num;
if (stdin_offset)
memmove (stdin_buffer, stdin_buffer + num, stdin_offset);