strndupa() is too arcane for some environments.
[tinc] / src / process.c
index c1dd2d0..9194bed 100644 (file)
@@ -362,7 +362,8 @@ bool execute_script(const char *name, char **envp)
 #ifdef HAVE_SYSTEM
        int status, len;
        struct stat s;
-       char *scriptname;
+       char *scriptname, *p;
+       int i;
 
        cp();
 
@@ -386,8 +387,8 @@ bool execute_script(const char *name, char **envp)
 #ifdef HAVE_PUTENV
        /* Set environment */
        
-       while(*envp)
-               putenv(*envp++);
+       for(i = 0; envp[i]; i++)
+               putenv(envp[i]);
 #endif
 
        scriptname[len - 1] = '\"';
@@ -395,7 +396,17 @@ bool execute_script(const char *name, char **envp)
 
        free(scriptname);
 
-       /* Unset environment? */
+       /* Unset environment */
+
+       for(i = 0; envp[i]; i++) {
+               char *e = strchr(envp[i], '=');
+               if(e) {
+                       p = alloca(e - envp[i] + 1);
+                       strncpy(p, envp[i], e - envp[i]);
+                       p[e - envp[i]] = '\0';
+                       putenv(p);
+               }
+       }
 
 #ifdef WEXITSTATUS
        if(status != -1) {