aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--log.c7
-rw-r--r--log.h2
-rw-r--r--pingu.c38
-rw-r--r--pingu_host.h24
-rw-r--r--xlib.c1
5 files changed, 42 insertions, 30 deletions
diff --git a/log.c b/log.c
index f105ecd..91521c0 100644
--- a/log.c
+++ b/log.c
@@ -20,8 +20,11 @@
#include "pingu.h"
#include "log.h"
-void log_init(void)
+static int log_verbose = 0;
+
+void log_init(int verbose)
{
+ log_verbose = verbose;
openlog("pingu", LOG_PERROR | LOG_PID, LOG_DAEMON);
}
@@ -29,7 +32,7 @@ void log_debug(const char *format, ...)
{
va_list va;
- if (pingu_verbose) {
+ if (log_verbose) {
va_start(va, format);
vsyslog(LOG_DEBUG, format, va);
va_end(va);
diff --git a/log.h b/log.h
index 8668dff..f8581c9 100644
--- a/log.h
+++ b/log.h
@@ -1,6 +1,6 @@
#ifndef LOG_H
#define LOG_H
-void log_init(void);
+void log_init(int verbose);
void log_debug(const char *format, ...);
void log_perror(const char *message);
void log_error(const char *format, ...);
diff --git a/pingu.c b/pingu.c
index 6ebbd7d..db312aa 100644
--- a/pingu.c
+++ b/pingu.c
@@ -27,6 +27,7 @@
#include "log.h"
#include "list.h"
+#include "pingu_host.h"
#ifndef DEFAULT_CONFIG
#define DEFAULT_CONFIG "/etc/pingu/pingu.conf"
@@ -46,24 +47,6 @@ char *default_up_action = NULL;
char *default_down_action = NULL;
char *default_route_script = NULL;
-struct ping_host {
- struct list_head host_list_entry;
- char *host;
- char *source_ip;
- char *label;
- char *interface;
- char *gateway;
- char *up_action;
- char *down_action;
- int status;
- int max_retries;
- int required_replies;
- float timeout;
-
- ev_tstamp burst_interval;
- struct ev_timer burst_timeout_watcher;
-};
-
/* note: this overwrite the line buffer */
void parse_line(char *line, char **key, char **value)
{
@@ -109,7 +92,7 @@ void parse_line(char *line, char **key, char **value)
int read_config(const char *file, struct list_head *head)
{
FILE *f = fopen(file, "r");
- struct ping_host *p = NULL;
+ struct pingu_host *p = NULL;
int lineno = 0;
char line[256];
if (f == NULL) {
@@ -124,8 +107,8 @@ int read_config(const char *file, struct list_head *head)
continue;
if (strcmp(key, "host") == 0) {
- p = xmalloc(sizeof(struct ping_host));
- memset(p, 0, sizeof(struct ping_host));
+ p = xmalloc(sizeof(struct pingu_host));
+ memset(p, 0, sizeof(struct pingu_host));
p->host = xstrdup(value);
p->gateway = xstrdup(value);
p->status = 1; /* online by default */
@@ -186,7 +169,7 @@ int read_config(const char *file, struct list_head *head)
}
/* returns true if it get at least required_replies/retries replies */
-int ping_status(struct ping_host *p, int *seq)
+int ping_status(struct pingu_host *p, int *seq)
{
__u8 buf[1500];
struct iphdr *ip = (struct iphdr *) buf;
@@ -280,7 +263,7 @@ int usage(const char *program)
}
#if 0
-void dump_provider(struct ping_host *p)
+void dump_provider(struct pingu_host *p)
{
printf("router: %s\n"
"provider: %s\n"
@@ -294,7 +277,7 @@ void dump_provider(struct ping_host *p)
}
#endif
-char *get_provider_gateway(struct ping_host *p)
+char *get_provider_gateway(struct pingu_host *p)
{
if (p->gateway != NULL)
return p->gateway;
@@ -303,7 +286,7 @@ char *get_provider_gateway(struct ping_host *p)
void exec_route_change(struct list_head *head)
{
- struct ping_host *p;
+ struct pingu_host *p;
struct list_head *n;
char **args;
int i = 0, status;
@@ -404,7 +387,7 @@ static int daemonize(void)
static void burst_cb(struct ev_loop *loop, struct ev_timer *w,
int revents)
{
- struct ping_host *p = container_of(w, struct ping_host, burst_timeout_watcher);
+ struct pingu_host *p = container_of(w, struct pingu_host, burst_timeout_watcher);
int seq = 0, change = 0;
int status;
status = ping_status(p, &seq);
@@ -425,7 +408,7 @@ static void burst_cb(struct ev_loop *loop, struct ev_timer *w,
int ping_loop(struct list_head *head)
{
static struct ev_loop *loop;
- struct ping_host *p;
+ struct pingu_host *p;
loop = ev_default_loop(0);
list_for_each_entry(p, head, host_list_entry) {
ev_timer_init(&p->burst_timeout_watcher, burst_cb,
@@ -464,6 +447,7 @@ int main(int argc, char *argv[])
argc -= optind;
argv += optind;
+ log_init(0);
if (read_config(config_file, &hostlist) == -1)
return 1;
diff --git a/pingu_host.h b/pingu_host.h
new file mode 100644
index 0000000..1599aa4
--- /dev/null
+++ b/pingu_host.h
@@ -0,0 +1,24 @@
+#ifndef PINGU_HOST_H
+#define PINGU_HOST_H
+
+#include <ev.h>
+
+struct pingu_host {
+ struct list_head host_list_entry;
+ char *host;
+ char *source_ip;
+ char *label;
+ char *interface;
+ char *gateway;
+ char *up_action;
+ char *down_action;
+ int status;
+ int max_retries;
+ int required_replies;
+ float timeout;
+
+ ev_tstamp burst_interval;
+ struct ev_timer burst_timeout_watcher;
+};
+
+#endif
diff --git a/xlib.c b/xlib.c
index 9c8798c..0bc8123 100644
--- a/xlib.c
+++ b/xlib.c
@@ -3,6 +3,7 @@
#include <netinet/in.h>
#include <sys/socket.h>
+#include <err.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>