And, the patch ! :)

On Thu, Sep 18, 2008 at 4:29 PM, Pawel Veselov <[EMAIL PROTECTED]> wrote:
> Hi!
>
> I'm attaching the patch that allegedly takes care of these problems.
> The main changes are:
>
> - prevent initializing the environment variables from the shared block twice
> - fix the initialization of the environment variables from the shared block
> - change the function names in shared.c to match shared.h
>
> Thanks!
>  Pawel.
>
> On Wed, Sep 17, 2008 at 6:56 PM, Pawel Veselov <[EMAIL PROTECTED]> wrote:
>> Argh, took me a find out what's going on. Will need some more time to
>> actually produce a fix. Discovered all that while testing the changes
>> to the tracer.
>>
>> The application has a good chance crashing in prologue, if it's being
>> attached to an existing process group. I guess those are the reasons I
>> for the problems I complained on earler, that setting environment
>> variables in 'ush' didn't change the tracing output.
>
> [ skipped ]
>
> --
> With best of best regards
> Pawel S. Veselov
>



-- 
With best of best regards
Pawel S. Veselov
Index: newlib/libc/stdlib/setenv_r.c
===================================================================
--- newlib/libc/stdlib/setenv_r.c	(revision 1182)
+++ newlib/libc/stdlib/setenv_r.c	(working copy)
@@ -58,6 +58,9 @@
 
   ENV_LOCK;
 
+  // $TODO: this seems to be bogus, environment variable value
+  // can certainly start with '=' in general case.
+
   if (*value == '=')		/* no `=' in value */
     ++value;
   l_value = strlen (value);
Index: newlib/libc/sys/wince/sys/shared.h
===================================================================
--- newlib/libc/sys/wince/sys/shared.h	(revision 1182)
+++ newlib/libc/sys/wince/sys/shared.h	(working copy)
@@ -30,10 +30,14 @@
 
 _SHMBLK _shared_init(int pgid);
 void    _shared_dump(_SHMBLK shmblk);
-int    _shared_getshowwindow();
+int     _shared_getshowwindow();
 void    _shared_setshowwindow(_SHMBLK shmblk, int show);
 void    _shared_setenvironblk(_SHMBLK shmblk, char **env);
-void    _shared_getenvironblk(_SHMBLK shmblk, char **env);
+
+// returns the amount of environment variables extracted
+// from the shared block. The environment variables are
+// written into *env, which is allocated using malloc()
+int     _shared_getenvironblk(_SHMBLK shmblk, char **env);
 void    _shared_reset(_SHMBLK shmblk);
 void    _shared_getcwd(_SHMBLK shmblk, char *cwd);
 void    _shared_setcwd(_SHMBLK shmblk, char *cwd);
Index: newlib/libc/sys/wince/startup.c
===================================================================
--- newlib/libc/sys/wince/startup.c	(revision 1182)
+++ newlib/libc/sys/wince/startup.c	(working copy)
@@ -548,7 +548,6 @@
 
     atexit(_ioatexit);
     _shared_dump(shmblk);
-    _shared_getenvblk(shmblk, environ);
     __pgid = _shared_getpgid(shmblk);
     _shared_getcwd(shmblk, buf);
 
Index: newlib/libc/sys/wince/env.c
===================================================================
--- newlib/libc/sys/wince/env.c	(revision 1182)
+++ newlib/libc/sys/wince/env.c	(working copy)
@@ -80,20 +80,24 @@
 {
   if (shmblk)
   {
-	  char buf[MAX_ENVIRONBLK];
+	  char * buf;
 
-          /* We are being initialized from a cegcc app.
-             Kill environ set from the registry.  */
-	  environ[0] = 0;
-	  _shared_getenvblk(shmblk, buf);
-	  if(buf[0] != 0)
-		  _initenv_from_envblock(buf);
-	  else
-		  _initenv_from_reg();
-	  _shared_setenvblk(shmblk, "");
+          // We are being initialized from a cegcc app.
+          // Only use registry environment if there are
+          // no environment variables in the shared block
+
+	  int no = _shared_getenvironblk(shmblk, &buf);
+
+	  if (no) {
+              _initenv_from_envblock(buf);
+              free(buf);
+          } else {
+              _initenv_from_reg();
+          }
   }
   else
   {
 	  _initenv_from_reg();
   }
 }
+
Index: newlib/libc/sys/wince/spawn.c
===================================================================
--- newlib/libc/sys/wince/spawn.c	(revision 1182)
+++ newlib/libc/sys/wince/spawn.c	(working copy)
@@ -93,7 +93,7 @@
   }
 
   WCETRACE(WCE_IO, "spawnv: _shared_init returns %x", shmblk);
