[PATCH] ifplugd: repeated setenv calls

Denys Vlasenko vda.linux at googlemail.com
Sat May 8 21:25:42 UTC 2010


On Friday 07 May 2010 10:00, Maksym Kryzhanovskyy wrote:
> > What we can do is to use the sequence
> > 
> > unsetenv(IFPLUGD_ENV_PREVIOUS);
> > free(env_PREVIOUS);
> > env_PREVIOUS = xasprintf(IFPLUGD_ENV_PREVIOUS"=%s",
> > strstatus(G.iface_last_status));
> > putenv(env_PREVIOUS);
> > 
> > every time we want to set the variable to the new value.
> > env_PREVIOUS is a global variable of type char*.
> > This will work correctly with any libc.
> > 
> > -- 
> > vda
> > 
> 
> Hi Denis,
> 
> thanks for your reply. I wrote two alternatives to
> apply this technique. Please consider their usage.

ifplugd.setenv1.patch looks better. These lines are not needed:
+       G.env_PREVIOUS = NULL; \
+       G.env_CURRENT = NULL; \
the rest is fine.

I applied a bit different version of it - I set/unset
env just around spawn_and_wait(). See attached.


ifplugd.setenv2.patch:

+       env = getenv(name);
+       unsetenv(name);
+       if (env != NULL) {
+               free(env - strlen(name) - 1);
+       }

Why do you think getenv result is safe to be freed?
Initial program environment is NOT malloced,
you must not free it, this may SEGV!

-- 
vda
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 8.patch
Type: text/x-diff
Size: 3523 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20100508/485a84ea/attachment.bin>


More information about the busybox mailing list