The new std.process is ready for review

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 11 16:21:17 PDT 2013


On Sat, 09 Mar 2013 23:52:26 -0500, Vladimir Panteleev  
<vladimir at thecybershadow.net> wrote:

> On Sunday, 10 March 2013 at 03:48:36 UTC, Steven Schveighoffer wrote:

>>
>> IIRC, you were able to get something working there with std.process2.   
>> Is that example still working?  I'm trying to see what could be  
>> different that's causing this.
>
> Yes, Steven. The ls test program still works:
> http://dump.thecybershadow.net/935b0c4a47ce367313efcc1806f75076/lstest.d

OK, I was able to reproduce on a windows 7 box, and I found the problem.   
Really dumb.  It was the difference in the spawnProcess calls between the  
two programs that gave me the hint.

So the environment pointer to CreateProcess is a list of null-separated  
"var=value" strings.  The last string is followed by an additional null,  
so the function can identify the end of the list.

HOWEVER, if you have NO variables, there is no double null, because there  
isn't the null from the last variable.  However, on XP, a single null  
character is fine, whereas on windows 7, it REQUIRES an extra null  
character, even if you didn't have any variables.  Adding the extra null  
character in toEnvz fixed the problem.

Now, that actually brings up another bug I think.  pipeProcess is sending  
a null to spawnProcess for the environment.  However, because AA's are  
structs, and null is the same as an empty AA, it gets translated into  
"kill the entire environment" for the child process.  I think this is  
wrong.  But at the same time, what if you DID want to kill the entire  
environment?  Should we even support that?  Either way I don't think  
pipeProcess should kill the environment, so that needs to be changed.

Passing null to CreateProcessW copies the parent's environment, I think  
that should be the ultimate default when the environment is not specified,  
even for pipeProcess.  But what should we do if the spawnProcess overload  
that takes an environment receives a null environment?  My instinct is to  
detect an empty AA, and interpret that as "copy parent environment," even  
Lars seems to have interpreted it that way (maybe it works that way on  
Linux as it's written now?) in how he wrote pipeProcess.

I think we can forgo the pull request, the solution is simply to add  
another '\0', that will handle the case where the environment is empty and  
be a noop for when the environment has stuff in it.  But maybe we want to  
make toEnvz return null if it gets an empty AA to avoid killing the  
environment?  I have no idea what the right answer is.

-Steve


More information about the Digitalmars-d mailing list