smarter handling of environment variables.

See: https://github.com/chjj/tty.js/issues/95
send SIGHUP instead of SIGTERM.
minor refactor.