-  _shared_setenvblk(shmblk, environ);
+  _shared_setenvironblk(shmblk, environ);
   getcwd(buf, BUFSIZE);
   WCETRACE(WCE_IO, "spawnv: cwd \"%s\"", buf);
   _shared_setcwd(shmblk, buf);
@@ -155,7 +155,7 @@
   }
 
   WCETRACE(WCE_IO, "spawnv: _shared_init returns %x", shmblk);
-  _shared_setenvblk(shmblk, environ);
+  _shared_setenvironblk(shmblk, environ);
   getcwd(buf, BUFSIZE);
   WCETRACE(WCE_IO, "spawnvp: cwd \"%s\"", buf);
   _shared_setcwd(shmblk, buf);
@@ -190,7 +190,7 @@
     return(-1);
   }
 
-  _shared_setenvblk(shmblk, environ);
+  _shared_setenvironblk(shmblk, environ);
   getcwd(buf, BUFSIZE);
   _shared_setcwd(shmblk, buf);
   _shared_setstdinfd(shmblk, (infd >= 0) ? _fdtab[infd].fd : infd);
Index: newlib/libc/sys/wince/shared.c
===================================================================
--- newlib/libc/sys/wince/shared.c	(revision 1182)
+++ newlib/libc/sys/wince/shared.c	(working copy)
@@ -194,7 +194,7 @@
 }
 
 void
-_shared_setenvblk(_SHMBLK shmblk, char **env)
+_shared_setenvironblk(_SHMBLK shmblk, char **env)
 {
 	char *d;
 	int i, len;
@@ -209,7 +209,7 @@
 	for (i = 0, d = shmblk->pginfo.environ; env[i] != NULL; i++) {
 		len = strlen(env[i]);
 		if (d + len >= endp)	{
-			WCETRACE(WCE_IO, "_shared_setenvblk: FATAL space exhausted (max %d)",
+			WCETRACE(WCE_IO, "_shared_setenvironblk: FATAL space exhausted (max %d)",
 				MAX_ENVIRONBLK);
 			exit(1);
 		}
@@ -219,28 +219,32 @@
 	*d = 0;
 }
 
-void
-_shared_getenvblk(_SHMBLK shmblk, char **env)
+int
+_shared_getenvironblk(_SHMBLK shmblk, char **env)
 {
 	char *s;
 	int i, len;
 
-	if (shmblk == NULL)
-		return;
+	if (!shmblk) { return; }
 
 	for (i = 0, s = shmblk->pginfo.environ; *s; i++) {
-		len = strlen(s);
-		if (env[i] != NULL) {
-			free(env[i]);
-		}
-		env[i] = malloc(len + 1);
-		if (env[i] == NULL) {
-			WCETRACE(WCE_IO, "_shared_getenvblk: FATAL ERROR malloc failed");
-			exit(1);
-		}
-		memcpy(env[i], s, len + 1);
-		s += len + 1;
-	}
+            s += strlen(s) + 1;
+        }
+
+        if (i) {
+
+            len = s - shmblk->pginfo.environ + 1;
+            *env = (char*)malloc(len);
+            if (!*env) {
+                WCETRACE(WCE_IO, "_shared_getenvironblk: FATAL ERROR malloc failed for %d more bytes", len);
+                exit(1);
+            }
+
+            memcpy(*env, shmblk->pginfo.environ, len);
+        }
+
+
+        return i;
 }
 
 BOOL
Index: ChangeLog.cegcc
===================================================================
--- ChangeLog.cegcc	(revision 1182)
+++ ChangeLog.cegcc	(working copy)
@@ -1,3 +1,18 @@
+2008-09-18  Pawel Veselov <[EMAIL PROTECTED]>
+        * newlib/libc/stdlib/setenv_r.c: flag a possible problem with
+          environment variable values that start with '='
+        * newlib/libc/sys/wince/sys/shared.h: _shared_getenvironblk() now
+          returns (int). Also added description for _shared_getenvironblk()
+        * newlib/libc/sys/wince/startup.c: do not reset environment variables
+          from the shared block, as it's already been done
+        * newlib/libc/sys/wince/env.c: fix shared block environment variables
+          initialization
+        * newlib/libc/sys/wince/spawn.c: use proper function names
+        * newlib/libc/sys/wince/shared.c: change _shared_getenvironblk() 
+          behavior to dump full environment block as is, not chop it up
+          into separate variables. Rename _shared_setenvblk() and
+          _shared_setenvblk() to match the header file declarations.
+
 2008-09-12  Pawel Veselov <[EMAIL PROTECTED]>
         * newlib/newlib/libc/include/stdlib.h : added realpath() declaration
         * newlib/libc/sys/wince/Makefile.in newlib/libc/sys/wince/Makefile.am :
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Cegcc-devel mailing list
Cegcc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cegcc-devel

Reply via email to