aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNatanael Copa <natanael.copa@gmail.com>2008-12-18 21:14:14 +0100
committerNatanael Copa <natanael.copa@gmail.com>2008-12-18 21:14:14 +0100
commit518df3c6280fa4829d6e389da6ade6a025c2e6c0 (patch)
treeab139a45ef57e6524fffa0b8150869af6ff9260f
parent5fa677e245b39735bce7243b3461723a26b16c3e (diff)
downloadpingu-518df3c6280fa4829d6e389da6ade6a025c2e6c0.tar.bz2
pingu-518df3c6280fa4829d6e389da6ade6a025c2e6c0.tar.xz
misc code cleanup
-rw-r--r--Makefile21
-rw-r--r--pingu.c27
-rw-r--r--pingu.conf4
-rw-r--r--pingu.h6
4 files changed, 38 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 8df6369..4500736 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,21 @@
-pingu: pingu.c
- $(CC) -o $@ $^
+TARGETS = pingu mtu
+CFLAGS ?= -g
+
+pingu_OBJS = \
+ pingu.o \
+ log.o
+
+mtu_OBJS = \
+ mtu.o
+
+ALL_OBJS= $(pingu_OBJS) $(mtu_OBJS)
+
+all: $(TARGETS)
+
+pingu: $(pingu_OBJS)
+
+mtu: $(mtu_OBJS)
clean:
- rm -f pingu
+ rm -f $(TARGETS) $(ALL_OBJS)
diff --git a/pingu.c b/pingu.c
index bfeeefc..515855b 100644
--- a/pingu.c
+++ b/pingu.c
@@ -6,6 +6,10 @@
#include <string.h>
#include <unistd.h>
+#include "pingu.h"
+
+int pingu_verbose = 0;
+
struct provider {
char *name;
char *interface;
@@ -39,16 +43,7 @@ char *xstrdup(const char *str)
return s;
}
-void log_error(const char *str)
-{
- if (errno) {
- /* TODO send to syslog */
- fprintf(stderr, "%s: %s\n", str, strerror(errno));
- } else {
- fprintf(stderr, "%s\n", str);
- }
-}
-
+#if 0
int skip(char **str, int whitespace)
{
char *
@@ -57,6 +52,8 @@ int skip(char **str, int whitespace)
return;
p++;
}
+}
+#endif
/* note: this overwrite the line buffer */
void parse_line(char *line, char **key, char **value)
@@ -108,7 +105,7 @@ struct provider **read_config(const char *file)
int i = 0, lineno = 0;
char line[256];
if (f == NULL) {
- log_error(file);
+ log_perror(file);
return NULL;
}
while (fgets(line, sizeof(line), f)) {
@@ -120,14 +117,14 @@ struct provider **read_config(const char *file)
printf("DEBUG: lineno=%i, key='%s', val='%s'\n",
lineno, key, value);
- if (strcmp(key, "provider") == 0) {
+ if (strcmp(key, "interface") == 0) {
list = xrealloc(list, (i + 2) * sizeof(struct provider *));
p = xmalloc(sizeof(struct provider));
p->name = xstrdup(value);
list[i] = p;
i++;
- } else if (p && strcmp(key, "interface") == 0) {
- p->interface = xstrdup(value);
+ } else if (p && strcmp(key, "provider") == 0) {
+ p->name = xstrdup(value);
} else if (p && strcmp(key, "pinghost") == 0) {
p->pinghost = xstrdup(value);
} else if (p && strcmp(key, "up-action") == 0) {
@@ -135,7 +132,7 @@ struct provider **read_config(const char *file)
} else if (p && strcmp(key, "down-action") == 0) {
p->down_action = xstrdup(value);
} else if (p) {
- log_error("Unknown keyword");
+ log_error("Unknown keyword '%s' on line %i", key, lineno);
} else {
log_error("provider not specified");
}
diff --git a/pingu.conf b/pingu.conf
index c77c6e9..44956a5 100644
--- a/pingu.conf
+++ b/pingu.conf
@@ -1,14 +1,14 @@
# comments are prefixed with #
-provider ISP-1
interface eth0
+provider ISP-1
pinghost 10.2.0.3
up-action /etc/pingu/isp1 up
down-action /etc/pingu/isp1 down
-provider ISP-2
interface eth1
+provider ISP-2
pinghost 192.168.0.1
up-action echo "isp 2 went up" >> /var/log/isp2.log
down-action echo "iso 2 went down" >> /var/log/isp2.log
diff --git a/pingu.h b/pingu.h
new file mode 100644
index 0000000..e5906ad
--- /dev/null
+++ b/pingu.h
@@ -0,0 +1,6 @@
+#ifndef PINGU_H
+#define PINGU_H
+
+extern int pingu_verbose;
+
+#endif