From f95cc86d0c14ca4c47e5459af4bb6d1170baa9f5 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Tue, 7 Nov 2000 21:43:28 +0000 Subject: [PATCH] Changed execution of tinc-up: - Do not free() strings that have been putenv()d, see man page of the latter. - Do not set IFNAME anymore, it appears that the ioctl to get the name of the interface does not work at all. Since it is set to NETNAME in case of tun/tap and it is known beforehand in case of ethertap, there is no need for it anyway... (though it would've simplified things). --- src/net.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/src/net.c b/src/net.c index a4324a47..bc32b7cc 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.67 2000/11/04 22:57:30 guus Exp $ + $Id: net.c,v 1.35.4.68 2000/11/07 21:43:28 guus Exp $ */ #include "config.h" @@ -74,7 +74,6 @@ int keylifetime = 0; int keyexpires = 0; char *unknown = NULL; -char *interface_name = NULL; /* Contains the name of the interface */ subnet_t mymac; @@ -82,7 +81,7 @@ subnet_t mymac; Execute the given script. This function doesn't really belong here. */ -int execute_script(const char* name) +int execute_script(const char *name) { char *scriptname; pid_t pid; @@ -102,35 +101,28 @@ int execute_script(const char* name) /* Child here */ - asprintf(&scriptname, "%s/%s", confbase, name); - asprintf(&s, "IFNAME=%s", interface_name); - putenv(s); - free(s); - if(netname) { asprintf(&s, "NETNAME=%s", netname); - putenv(s); - free(s); + putenv(s); /* Don't free s! see man 3 putenv */ } else { unsetenv("NETNAME"); } - if(chdir(confbase) < 0) - { - syslog(LOG_ERR, _("Couldn't chdir to `%s': %m"), - confbase); - } + chdir(confbase); /* This cannot fail since we already read config files from this directory. */ + asprintf(&scriptname, "%s/%s", confbase, name); execl(scriptname, NULL); + /* No return on success */ if(errno != ENOENT) /* Ignore if the file does not exist */ syslog(LOG_WARNING, _("Error executing `%s': %m"), scriptname); /* No need to free things */ + exit(0); } @@ -463,18 +455,11 @@ cp strncpy(ifr.ifr_name, netname, IFNAMSIZ); cp if (!ioctl(tap_fd, TUNSETIFF, (void *) &ifr)) - { + { syslog(LOG_INFO, _("%s is a new style tun/tap device"), tapfname); taptype = TAP_TYPE_TUNTAP; } #endif - - /* Add name of network interface to environment (for scripts) */ - - ioctl(tap_fd, SIOCGIFNAME, (void *) &ifr); - interface_name = xmalloc(strlen(ifr.ifr_name)); - strcpy(interface_name, ifr.ifr_name); - cp return 0; } -- 2.20.1