It turns out the environ variable cannot be redeclared because of -Wredundant-decls. Instead i looked into why it was added and if it can be removed.
It was initially added in commit efb7b9dec135594718b765234bc1f745855f60d2 because (according to the comment) FreeBSD needed it. The man page (all the way back to FreeBSD 1.0) tells us otherwise. If someone could give the reasoning why FreeBSD requires declaring environ that would be helpful because i don't have a FreeBSD machine and cannot test it myself.
In commit bc66878bdea0250991fc99b2d023146f67a6f4bb the environ configure check was added because it gave redundant declaration warnings on Linux. These were the exact same warnings i got when testing redeclaring environ unconditionally.
This ticket has been stuck on the following section.
If someone could give the reasoning why FreeBSD requires declaring environ that would be helpful because i don't have a FreeBSD machine and cannot test it myself.
IMO the environ configure can be removed because nobody has given reasons for it being necessary and all the documentation says it is defined by default.
CC src/common/compat.osrc/common/compat.c: In function 'get_environment':src/common/compat.c:2404: error: 'environ' undeclared (first use in this function)src/common/compat.c:2404: error: (Each undeclared identifier is reported only oncesrc/common/compat.c:2404: error: for each function it appears in.)*** Error 1 in . (Makefile:3699 'src/common/compat.o': @echo " CC " src/common/compat.o;depbase=`echo src/common/compat.o | sed 's|[^/...)
Sorry for the time wasted on my suggestion which didn't work out in the end.
The FreeBSD builds on the BSD buildbot also started failing on this so i took another look at the FreeBSD implementation. This time i looked at the printenv implementation and it shows on line 55 they also define environ.
However, i believe the environ check can be simplified and I've opened #21023 (moved) for that (and other checks).