Allow a hack process which uses daemon, to launch another hack process which also uses daemon
Summary:
Hack uses a monstrous affordance to simulate thread-spawning: it sets an environment variable with the new thread's entry-point, then forks+execs, and the newly forked thing is expected to read the environment variable and (if it's set) then jump to the thread entry point.
But what happens if hh_client uses daemon to fork a thread (so setting the environment variable), and then it launches hh_server (which itself uses threads and so checks for the environment variable at startup)? -- It produces a confusing error message along the lines "/tmp/daemon236.bin not found".
When the thread starts, it reads a temporary file of marshalled data (the filename is stored in an environment variable) and then promptly deletes the file. This is a clue that we should also be RESETTING the environment variables at the same time. They will certainly be useless after the file has been deleted. So that's what this diff does.
There's one minor niggle. As far as I can tell, ocaml doesn't allow us to UNSET an environment variable. So I'm setting the environment variable to an empty string. Then, upon read, I'm treating empty-string and absent-environment-variable the same.
Reviewed By: arxanas, alexchow
Differential Revision:
D5111096
fbshipit-source-id:
bf5742715f4b4837ec88d9a920fd56787bb6e458