Rafael Zalamena <rzalam...@gmail.com> writes:

> 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.

I understand this, but...

> 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.

right now there are mixed uses of a global 'env' variable, a global
'snmpd_env' variable, some local 'env' variables set using ps_env or
cs_env fields.  I fear that throwing another *file-local* 'env' variable
in the mix makes the code harder to follow.

Also, why would smi.c be special?

kroute.c:47:extern struct snmpd *env;
mib.c:61:extern struct snmpd    *env;
mps.c:48:extern struct snmpd *env;
timer.c:45:extern struct snmpd  *env;
trap.c:42:extern struct snmpd   *env;
usm.c:45:extern struct snmpd    *env;

-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to