summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-06-09 15:44:02 +0000
committerStef Walter <stef@memberwebs.com>2008-06-09 15:44:02 +0000
commit3add3c0e19b659427a2624ec85daf67019b8ed7f (patch)
treed838130f55963af53920646a37b4f1004208b586 /tools
parentabb82291887b6784a13a7fcf719fa1d463781007 (diff)
Lots of bug fixes, changes.
Diffstat (limited to 'tools')
-rw-r--r--tools/Makefile.am10
-rw-r--r--tools/notify-dns-slaves.c (renamed from tools/notify-slaves.c)59
2 files changed, 35 insertions, 34 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 19bbc50..fe0ffc5 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -4,14 +4,14 @@ INCLUDES = \
$(PTHREAD_CFLAGS)
bin_PROGRAMS = \
- notify-slaves
+ notify-dns-slaves
-notify_slaves_SOURCES = \
- notify-slaves.c \
+notify_dns_slaves_SOURCES = \
+ notify-dns-slaves.c \
../common/async-resolver.c \
../common/server-mainloop.c \
../common/sock-any.c
# TODO: Somehow PTHREAD_LIBS isn't setup on linux gcc
-notify_slaves_LDFLAGS = -pthread
-notify_slaves_LIBS = $(PTHREAD_LIBS) \ No newline at end of file
+notify_dns_slaves_LDFLAGS = -pthread
+notify_dns_slaves_LIBS = $(PTHREAD_LIBS) \ No newline at end of file
diff --git a/tools/notify-slaves.c b/tools/notify-dns-slaves.c
index ebd2262..96f2ea7 100644
--- a/tools/notify-slaves.c
+++ b/tools/notify-dns-slaves.c
@@ -105,13 +105,13 @@ static int the_socket6 = -1;
static char stdin_buffer[LINE_LENGTH + 1];
static size_t stdin_offset = 0;
-static int stdin_closed = 0;
static int processing_active = 0;
+static int input_complete = 0;
static unsigned int unique_identifier = 1;
static int is_helper = 0;
-static int debug_level = LOG_WARNING;
+static int debug_level = LOG_INFO;
typedef struct _notification {
struct _notification *next;
@@ -164,9 +164,10 @@ vmessage(int level, int erno, const char* msg, va_list ap)
}
/* Either to syslog or stderr */
- if (is_helper && level < LOG_DEBUG)
+ if (is_helper && level != LOG_DEBUG)
vsyslog (level, buf, ap);
- vwarnx(buf, ap);
+
+ vwarnx (buf, ap);
}
static void
@@ -366,20 +367,18 @@ process_all_packets (uint64_t when, void *unused)
}
}
- not = &(*not)->next;
+ not = &notif->next;
}
/* Continue processing? */
if (the_notifications)
return 1;
- if (stdin_closed) {
- debug ("processing done, and no more input, stopping");
+ if (input_complete)
server_stop ();
- } else {
- debug ("processing done for now");
- processing_active = 0;
- }
+
+ debug ("processing done");
+ processing_active = 0;
return 0;
}
@@ -418,6 +417,7 @@ address_resolved (int ecode, struct addrinfo *ai, void *arg)
notif->server, gai_strerror (ecode));
*not = notif->next;
free (notif);
+ break;
/* A successful resolve */
} else {
@@ -426,9 +426,8 @@ address_resolved (int ecode, struct addrinfo *ai, void *arg)
SANY_LEN (notif->address) = ai->ai_addrlen;
notif->resolved = 1;
prepare_and_process (notif, server_get_time ());
+ break;
}
-
- break;
}
}
@@ -641,27 +640,25 @@ stdin_callback (int fd, int type, void *arg)
if (errno == EAGAIN || errno == EINTR)
return;
warningx ("couldn't read from stdin");
- server_unwatch (fd);
- stdin_closed = 1;
- return;
+ input_complete = 1;
} else if (num == 0) {
- stdin_closed = 1;
- server_unwatch (fd);
+ debug ("input closed");
+ input_complete = 1;
+ } else {
+ stdin_offset += num;
}
- stdin_offset += num;
-
- for (;;) {
+ do {
line = strchr (stdin_buffer, '\n');
+ if (!line && input_complete)
+ line = stdin_buffer + stdin_offset;
+
if (!line && stdin_offset >= LINE_LENGTH) {
warningx ("input line too long");
line = stdin_buffer + LINE_LENGTH;
}
- if (!line && stdin_closed)
- line = stdin_buffer + stdin_offset;
-
if (!line) /* Wait for more data */
break;
@@ -672,8 +669,12 @@ stdin_callback (int fd, int type, void *arg)
stdin_offset = LINE_LENGTH - num;
memmove (stdin_buffer, stdin_buffer + num, stdin_offset);
- if (stdin_closed)
- break;
+ } while (!input_complete);
+
+ if (input_complete) {
+ if (!the_notifications)
+ server_stop ();
+ server_unwatch (fd);
}
}
@@ -785,14 +786,14 @@ main(int argc, char *argv[])
fatal (1, "couldn't initialize DNS resolver");
if (is_helper) {
- stdin_closed = 0;
-
+ openlog ("notify-dns-slaves", 0, LOG_DAEMON);
+ input_complete = 0;
/* Watch stdin for data */
fcntl (0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NONBLOCK);
if (server_watch (0, SERVER_READ, stdin_callback, NULL) < 0)
fatal (1, "coludn't watch stdin for changes");
} else {
- stdin_closed = 1;
+ input_complete = 1;
str = argv[0];
for (i = 1; i < argc; ++i)
process_notify (str, argv[i], 0);