28
28
29
29
#include "portab.h"
30
30
#include "globals.h"
31
+ #include "debug.h"
32
+
31
33
32
- #ifdef VERSION_STRINGS
33
- static BYTE * RcsId =
34
- "$Id: task.c 1563 2011-04-08 16:04:24Z bartoldeman $" ;
35
- #endif
36
34
37
35
#define toupper (c ) ((c) >= 'a' && (c) <= 'z' ? (c) + ('A' - 'a') : (c))
38
36
@@ -130,6 +128,9 @@ STATIC UWORD SetverGetVersion(BYTE FAR *table, BYTE FAR *name)
130
128
return 0 ;
131
129
}
132
130
131
+ /* allocate memory for and copy current process env to child environment
132
+ returns segment of env MCB (not env block itself) in pChildEnvSeg
133
+ */
133
134
STATIC COUNT ChildEnv (exec_blk * exp , UWORD * pChildEnvSeg , char far * pathname )
134
135
{
135
136
BYTE FAR * pSrc ;
@@ -167,18 +168,27 @@ STATIC COUNT ChildEnv(exec_blk * exp, UWORD * pChildEnvSeg, char far * pathname)
167
168
if (nEnvSize >= MAXENV - ENV_KEEPFREE )
168
169
return DE_INVLDENV ;
169
170
171
+ /* loop until first double terminator '\0\0' found */
170
172
if (* (UWORD FAR * ) (pSrc + nEnvSize ) == 0 )
171
173
break ;
172
174
}
173
175
nEnvSize += 2 ; /* account for trailing \0\0 */
174
176
}
175
177
176
- /* allocate enough space for env + path */
178
+ /* allocate enough space for env + path (rounding up to nearest para)
179
+ Note: we must allocate at least 1 paragraph (16 bytes) for empty environment
180
+ + ENV_KEEPFREE for argv[0] (program name)
181
+ */
182
+ DebugPrintf (("PriPathName is %lu bytes\n" , sizeof (PriPathName )));
183
+ assert (sizeof (PriPathName )+ 3 == ENV_KEEPFREE );
177
184
if ((RetCode = DosMemAlloc ((nEnvSize + ENV_KEEPFREE + 15 )/16 ,
178
185
mem_access_mode , pChildEnvSeg ,
179
186
NULL /*(UWORD FAR *) MaxEnvSize ska */ )) < 0 )
187
+ {
188
+ DebugPrintf (("Error alloc Env space\n" ));
180
189
return RetCode ;
181
- pDest = MK_FP (* pChildEnvSeg + 1 , 0 );
190
+ }
191
+ pDest = MK_FP (* pChildEnvSeg + 1 , 0 ); /* skip past MCB and set pDest to start of env block */
182
192
183
193
/* fill the new env and inform the process of its */
184
194
/* location throught the psp */
@@ -199,8 +209,10 @@ STATIC COUNT ChildEnv(exec_blk * exp, UWORD * pChildEnvSeg, char far * pathname)
199
209
/* copy complete pathname */
200
210
if ((RetCode = truename (pathname , PriPathName , CDS_MODE_SKIP_PHYSICAL )) < SUCCESS )
201
211
{
212
+ DebugPrintf (("Failed to get truename for env argv0\n" ));
202
213
return RetCode ;
203
214
}
215
+ DebugPrintf (("ChildEnv for [%s]\n" , PriPathName ));
204
216
fstrcpy (pDest , PriPathName );
205
217
206
218
/* Theoretically one could either:
@@ -472,6 +484,9 @@ COUNT DosComLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
472
484
}
473
485
474
486
rc = ChildEnv (exp , & env , namep );
487
+ #if DEBUG
488
+ if (rc != SUCCESS ) DebugPrintf (("Failed to create ChildEnv\n" ));
489
+ #endif
475
490
476
491
/* COMFILES will always be loaded in largest area. is that true TE */
477
492
/* yes, see RBIL, int21/ah=48 -- Bart */
@@ -652,6 +667,9 @@ COUNT DosExeLoader(BYTE FAR * namep, exec_blk * exp, COUNT mode, COUNT fd)
652
667
}
653
668
654
669
rc = ChildEnv (exp , & env , namep );
670
+ #if DEBUG
671
+ if (rc != SUCCESS ) DebugPrintf (("Failed to create ChildEnv\n" ));
672
+ #endif
655
673
656
674
if (rc == SUCCESS )
657
675
/* Now find out how many paragraphs are available */
0 commit comments