Allow a hack process which uses daemon, to launch another hack process which also...
commit007f17c01835e8dd29b19315d0b9f6b3d9568084
authorLucian Wischik <ljw@fb.com>
Wed, 24 May 2017 19:04:46 +0000 (24 12:04 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Wed, 24 May 2017 19:19:05 +0000 (24 12:19 -0700)
tree7aba5e741e10abb0c79c09f0c1357cc4b2d832e4
parent0f07bc7247e95180bbc7b21ab10aa34056527e96
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
hphp/hack/src/utils/daemon.ml