Mail Archives: djgpp-workers/2002/01/20/06:56:56
Hello.
Eli Zaretskii wrote:
> To clarify: what this comment _really_ wants to tell is that the
> original environ, the one putenv sees on its very first call, _must_
> be malloc'ed. Once the first call was made (typically, by the
> startup code), it is okay to do what the test program did,
> i.e. replace environ with a non-malloc'ed array.
>
> It's quite possible that this explains the cause for the: If having
> $DJGPP undefined prevents putenv from being called during startup
> even once, putenv will indeed be unable to cope with such code.
Yes, this seems to be the case, looking at __crt0_load_environment_file in
src/libc/crt0/c1loaddef.c.
> This suggests a solution: add a dummy putenv call to the startup
> code, which will be called unconditionally.
Yes, this works. There's a patch below. Do you think this code should be in
crt1.c instead of this function or is it OK where it is? OK to commit?
Eli, would you still like YAMD versions of Charles's test programs? I don't
think there's any memory corruption going on (see other mail). 'environ' did
not get set to any unexpected values when I tested using gdb watchpoints
(watch environ != <address returned from malloc in startup code>). But I can
provide you with test images, if you'd like.
Thanks, bye, Rich =]
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
Index: c1loadef.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/crt0/c1loadef.c,v
retrieving revision 1.5
diff -p -u -3 -r1.5 c1loadef.c
--- c1loadef.c 1999/06/03 17:27:35 1.5
+++ c1loadef.c 2002/01/20 11:51:22
@@ -1,3 +1,4 @@
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
@@ -10,12 +11,23 @@
#include <string.h>
#include <ctype.h>
#include <unistd.h>
+#include <libc/unconst.h>
void
__crt0_load_environment_file(char *app_name)
{
int djgpp_env;
char *djgpp_var = getenv("DJGPP");
+
+ /*
+ * Call putenv so that its static counters are computed. If this
+ * is not done, programs that manipulate `environ' directly will crash,
+ * when `DJGPP' is not set in the environment.
+ *
+ * Use putenv to delete an environment variable with a name that is
+ * unlikely to be used.
+ */
+ putenv(unconst("DJGPP_sillynametohaveforanenvironmentvariable", char *));
if (djgpp_var)
{
- Raw text -