base: syslog panics on double-init.

We've had multiple silent bugs stemming from the current double-init
behavior of the logging system. To prevent that from happening for the
fourth time, this CL makes all subsequent logging inits panic. This way,
it will be much harder to commit code that won't work. Details:

* Current behavior: only the first init applies logging configuration.
  The subsequent inits will silently do nothing, and discard the
  supplied settings. These settings could be important things like
  setting the log file, whether to echo to stderr, etc.
* New behavior: after the first call to init, any subseqent call will

NOTE: If this CL breaks a downstream project, there is very likely
a bug in that project which may be causing logs from crosvm to be
lost. Please fix that bug, or revert this CL in the downstream project

In this CL, we discovered that openlog_and_get_socket (used in linux
syslog) mutates global state. In tests, this manifested as a failure.
For this CL, we've chosen to preserve the behavior of only re-creating
State (and by extension, PlatformSyslog) when there is no STATE
currently set. (This behavior is nice for other reasons since it keeps
us from performing unnecessary operations when a no-op is possible.)

TEST=presubmit & tested downstream by verifying log files were written.
Also ran example_simple & verified it didn't panic.

Change-Id: Iad64c1b52b917e63d14a42cbbd1739ef94107fae
Commit-Queue: Noah Gold <>
Tested-by: kokoro <>
Reviewed-by: Daniel Verkamp <>
Reviewed-by: Vikram Auradkar <>
3 files changed
tree: 31d99e4504267aa388d179e24d5fe59825e70cb6
  1. .cargo/
  2. .devcontainer/
  3. .github/
  4. aarch64/
  5. acpi_tables/
  6. arch/
  7. argh_helpers/
  8. base/
  9. bin/
  10. bit_field/
  11. broker_ipc/
  12. ci/
  13. common/
  14. cros_async/
  15. crosvm-fuzz/
  16. crosvm_control/
  17. crosvm_plugin/
  18. devices/
  19. disk/
  20. docs/
  21. fuse/
  22. gpu_display/
  23. hypervisor/
  24. infra/
  25. integration_tests/
  26. io_uring/
  27. kernel_cmdline/
  28. kernel_loader/
  29. kvm/
  30. kvm_sys/
  31. libcras_stub/
  32. linux_input_sys/
  33. logo/
  34. media/
  35. metrics/
  36. net_sys/
  37. net_util/
  38. power_monitor/
  39. protos/
  40. qcow_utils/
  41. resources/
  42. rutabaga_gfx/
  43. seccomp/
  44. serde_keyvalue/
  45. src/
  46. system_api_stub/
  47. tests/
  48. third_party/
  49. tools/
  50. tpm2/
  51. tpm2-sys/
  52. tracing/
  53. tube_transporter/
  54. usb_sys/
  55. usb_util/
  56. vfio_sys/
  57. vhost/
  58. virtio_sys/
  59. vm_control/
  60. vm_memory/
  61. win_audio/
  62. win_util/
  63. x86_64/
  64. .dockerignore
  65. .gitignore
  66. .gitmodules
  67. .rustfmt.toml
  69. Cargo.toml
  73. OWNERS
  74. PRESUBMIT.cfg
  77. run_tests
  78. rust-toolchain
  80. test_all
  81. unblocked_terms.txt

crosvm - The Chrome OS Virtual Machine Monitor

crosvm is a virtual machine monitor (VMM) based on Linux’s KVM hypervisor, with a focus on simplicity, security, and speed. crosvm is intended to run Linux guests, originally as a security boundary for running native applications on the Chrome OS platform. Compared to QEMU, crosvm doesn’t emulate architectures or real hardware, instead concentrating on paravirtualized devices, such as the virtio standard.

crosvm is currently used to run Linux/Android guests on Chrome OS devices.