Edward O'Callaghan submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Edward O'Callaghan: Looks good to me, approved Peter Marheine: Looks good to me, but someone else must approve
CHROMIUM: flashrom_tester: Drop nix dependency

We can just use the libc functions directly. This is exactly what nix
does anyway.

BUG=none
TEST=unit tests
BRANCH=none

Original-Change-Id: I45c02f0c71d164bd8f504fe2b8d3acd54e0d5704
Original-Signed-off-by: Chirantan Ekbote <chirantan@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/flashrom/+/2560393
Original-Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
Original-Reviewed-by: Allen Webb <allenwebb@google.com>
Original-Commit-Queue: Allen Webb <allenwebb@google.com>
(cherry picked from commit 1ba7dbe83e01d270b6d8d597a079ea3bfeb2117e)
Change-Id: Iea61c65efb04da9cd0bc0bd85a34fc10912ea87b
Reviewed-on: https://review.coreboot.org/c/flashrom/+/52889
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Reviewed-by: Edward O'Callaghan <quasisec@chromium.org>
---
M util/flashrom_tester/Cargo.toml
M util/flashrom_tester/src/main.rs
2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/util/flashrom_tester/Cargo.toml b/util/flashrom_tester/Cargo.toml
index 0898d3c..e7a5820 100644
--- a/util/flashrom_tester/Cargo.toml
+++ b/util/flashrom_tester/Cargo.toml
@@ -18,8 +18,8 @@
chrono = { version = "0.4", optional = true }
clap = { version = "2.33", default-features = false, optional = true }
flashrom = { path = "flashrom/" }
+libc = "0.2"
log = { version = "0.4", features = ["std"] }
-nix = "0.14.1"
rand = "0.6.4"
serde_json = "1"
sys-info = "0.5.7"
diff --git a/util/flashrom_tester/src/main.rs b/util/flashrom_tester/src/main.rs
index e589ee1..80484d2 100644
--- a/util/flashrom_tester/src/main.rs
+++ b/util/flashrom_tester/src/main.rs
@@ -152,12 +152,11 @@
/// Once a signal is trapped, the default behavior is restored (terminating
/// the process) for future signals.
fn handle_sigint() -> &'static AtomicBool {
- use nix::libc::c_int;
- use nix::sys::signal::{self, SigHandler, Signal};
+ use libc::c_int;
use std::sync::atomic::Ordering;

unsafe {
- let _ = signal::signal(Signal::SIGINT, SigHandler::Handler(sigint_handler));
+ let _ = libc::signal(libc::SIGINT, sigint_handler as libc::sighandler_t);
}
static TERMINATE_FLAG: AtomicBool = AtomicBool::new(false);

@@ -169,10 +168,17 @@
test, or press ^C again to exit immediately (possibly bricking your machine).
";

- // Use raw write() because signal-safety is a very hard problem
- let _ = nix::unistd::write(STDERR_FILENO, MESSAGE);
+ // Use raw write() because signal-safety is a very hard problem. Safe because this doesn't
+ // modify any memory.
+ let _ = unsafe {
+ libc::write(
+ STDERR_FILENO,
+ MESSAGE.as_ptr() as *const libc::c_void,
+ MESSAGE.len() as libc::size_t,
+ )
+ };
unsafe {
- let _ = signal::signal(Signal::SIGINT, SigHandler::SigDfl);
+ let _ = libc::signal(libc::SIGINT, libc::SIG_DFL);
}
TERMINATE_FLAG.store(true, Ordering::Release);
}

To view, visit change 52889. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: Iea61c65efb04da9cd0bc0bd85a34fc10912ea87b
Gerrit-Change-Number: 52889
Gerrit-PatchSet: 2
Gerrit-Owner: Daniel Campello <campello@chromium.org>
Gerrit-Reviewer: Edward O'Callaghan <quasisec@chromium.org>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Paul Menzel <paulepanter@mailbox.org>
Gerrit-MessageType: merged