Set $NAME when calling host-up/down and subnet-up/down scripts.
authorGuus Sliepen <guus@tinc-vpn.org>
Fri, 5 Jul 2013 18:51:27 +0000 (20:51 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Fri, 5 Jul 2013 18:53:53 +0000 (20:53 +0200)
src/graph.c
src/net_setup.c
src/subnet.c

index 203942d..a15e5c7 100644 (file)
@@ -156,7 +156,7 @@ static void sssp_bfs(void) {
        bool indirect;
        char *name;
        char *address, *port;
-       char *envp[7];
+       char *envp[8] = {NULL};
        int i;
 
        todo_list = list_alloc(NULL);
@@ -269,7 +269,7 @@ static void sssp_bfs(void) {
                        sockaddr2str(&n->address, &address, &port);
                        xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
                        xasprintf(&envp[5], "REMOTEPORT=%s", port);
-                       envp[6] = NULL;
+                       xasprintf(&envp[6], "NAME=%s", myself->name);
 
                        execute_script(n->status.reachable ? "host-up" : "host-down", envp);
 
@@ -282,7 +282,7 @@ static void sssp_bfs(void) {
                        free(address);
                        free(port);
 
-                       for(i = 0; i < 6; i++)
+                       for(i = 0; i < 7; i++)
                                free(envp[i]);
 
                        subnet_update(n, NULL, n->status.reachable);
index 5a7c606..623ac38 100644 (file)
@@ -334,7 +334,7 @@ static bool setup_myself(void) {
        char *address = NULL;
        char *proxy = NULL;
        char *space;
-       char *envp[5];
+       char *envp[5] = {NULL};
        struct addrinfo *ai, *aip, hint = {0};
        bool choice;
        int i, err;
@@ -692,11 +692,10 @@ static bool setup_myself(void) {
        xasprintf(&envp[1], "DEVICE=%s", device ? : "");
        xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
        xasprintf(&envp[3], "NAME=%s", myself->name);
-       envp[4] = NULL;
 
        execute_script("tinc-up", envp);
 
-       for(i = 0; i < 5; i++)
+       for(i = 0; i < 4; i++)
                free(envp[i]);
 
        /* Run subnet-up scripts for our own subnets */
@@ -862,7 +861,7 @@ bool setup_network(void) {
 void close_network_connections(void) {
        avl_node_t *node, *next;
        connection_t *c;
-       char *envp[5];
+       char *envp[5] = {NULL};
        int i;
 
        for(node = connection_tree->head; node; node = next) {
@@ -896,7 +895,6 @@ void close_network_connections(void) {
        xasprintf(&envp[1], "DEVICE=%s", device ? : "");
        xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
        xasprintf(&envp[3], "NAME=%s", myself->name);
-       envp[4] = NULL;
 
        exit_requests();
        exit_edges();
index d7b9f47..7b67352 100644 (file)
@@ -523,7 +523,7 @@ subnet_t *lookup_subnet_ipv6(const ipv6_t *address) {
 void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
        avl_node_t *node;
        int i;
-       char *envp[9] = {NULL};
+       char *envp[10] = {NULL};
        char netstr[MAXNETSTR];
        char *name, *address, *port;
        char empty[] = "";
@@ -544,6 +544,8 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
                free(address);
        }
 
+       xasprintf(&envp[8], "NAME=%s", myself->name);
+
        name = up ? "subnet-up" : "subnet-down";
 
        if(!subnet) {