This API directly depends on Minijail, so it does not make sense for it
to be in the base crate that should be cross platform. Move it into the
jail crate, which already wraps other Linux-specific Minijail
functionality.
If we need to add a fork API that works on all unix platforms (including
non-Linux), that could be re-added in base, but for now, this is only
needed for Linux.
This removes the `base` crate's dependency on minijail, as well as the
special case test harness (which is moved to `jail` instead).
Change-Id: Iabefff03ab18222b71b82571bd815d5f028236c8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5556681
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
This cleans up the API and avoids the need for the caller to wrap each
descriptor in Some() first.
Change-Id: Iaf38a0882f2c9dbc39fb7b910abfa3fedf425f30
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5074591
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
On MacOS there is no MSG_NOSIGNAL, but there is SO_NOSIGPIPE which is
set as a socket option. This changes ScmSocket from a trait to a wrapper
type that can guarantee SO_NOSIGPIPE is set once on every relevant
socket before it is used in situations that can produce signals.
The biggest wrinkle is that setsockopt can produce errors, which makes
the conversion into ScmSocket a case that can possibly error. Not all
places that accept sockets were prepared to return errors.
Bug: b/309020556
Change-Id: I079bbaf8803e137ca7c0e0ebe60e63de5df59cc0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5021438
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
This is dead code and can be removed.
Change-Id: Ic6bee7b3a6fe59af117f7667ce4ff2a893cf9228
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5018778
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Every platform was re-exporting the non-platform-specific symbols
defined in descriptor_reflection.rs.
Change-Id: I95d0acdaaf8c157206ca788e4cdf64f15ebd2f84
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5001574
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
base::Pid is explicitly added since every platform has a process id
type.
Bug: 233233301
Test: tools/dev_container ./tools/presubmit
Change-Id: Id0d54fe06981c1dcbdee3f73b1241af74a26300f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909061
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Update the broker code to pass the logging arguments to child processes.
This also updates the base syslog LogConfig to separate out the
serializable logging arguments from the active logging configuration,
and also updates the LogConfig to no longer require generics when they
aren't used in practice.
Test: passed --log-level to run-mp, verified child processes logs
Change-Id: I98f046555610fa804df63b1e6ead3603e96f7666
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4967905
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Colin Downs-Razouk <colindr@google.com>
Updates are made to source and documentation.
This more accurately represents the currently supported platforms of
Android/Linux and Windows, without unexpectedly including other
unix-like operating systems.
Command to reproduce:
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -i 's/cfg(unix)/cfg(any(target_os = "android", target_os = "linux"))/g' {}
$ cargo fmt
md files manually updated to fix line lengths.
Renaming `unix` modules to `linux` will be done in a later CL.
Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I42c1bf0abf80b9a0df25551613910293217c7295
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909059
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
This test is unrelated to vm_control; it is testing base::Event and
base::Tube functionality, so move it next to the existing Tube tests.
The test module was also in the middle of the file for some reason,
which caused clippy warnings in Rust 1.71.
Change-Id: I52858e71df8aa3e092b3b7d12e1232454b61c4d4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4684827
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
These tests require initialization of the syslogger via
`openlog_and_get_socket` which requires no other threads in the
process to prevent conflicting file descriptors.
BUG=b:280331266
TEST=run_tests --dut=host
TEST=cargo test -p base --test syslog
TEST=cargo test -p base --lib
Change-Id: I3d83ecb80770d94914fc23b2d5760c7a54f6380f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4499660
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Avoid the possibility of tests reusing the same socket path by using a
known unique directory from tempfile::tempdir().
BUG=b:274145919
TEST=tools/dev_container tools/presubmit
Change-Id: I883e223617fb465cdfbff5a45509098487b62b3b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4348699
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
The SafeDescriptor type manages the lifetime of the file descriptor,
which simplifies the socket wrappers (each wrapper no longer needs to
manually implement Drop to close the descriptor, for example).
Also remove unneeded RawFd-related functions, replacing them with
RawDescriptor and SafeDescriptor equivalents.
BUG=None
TEST=tools/dev_container tools/presubmit
Change-Id: I634a19922ec24d06071b21247c79761cfc21a79a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4322266
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
forking a process with multiple threads will lead to
undefined behavior. Unfortunately, newer versions of
libtest will spawn multiple threads even when running
a with --test-threads=1.
This change implements a custom, test harness using
libtest-mimic. It mimics the libtest CLI but enforces
a single threaded test process.
BUG=b:270167741
BUG=b:268496046
TEST=tools/run_tests --dut=host
Change-Id: Icef6a1b65bab7f5cd5021c01fbd94487fa0ca5fb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4295157
Reviewed-by: George Burgess <gbiv@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
The Rust uprev breaks some assumptions these make. Sounds best from
discussion on the CL to temporarily disable them.
BUG=b:266817148, b:268496046
TEST=emerge-nocturne crosvm-base
Change-Id: If86eb23200b5af4be8221bacc42954b3dfc25aeb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4218895
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: George Burgess <gbiv@chromium.org>
A few more needless_borrow and needless_return warnings slipped in since
the last round of Rust 1.65 clippy fixes.
BUG=b:260784028
TEST=tools/clippy # with Rust 1.65
Change-Id: Iefceab6f1ec1c460e92b49f9cd21cfb79569f04a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4133516
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
These tests will use fork, which does not work in a multi-threaded
process. This is currently enforced by passing --test-threads 1 to
this test, but that won't work with cargo nextest.
To ensure that the test process is single-threaded, re-execute the
test binary as a child process.
BUG=b:261600801
TEST=presubmit
Change-Id: I1762ebbae66331895f84df9daa484468f1fe086d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4086902
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
The test needs to be run single threaded and is not suitable
to be a unit tests.
Integration tests are automatically run single threaded.
BUG=None
TEST=presubmit
Change-Id: Idd49af90c7c1858b28ba47a642a8a808319138c3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4018113
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
In non-privileged containers, comparing a file descriptor may not
work. So the test will not work in every runtime environment.
BUG=b:244623061
TEST=dev_container --podman --unprivileged tools/run_tests base:base
Change-Id: Ifa67e11db9694c36b47cd5ae88de9247284e1cdf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3999711
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
The extracted tests rely on access to system devices
or global state that prevent them from being run in parallel
or in restricted environments.
As an integration test they will be executed separately and
single threaded.
Updates the test runner to ensure integration tests are actually
run single threaded as intended.
BUG=b:244623061
TEST=./tools/run_tests base:\* --repeat 100 -p x86_64/mingw64/aarch64
Change-Id: I4267b9f79055208aca86796d902da251816bcada
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3971025
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>