Fix race condition when starting env_syncer in enter_chroot.sh.

Sometimes, two processes might start the env_syncer at the same time.
If this occurs, then the pid file will get overwritten and one of the
processes won't be killed.

I've also fixed the env_syncer to properly daemonize, such that
cbuildbot won't wait on the env_syncer to be killed before exiting.
This requires closing stdin, stderr, and stdout.

BUG=chromium-os:17680
TEST=Reproduce hang, and verify that this fixes the hang. Verify that
     multiple chroots can be entered at the same time and that the
     env_syncer is killed when the last chroot exits. Verify that
     cbuildbot is not kept hanging even if the env_syncer doesn't
     exit.

Change-Id: I3cb9fbdf47a406e818e12cf91593b8e3481aa578
Reviewed-on: http://gerrit.chromium.org/gerrit/4232
Reviewed-by: Ryan Cui <rcui@chromium.org>
Tested-by: David James <davidjames@chromium.org>
1 file changed
tree: 2478e3b7e41e1a331022a799e9c0a744e50b8e95
  1. bin/
  2. chroot_version_hooks.d/
  3. lib/
  4. mod_for_factory_scripts/
  5. mod_for_test_scripts/
  6. .gitignore
  7. archive_build.sh
  8. archive_hwqual
  9. bash_completion
  10. build_gpt.sh
  11. build_image
  12. build_kernel_image.sh
  13. call_autoserv.py
  14. check_control_files.sh
  15. check_deps
  16. chromeos_blacklist
  17. clean_loopback_devices
  18. common.sh
  19. create_esp.sh
  20. create_legacy_bootloader_templates.sh
  21. cros_deps_diff
  22. cros_download_latest_image
  23. cros_generate_breakpad_symbols
  24. cros_generate_deps_graphs
  25. cros_show_stacks
  26. dot_helper.py
  27. emit_gpt_scripts.sh
  28. enable_localaccount.sh
  29. enter_chroot.sh
  30. file_copy.py
  31. fixup_image_for_qemu.py
  32. generate_au_zip.py
  33. get_latest_image.sh
  34. get_package_list
  35. image_to_usb.sh
  36. image_to_vm.sh
  37. inherit-review-settings-ok
  38. make_developer_script_runner.sh
  39. make_factory_package.sh
  40. make_netboot.sh
  41. make_universal_factory_shim.sh
  42. mk_memento_images.sh
  43. mod_image_for_recovery.sh
  44. mod_image_for_test.sh
  45. mount_gpt_image.sh
  46. remote_access.sh
  47. resize_stateful_partition.sh
  48. run_chroot_version_hooks
  49. serve_factory_packages.py
  50. set_shared_user_password.sh
  51. ssh_test.sh
  52. start_devserver
  53. test_build_root
  54. test_image
  55. update_bootloaders.sh
  56. update_chroot
  57. update_kernel.sh
  58. upload_symbols
  59. verify_rootfs_chksum.sh
  60. WATCHLISTS