Commit 44824aca3cae1a3908f80216ff8e53f859d16dc4

Guillem Jover 2023-04-01T12:41:42

Declare environ if the system does not do so The environ variable is supposed to be defined by the code using it, but on glibc-based systems it will get defined if we request it, by including <unistd.h> and defining _GNU_SOURCE.

diff --git a/configure.ac b/configure.ac
index 17978b1..4a3c8b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -194,6 +194,10 @@ AC_CHECK_DECL([F_CLOSEM], [
 #include <fcntl.h>
 ]])
 
+AC_CHECK_DECLS([environ], [], [], [[
+#include <unistd.h>
+]])
+
 AC_CACHE_CHECK([for GNU .init_array section support],
   [libbsd_cv_gnu_init_array_support], [
   AC_RUN_IFELSE([
diff --git a/src/setproctitle.c b/src/setproctitle.c
index d3e1087..64ff92a 100644
--- a/src/setproctitle.c
+++ b/src/setproctitle.c
@@ -33,6 +33,10 @@
 #include <string.h>
 #include "local-link.h"
 
+#if !HAVE_DECL_ENVIRON
+extern char **environ;
+#endif
+
 static struct {
 	/* Original value. */
 	const char *arg0;