After x11/lightdm was committed to the ports tree, jbeich pointed out that the function used to clear the process environment in place of clearenv() does not look right: https://lists.freebsd.org/pipermail/svn-ports-head/2016-December/135993.html The issue with the BSDs not having clearenv() was first raised on the LightDM bug reporting system related to NetBSD here: https://bugs.launchpad.net/lightdm/+bug/999714 There was discussion about which of the following should be the replacement: putenv ("environ=NULL"); environ = NULL; The latter option was ultimately committed to LightDM here: http://bazaar.launchpad.net/~lightdm-team/lightdm/trunk/revision/1517 However the FreeBSD port was committed with a patch to change the replacement code to the former option. According to the NOTES section in the Linux kernel manpage for clearenv(3): On systems where clearenv() is unavailable, the assignment environ = NULL; will probably do. http://man7.org/linux/man-pages/man3/clearenv.3.html
Note that if the patch contained in x11/lightdm/files/patch-src_process.c is removed, the build fails with the following error: cc -DHAVE_CONFIG_H -I. -I.. -isystem /usr/local/include -Wall -Wstrict-prototypes -Wnested-externs -Werror=missing-prototypes -Werror=implicit-function-declaration -Wer ror=pointer-arith -Werror=init-self -Werror=format-security -Werror=format=2 -Werror=missing-include-dirs -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/incl ude -I/usr/local/include/gio-unix-2.0/ -pthread -I"../common" -DSBIN_DIR=\"/usr/local/sbin\" -DUSERS_DIR=\"/var/lib/lightdm-data\" -DLOG_DIR=\"/var/log/lightdm\" -DRUN_DIR=\"/var/run/lightdm\" -DCACHE_DIR=\"/var/cache/lightdm\" -DSESSIONS_DIR=\"/usr/loca l/share/lightdm/sessions:/usr/local/share/xsessions:/usr/local/share/wayland-sessions\" -DWAYLAND_SESSIONS_DIR=\"/usr/local/share/wayland-sessions\" -DREMOTE_SESSIONS_DIR=\"/usr/local/share/lightdm/remote-sessions\" -DGREETERS_DIR=\"/usr/local/share/light dm/greeters:/usr/local/share/xgreeters\" -O2 -pipe -fstack-protector -isystem /usr/local/include -fno-strict-aliasing -MT lightdm-seat-xdmcp-session.o -MD -MP -MF .deps/lightdm-seat-xdmcp-session.Tpo -c -o lightdm-seat-xdmcp-session.o `test -f 'seat-xdmc p-session.c' || echo './'`seat-xdmcp-session.c process.c:234:13: error: use of undeclared identifier 'environ' environ = NULL; ^ 1 error generated. gmake[3]: *** [Makefile:990: lightdm-process.o] Error 1
Testing with a dummy program reveals that indeed the existing patch does not clear the environment variables at all, but instead simply adds a new environment variable named environ with the value "NULL". #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { char **ep; extern char **environ; putenv ("environ=NULL"); for (ep = environ; *ep; ep++) (void)printf("%s\n", *ep); } $ ./a.out environ=NULL _=/home/testuser/./a.out PWD=/home/testuser EDITOR=/usr/local/bin/vim ... (prints the remainder of my environment variables) However, using similar code from the FreeBSD env(1) command as suggested by jbeich successfully creates an empty environment. #include <stdio.h> #include <stdlib.h> extern char **environ; int main(int argc, char *argv[]) { char **ep; extern char **environ; char *cleanenv[1]; environ = cleanenv; cleanenv[0] = NULL; for (ep = environ; *ep; ep++) (void)printf("%s\n", *ep); } $ ./a.out $
A commit references this bug: Author: woodsb02 Date: Wed Apr 12 15:44:25 UTC 2017 New revision: 438362 URL: https://svnweb.freebsd.org/changeset/ports/438362 Log: x11/lightdm: Use correct replacement for clearenv() The previous patch to replace the Linux clearenv(3) function did not actually clear the environment, but instead created a new environment variable named environ with the value "NULL". PR: 218564 Reported by: jbeich Obtained from: FreeBSD env(1) command MFH: 2017Q2 Changes: head/x11/lightdm/Makefile head/x11/lightdm/files/patch-src_process.c
A commit references this bug: Author: woodsb02 Date: Tue Apr 25 03:11:49 UTC 2017 New revision: 439357 URL: https://svnweb.freebsd.org/changeset/ports/439357 Log: MFH: r438362 x11/lightdm: Use correct replacement for clearenv() The previous patch to replace the Linux clearenv(3) function did not actually clear the environment, but instead created a new environment variable named environ with the value "NULL". PR: 218564 Reported by: jbeich Obtained from: FreeBSD env(1) command Approved by: ports-secteam (junovitch) Changes: _U branches/2017Q2/ branches/2017Q2/x11/lightdm/Makefile branches/2017Q2/x11/lightdm/files/patch-src_process.c
Merged to 2017Q2.