On Fri, Oct 21, 2016 at 01:26:36PM +0200, Jeremie Courreges-Anglas wrote:
> Rafael Zalamena <rzalam...@gmail.com> writes:
> > On Fri, Oct 14, 2016 at 06:47:09PM +0200, Rafael Zalamena wrote:
> >> On Mon, Sep 26, 2016 at 03:45:59PM +0200, Rafael Zalamena wrote:
> >> ---snip---
> >
> > I got feedback from jca@ that the trap handler wasn't working, so after
> > trying to reproduce the problem myself I found one 'env' global variable
> > that was not being set and the child process was dying silently.
> > (thanks jca@ !)
> >
> > Instead of depending on snmpe.c:snmpe env initialization (p_init), I'm
> > now calling smi_setenv() to do that in the main() function so all children
> > get the same behaviour. Also note that we don't have an 'extern' env in
> > smi.c anymore.
> >
> > ok?
> 
> Works fine here, but then I don't understand the relationship between
> static struct snmpd *env in smi.c and struct snmpd *env in snmpe.c.

smi.c had a "extern struct snmpd *env" and that variable was only being
set during the snmpe initialzation (p_init). Since with fork+exec the
child process runs entirely from scratch (no memory / socket sharing with
the parent process), we need to set it somewhere else.

It is a known problem that everyone that used to set things in the p_init
and expected it to work for everyother process was wrong. sunil@ found this
the hard-way when he found out that p_env wasn't being set for his process
and he noticed that now p_init is ran in the child process already. Before
fork+exec the p_init() functions were run by the parent process.

To fix the current problem I made the 'env' for smi.c to be a local file
global variable and set it in the main() process for every child.

Reply via email to