On Tue, 12 Mar 2013 03:31:30 -0400, Lars T. Kyllingstad <[email protected]> wrote:


Nice catch! Fortunately, the only bug here is that I've specified a null parameter in the spawn call in pipeProcessImpl(). If you look at the various spawnProcess() overloads, you'll see that they are designed as follows:

If you omit the AA parameter altogether, the child inherits the parent's environment. A null pointer is passed as 'envz' to spawnProcessImpl(), which in turn passes this straight to CreateProcess() on Windows and replaces it by 'environ' on POSIX.

If you do specify the AA parameter, it is passed through toEnvz() on its way to spawnProcessImpl(). If the AA is empty/null, toEnvz() will create an empty (but non-null) environment block, and the child's environment will be empty.

I understand that point. I am a little concerned, however, that passing null as env results in clearing the child environment. These concerns are simply that the most common desire is to inherit the environment, and that there is no parameter that simply says "inherit parent environment," you have to call a different function.

I suppose it's no different than exec, which you have to call the right function depending on what you want.

So this sounds fine. The toEnvz still should be fixed to add an extra null, I'm assuming you're doing that right? :)

I think the bug stems from the fact that, at some intermediate stage of the development, pipeProcessImpl() used to call spawnProcessImpl() directly. I later changed this to spawnProcess(), but forgot to remove the null parameter. I'll simply remove it, and everything will work as intended.

OK, this makes sense.

Initially, I wrote spawnProcess() the way you suggest, i.e. that a passing a null AA is equivalent to omitting it. But then we are left with no simple way to explicitly clear the child's environment. We could make a distinction between a "null" and an "empty" AA, but making a non-null empty AA is a hassle. I think it is better the way it is now.

OK

I don't think we need to support clearing the child's environment in pipeProcess(). I suspect it is a rare need, and the user will just have to deal with spawnProcess() directly in that case. (It's like how there are all kinds of different exec*() functions in C, but only one, simple, popen() function.)

Agree.

-Steve

Reply via email to