aboutsummaryrefslogtreecommitdiffstats
path: root/pingu_host.c
diff options
context:
space:
mode:
authorNatanael Copa <ncopa@alpinelinux.org>2011-07-08 11:26:03 +0200
committerNatanael Copa <ncopa@alpinelinux.org>2011-07-08 11:26:03 +0200
commit6a3615ac20970c6cee440ab65234e828013be10b (patch)
treead634380a20799418fa00a1102f5cf79e0e8c757 /pingu_host.c
parent312cea0e34d3e2f7dbbe3f3832a6b1440ed57563 (diff)
downloadpingu-6a3615ac20970c6cee440ab65234e828013be10b.tar.bz2
pingu-6a3615ac20970c6cee440ab65234e828013be10b.tar.xz
pingu: run the route-script again
Diffstat (limited to 'pingu_host.c')
-rw-r--r--pingu_host.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/pingu_host.c b/pingu_host.c
index e184576..ed07487 100644
--- a/pingu_host.c
+++ b/pingu_host.c
@@ -144,6 +144,55 @@ int pingu_host_read_config(const char *file)
return 0;
}
+static char *get_provider_gateway(struct pingu_host *p)
+{
+ if (p->gateway != NULL)
+ return p->gateway;
+ return p->host;
+}
+
+static void exec_route_change(void)
+{
+ struct pingu_host *host;
+ struct list_head *n;
+ char **args;
+ int i = 0;
+ pid_t pid;
+
+ if (default_route_script == NULL)
+ return;
+
+ list_for_each(n, &host_list)
+ i++;
+
+ args = malloc(sizeof(char *) * (i + 2));
+ if (args == NULL) {
+ log_perror("malloc");
+ return;
+ }
+
+ i = 0;
+ args[i++] = default_route_script;
+ list_for_each_entry(host, &host_list, host_list_entry) {
+ if (host->status)
+ args[i++] = get_provider_gateway(host);
+ }
+ args[i] = NULL;
+ pid = fork();
+ if (pid < 0) {
+ log_perror("fork");
+ free(args);
+ return;
+ }
+ if (pid == 0) {
+ /* the child */
+ execvp(default_route_script, args);
+ log_perror(args[0]);
+ exit(1);
+ }
+ /* libev reaps all children */
+}
+
static void execute_action(const char *action)
{
pid_t pid;
@@ -184,6 +233,7 @@ void pingu_host_set_status(struct pingu_host *host, int status)
}
if (action != NULL)
execute_action(action);
+ exec_route_change();
}
int pingu_host_verify_status(struct ev_loop *loop, struct pingu_host *host)