Set $NAME when calling host-up/down and subnet-up/down scripts.

This commit is contained in:
Guus Sliepen 2013-07-05 21:36:51 +02:00
parent b811e980e3
commit 2eba793305
3 changed files with 9 additions and 9 deletions

View file

@ -235,7 +235,7 @@ static void check_reachability(void) {
char *name; char *name;
char *address; char *address;
char *port; char *port;
char *envp[7]; char *envp[8] = {NULL};
xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
xasprintf(&envp[1], "DEVICE=%s", device ? : ""); xasprintf(&envp[1], "DEVICE=%s", device ? : "");
@ -244,7 +244,7 @@ static void check_reachability(void) {
sockaddr2str(&n->address, &address, &port); sockaddr2str(&n->address, &address, &port);
xasprintf(&envp[4], "REMOTEADDRESS=%s", address); xasprintf(&envp[4], "REMOTEADDRESS=%s", address);
xasprintf(&envp[5], "REMOTEPORT=%s", port); 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); execute_script(n->status.reachable ? "host-up" : "host-down", envp);
@ -255,7 +255,7 @@ static void check_reachability(void) {
free(address); free(address);
free(port); free(port);
for(int i = 0; i < 6; i++) for(int i = 0; i < 7; i++)
free(envp[i]); free(envp[i]);
subnet_update(n, NULL, n->status.reachable); subnet_update(n, NULL, n->status.reachable);

View file

@ -828,12 +828,11 @@ static bool setup_myself(void) {
io_add(&device_io, handle_device_data, NULL, device_fd, IO_READ); io_add(&device_io, handle_device_data, NULL, device_fd, IO_READ);
/* Run tinc-up script to further initialize the tap interface */ /* 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[0], "NETNAME=%s", netname ? : "");
xasprintf(&envp[1], "DEVICE=%s", device ? : ""); xasprintf(&envp[1], "DEVICE=%s", device ? : "");
xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
xasprintf(&envp[3], "NAME=%s", myself->name); xasprintf(&envp[3], "NAME=%s", myself->name);
envp[4] = NULL;
execute_script("tinc-up", envp); execute_script("tinc-up", envp);
@ -1065,12 +1064,11 @@ void close_network_connections(void) {
close(unix_socket.fd); close(unix_socket.fd);
#endif #endif
char *envp[5]; char *envp[5] = {NULL};
xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); xasprintf(&envp[0], "NETNAME=%s", netname ? : "");
xasprintf(&envp[1], "DEVICE=%s", device ? : ""); xasprintf(&envp[1], "DEVICE=%s", device ? : "");
xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
xasprintf(&envp[3], "NAME=%s", myself->name); xasprintf(&envp[3], "NAME=%s", myself->name);
envp[4] = NULL;
exit_requests(); exit_requests();
exit_edges(); exit_edges();

View 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 // 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[0], "NETNAME=%s", netname ? : "");
xasprintf(&envp[1], "DEVICE=%s", device ? : ""); xasprintf(&envp[1], "DEVICE=%s", device ? : "");
xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); xasprintf(&envp[2], "INTERFACE=%s", iface ? : "");
@ -219,6 +219,8 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) {
free(address); free(address);
} }
xasprintf(&envp[8], "NAME=%s", myself->name);
name = up ? "subnet-up" : "subnet-down"; name = up ? "subnet-up" : "subnet-down";
if(!subnet) { 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]); free(envp[i]);
} }