[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: Re: ifplugd: the SIGHUP handling and repeated setenv calls
From: Denys Vlasenko <vda.linux () googlemail ! com>
Date: 2010-04-27 5:27:41
Message-ID: 201004270727.41233.vda.linux () googlemail ! com
[Download RAW message or body]
On Wednesday 21 April 2010 11:46, Maksym Kryzhanovskyy wrote:
> > > Hi Denis,
> > >
> > > if you do not mind, I have two questions about ifplugd.
> > >
> > > 1. How to handle the SIGHUP signal? The ifplugd-0.28 writes to log:
> > >
> > > switch (sig) {
> > > case SIGINT:
> > > case SIGTERM: goto cleanup;
> > > case SIGQUIT: goto finish;
> > > case SIGCHLD: break;
> > > case SIGHUP:
> > > daemon_log(LOG_INFO, "SIGHUP: %s, link detected on %s: %s",
> > > paused ? "Suspended" : "Running",
> > > interface,
> > > status == IFSTATUS_DOWN ? "no" : "yes"
> > > );
> > > if (use_ifmonitor)
> > > daemon_log(LOG_INFO, "SIGHUP: Interface %s", disabled ?
> > "disabled" : "enabled");
> > > break;
> > > case SIGUSR1:
> > > daemon_log(LOG_INFO, "SIGUSR1: Daemon suspended (#%i)", ++paused);
> > > break;
> > > case SIGUSR2:
> > > if (paused > 0) {
> > > daemon_log(LOG_INFO, "SIGUSR2: Daemon resumed (#%i)", paused);
> > > paused --;
> > > }
> > > break;
> > > default:
> > > daemon_log(LOG_INFO, "Ignoring unknown signal %s", strsignal(sig));
> > > break;
> > > }
> > >
> > > Do we need to inherit it?
> >
> > Until someone asks for it, it looks unnnecessary.
> > If you want to add it, add it inside #if 0
>
> Attached is a patch.
>
> >
> > > 2. What may happen with repeated setenv() calls?
> > >
> > > if (status != G.iface_last_status) {
> > > //TODO: is it safe to repeatedly do this?
> > > setenv(IFPLUGD_ENV_PREVIOUS, strstatus(G.iface_last_status), 1);
> > > setenv(IFPLUGD_ENV_CURRENT, strstatus(status), 1);
> > > G.iface_last_status = status;
> > > }
> >
> > There is no guarantee successive setenv's do not allocate
> > new malloc bocks to construct "VAR=VAL" strings without
> > freeing ones from previous calls.
>
> I understand. I looked at the setenv implementation in glibc and uClibc. Can we
> do something with it? Apply xsetenv from libbb there is not probably a good idea?
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
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic