gosh: Exit signal-handling goroutine on Cleanup, other cleanups.

I noticed while running tests that we had a bunch of termination
signal handler goroutines running.  It's better to clean up these
goroutines, since they do take up some resources, and more
importantly, clutter up the stack traces on failure.  The new
logic shuts down the goroutine when cleanup is called.  It's hard
to write a test to verify this, since Go doesn't provide a way to
detect that a goroutine has finished.  So I don't have a test.

I also did some minor reorganizing to get better stacktraces from
the goroutines spawned by gosh; basically making sure we had
named functions in the stacktrace to help debugging.

I also noticed that sh.dirStack is used in cleanup, so we need to
ensure sh.cleanupMu is locked when touching it.  I think I missed
this when I added the dirStack to the cleanup.

Finally, I noticed that TestSignal and TestTerminate are flaky,
because of a race between the child process installing the signal
handler, and the test process sending the signal.  I added some
synchronization to avoid this race, and also changed to children
to sleep for 1 hour rather than 1 second, since we're trying to
test the case where they haven't exited yet.

Change-Id: I73a080e781008a1fdcf3401b41d2d5b84e108560
3 files changed
tree: 65e62bdc8737aec582133417dd96a0cb2039faea
  1. cmd/
  2. cmdline/
  3. dbutil/
  4. envvar/
  5. gosh/
  6. host/
  7. ibe/
  8. metadata/
  9. netconfig/
  10. netstate/
  11. set/
  12. textutil/
  13. timing/
  14. toposort/
  15. vlog/
  16. .gitignore
  17. .godepcop
  18. AUTHORS
  19. CONTRIBUTING.md
  20. CONTRIBUTORS
  21. LICENSE
  22. PATENTS
  23. README.md
  24. VERSION
README.md

This repository contains general purpose libraries used by the Vanadium project. TEST