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

index 302056a..b4c01bb 100644 (file)
@@ -235,7 +235,7 @@ static void check_reachability(void) {
                        char *name;
                        char *address;
                        char *port;
-                       char *envp[7];
+                       char *envp[8] = {NULL};
 
                        xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
                        xasprintf(&envp[1], "DEVICE=%s", device ? : "");
@@ -244,7 +244,7 @@ static void check_reachability(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);
 
@@ -255,7 +255,7 @@ static void check_reachability(void) {
                        free(address);
                        free(port);
 
-                       for(int i = 0; i < 6; i++)
+                       for(int i = 0; i < 7; i++)
                                free(envp[i]);
 
                        subnet_update(n, NULL, n->status.reachable);
index ee8296c..8ae1e72 100644 (file)
@@ -828,12 +828,11 @@ static bool setup_myself(void) {
                io_add(&device_io, handle_device_data, NULL, device_fd, IO_READ);
 
        /* Run tinc-up script to further initialize the tap interface */
-       char *envp[5];
+       char *envp[5] = {NULL};
        xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
        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);
 
@@ -1065,12 +1064,11 @@ void close_network_connections(void) {
        close(unix_socket.fd);
 #endif
 
-       char *envp[5];
+       char *envp[5] = {NULL};
        xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
        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 bf4300e..3b98030 100644 (file)
@@ -204,7 +204,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
 
        // Prepare environment variables to be passed to the script
 
-       char *envp[9] = {NULL};
+       char *envp[10] = {NULL};
        xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
        xasprintf(&envp[1], "DEVICE=%s", device ? : "");
        xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
@@ -219,6 +219,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) {
@@ -260,7 +262,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
                }
        }
 
-       for(int i = 0; envp[i] && i < 8; i++)
+       for(int i = 0; envp[i] && i < 9; i++)
                free(envp[i]);
 }