From a834075aac70cf3ca01ed23d8220fb556730fe06 Mon Sep 17 00:00:00 2001 From: John Marino Date: Sun, 10 Feb 2013 12:32:58 +0100 Subject: [PATCH] libcsu: Assign environment when environ is NULL Preloaded libraries can change the environment. The current logic will unconditionally reassign the environment, undoing any previous customization. This change preserves the previous customization. Taken-from: FreeBSD SVN 245133 (07 Jan 2013) --- lib/csu/common/initfini.c | 14 +++++++++----- lib/csu/i386/crt1_c.c | 4 +--- lib/csu/x86_64/crt1.c | 4 +--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/csu/common/initfini.c b/lib/csu/common/initfini.c index a6760bb0ad..48dd815ad2 100644 --- a/lib/csu/common/initfini.c +++ b/lib/csu/common/initfini.c @@ -84,14 +84,18 @@ handle_static_init(int argc, char **argv, char **env) } static inline void -handle_progname(const char *v) +handle_argv(int argc, char *argv[], char **env) { const char *s; - __progname = v; - for (s = __progname; *s != '\0'; s++) { - if (*s == '/') - __progname = s + 1; + if (environ == NULL) + environ = env; + if (argc > 0 && argv[0] != NULL) { + __progname = argv[0]; + for (s = __progname; *s != '\0'; s++) { + if (*s == '/') + __progname = s + 1; + } } } diff --git a/lib/csu/i386/crt1_c.c b/lib/csu/i386/crt1_c.c index 79c696f560..d9b1fad505 100644 --- a/lib/csu/i386/crt1_c.c +++ b/lib/csu/i386/crt1_c.c @@ -57,9 +57,7 @@ _start1(fptr cleanup, int argc, char *argv[]) char **env; env = argv + argc + 1; - environ = env; - if (argc > 0 && argv[0] != NULL) - handle_progname(argv[0]); + handle_argv(argc, argv, env); /* * Setup the initial TLS space. The RTLD does not set up our TLS diff --git a/lib/csu/x86_64/crt1.c b/lib/csu/x86_64/crt1.c index 665eef8021..d1acef8460 100644 --- a/lib/csu/x86_64/crt1.c +++ b/lib/csu/x86_64/crt1.c @@ -56,9 +56,7 @@ _start(char **ap, void (*cleanup)(void)) argc = *(long *)(void *)ap; argv = ap + 1; env = ap + 2 + argc; - environ = env; - if (argc > 0 && argv[0] != NULL) - handle_progname(argv[0]); + handle_argv(argc, argv, env); /* * Setup the initial TLS space. The RTLD does not set up our TLS -- 2.41.0