diff --git a/Cargo.Bazel.lock b/Cargo.Bazel.lock index 74cd443d4..e8af389e1 100644 --- a/Cargo.Bazel.lock +++ b/Cargo.Bazel.lock @@ -1,5 +1,5 @@ { - "checksum": "fdcdf676d9bf2c46b288464c42c31a70f882f1339f47050290cd212d93893218", + "checksum": "b2310187ef1f7403122a658237ada76b63171f32fc13a2075dad28a0efae81fe", "crates": { "addr2line 0.20.0": { "name": "addr2line", @@ -672,7 +672,7 @@ "target": "log" }, { - "id": "nix 0.26.2", + "id": "nix 0.28.0", "target": "nix" }, { @@ -1337,6 +1337,44 @@ ], "license_file": "LICENSE-APACHE" }, + "cfg_aliases 0.1.1": { + "name": "cfg_aliases", + "version": "0.1.1", + "package_url": "https://github.com/katharostech/cfg_aliases", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/cfg_aliases/0.1.1/download", + "sha256": "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + } + }, + "targets": [ + { + "Library": { + "crate_name": "cfg_aliases", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "cfg_aliases", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "edition": "2018", + "version": "0.1.1" + }, + "license": "MIT", + "license_ids": [ + "MIT" + ], + "license_file": "LICENSE" + }, "clang-sys 1.6.1": { "name": "clang-sys", "version": "1.6.1", @@ -2027,7 +2065,7 @@ "target": "log" }, { - "id": "nix 0.26.2", + "id": "nix 0.28.0", "target": "nix" }, { @@ -4859,85 +4897,6 @@ ], "license_file": "LICENSE-MIT" }, - "memoffset 0.7.1": { - "name": "memoffset", - "version": "0.7.1", - "package_url": "https://github.com/Gilnaa/memoffset", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/memoffset/0.7.1/download", - "sha256": "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" - } - }, - "targets": [ - { - "Library": { - "crate_name": "memoffset", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": false, - "include": [ - "**/*.rs" - ] - } - } - }, - { - "BuildScript": { - "crate_name": "build_script_build", - "crate_root": "build.rs", - "srcs": { - "allow_empty": false, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "memoffset", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "crate_features": { - "common": [ - "default" - ], - "selects": {} - }, - "deps": { - "common": [ - { - "id": "memoffset 0.7.1", - "target": "build_script_build" - } - ], - "selects": {} - }, - "edition": "2015", - "version": "0.7.1" - }, - "build_script_attrs": { - "data_glob": [ - "**" - ], - "deps": { - "common": [ - { - "id": "autocfg 1.1.0", - "target": "autocfg" - } - ], - "selects": {} - } - }, - "license": "MIT", - "license_ids": [ - "MIT" - ], - "license_file": "LICENSE" - }, "minimal-lexical 0.2.1": { "name": "minimal-lexical", "version": "0.2.1", @@ -5105,14 +5064,14 @@ ], "license_file": "LICENSE" }, - "nix 0.26.2": { + "nix 0.28.0": { "name": "nix", - "version": "0.26.2", + "version": "0.28.0", "package_url": "https://github.com/nix-rust/nix", "repository": { "Http": { - "url": "https://static.crates.io/crates/nix/0.26.2/download", - "sha256": "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" + "url": "https://static.crates.io/crates/nix/0.28.0/download", + "sha256": "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" } }, "targets": [ @@ -5127,6 +5086,18 @@ ] } } + }, + { + "BuildScript": { + "crate_name": "build_script_build", + "crate_root": "build.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } } ], "library_target_name": "nix", @@ -5136,48 +5107,16 @@ ], "crate_features": { "common": [ - "acct", - "aio", "default", - "dir", - "env", - "event", - "feature", - "fs", - "hostname", - "inotify", - "ioctl", - "kmod", - "memoffset", - "mman", - "mount", - "mqueue", - "net", - "personality", - "pin-utils", - "poll", "process", - "pthread", - "ptrace", - "quota", - "reboot", - "resource", - "sched", - "signal", - "socket", - "term", - "time", - "ucontext", - "uio", - "user", - "zerocopy" + "resource" ], "selects": {} }, "deps": { "common": [ { - "id": "bitflags 1.3.2", + "id": "bitflags 2.4.0", "target": "bitflags" }, { @@ -5189,25 +5128,28 @@ "target": "libc" }, { - "id": "pin-utils 0.1.0", - "target": "pin_utils" - }, - { - "id": "static_assertions 1.1.0", - "target": "static_assertions" + "id": "nix 0.28.0", + "target": "build_script_build" } ], - "selects": { - "cfg(not(target_os = \"redox\"))": [ - { - "id": "memoffset 0.7.1", - "target": "memoffset" - } - ] - } + "selects": {} }, - "edition": "2018", - "version": "0.26.2" + "edition": "2021", + "version": "0.28.0" + }, + "build_script_attrs": { + "data_glob": [ + "**" + ], + "deps": { + "common": [ + { + "id": "cfg_aliases 0.1.1", + "target": "cfg_aliases" + } + ], + "selects": {} + } }, "license": "MIT", "license_ids": [ @@ -7637,45 +7579,6 @@ ], "license_file": "LICENSE-APACHE" }, - "static_assertions 1.1.0": { - "name": "static_assertions", - "version": "1.1.0", - "package_url": "https://github.com/nvzqz/static-assertions-rs", - "repository": { - "Http": { - "url": "https://static.crates.io/crates/static_assertions/1.1.0/download", - "sha256": "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - } - }, - "targets": [ - { - "Library": { - "crate_name": "static_assertions", - "crate_root": "src/lib.rs", - "srcs": { - "allow_empty": false, - "include": [ - "**/*.rs" - ] - } - } - } - ], - "library_target_name": "static_assertions", - "common_attrs": { - "compile_data_glob": [ - "**" - ], - "edition": "2015", - "version": "1.1.0" - }, - "license": "MIT OR Apache-2.0", - "license_ids": [ - "Apache-2.0", - "MIT" - ], - "license_file": "LICENSE-APACHE" - }, "strength_reduce 0.2.4": { "name": "strength_reduce", "version": "0.2.4", @@ -11239,42 +11142,6 @@ "x86_64-unknown-nixos-gnu", "x86_64-unknown-none" ], - "cfg(not(target_os = \"redox\"))": [ - "aarch64-apple-darwin", - "aarch64-apple-ios", - "aarch64-apple-ios-sim", - "aarch64-fuchsia", - "aarch64-linux-android", - "aarch64-pc-windows-msvc", - "aarch64-unknown-linux-gnu", - "aarch64-unknown-nixos-gnu", - "aarch64-unknown-nto-qnx710", - "arm-unknown-linux-gnueabi", - "armv7-linux-androideabi", - "armv7-unknown-linux-gnueabi", - "i686-apple-darwin", - "i686-linux-android", - "i686-pc-windows-msvc", - "i686-unknown-freebsd", - "i686-unknown-linux-gnu", - "powerpc-unknown-linux-gnu", - "riscv32imc-unknown-none-elf", - "riscv64gc-unknown-none-elf", - "s390x-unknown-linux-gnu", - "thumbv7em-none-eabi", - "thumbv8m.main-none-eabi", - "wasm32-unknown-unknown", - "wasm32-wasi", - "x86_64-apple-darwin", - "x86_64-apple-ios", - "x86_64-fuchsia", - "x86_64-linux-android", - "x86_64-pc-windows-msvc", - "x86_64-unknown-freebsd", - "x86_64-unknown-linux-gnu", - "x86_64-unknown-nixos-gnu", - "x86_64-unknown-none" - ], "cfg(not(windows))": [ "aarch64-apple-darwin", "aarch64-apple-ios", @@ -11471,7 +11338,7 @@ "itertools 0.11.0", "libc 0.2.153", "log 0.4.20", - "nix 0.26.2", + "nix 0.28.0", "once_cell 1.17.0", "openssl 0.10.62", "protobuf 3.2.0", diff --git a/Cargo.lock b/Cargo.lock index dae429831..c4ff8fd05 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -215,6 +215,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + [[package]] name = "clang-sys" version = "1.6.1" @@ -759,15 +765,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -796,16 +793,14 @@ dependencies = [ [[package]] name = "nix" -version = "0.26.2" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +checksum = "ab2156c4fce2f8df6c499cc1c763e4394b7482525bf2a9701c9d79d215f519e4" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.4.0", "cfg-if", + "cfg_aliases", "libc", - "memoffset", - "pin-utils", - "static_assertions", ] [[package]] @@ -1166,12 +1161,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "static_assertions" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" - [[package]] name = "strength_reduce" version = "0.2.4" diff --git a/audio_processor/Cargo.toml b/audio_processor/Cargo.toml index cfa5ed0eb..1e877f50f 100644 --- a/audio_processor/Cargo.toml +++ b/audio_processor/Cargo.toml @@ -17,7 +17,7 @@ clap = { version = "4.5.4", features = ["derive"] } dasp_sample = "0.11.0" hound = "3.4.0" libc = "0.2.124" -nix = "0.26.2" +nix = { version = "0.28.0", features = ["resource"] } serde = { version = "1.0.52", features = ["derive"]} serde_json = "1.0.96" thiserror = "1.0.30" diff --git a/cras/client/cras_tests/Cargo.toml b/cras/client/cras_tests/Cargo.toml index 33cc06f81..d49a5224e 100644 --- a/cras/client/cras_tests/Cargo.toml +++ b/cras/client/cras_tests/Cargo.toml @@ -14,7 +14,7 @@ either = "1.9.0" hound = "3.4.0" libchromeos = "*" libcras = "*" -nix = { version = "0.26", features = ["signal"] } +nix = { version = "0.28", features = ["signal"] } serde_json = "1.0.96" thiserror = "1.0.20" libc = "0.2" diff --git a/cras/client/cras_tests/src/audio.rs b/cras/client/cras_tests/src/audio.rs index 3f32a170c..d4a54d757 100644 --- a/cras/client/cras_tests/src/audio.rs +++ b/cras/client/cras_tests/src/audio.rs @@ -23,11 +23,15 @@ use either::Either; use hound::WavReader; use hound::WavSpec; use hound::WavWriter; -use libchromeos::signal::register_signal_handler; use libcras::BoxError; use libcras::CrasClient; use libcras::CrasNodeType; use libcras::CrasStreamEffect; +use nix::sys::signal::sigaction; +use nix::sys::signal::SaFlags; +use nix::sys::signal::SigAction; +use nix::sys::signal::SigHandler; +use nix::sys::signal::SigSet; use nix::sys::signal::Signal; use crate::arguments::AudioOptions; @@ -87,8 +91,19 @@ extern "C" fn sigint_handler(_: c_int) { } fn add_sigint_handler() -> Result<()> { - let result = unsafe { register_signal_handler(Signal::SIGINT, sigint_handler) }; - result.map_err(Error::SysUtil) + // SAFETY: sigint_handler only touches an AtomicBool. + unsafe { + sigaction( + Signal::SIGINT, + &SigAction::new( + SigHandler::Handler(sigint_handler), + SaFlags::SA_RESTART, + SigSet::empty(), + ), + ) + } + .map_err(Error::SysUtil)?; + Ok(()) } fn set_priority_to_realtime() { diff --git a/cras/client/libcras/Cargo.toml b/cras/client/libcras/Cargo.toml index ee4738ebf..481c105dd 100644 --- a/cras/client/libcras/Cargo.toml +++ b/cras/client/libcras/Cargo.toml @@ -17,6 +17,6 @@ futures = "*" libc = "*" libchromeos = "*" log = "0.4" -nix = { version = "0.26", features = ["socket"] } +nix = { version = "0.28", features = ["socket", "fs"] } serde = "1.0.125" tokio = { version = "1.19.2", features = ["rt", "net", "time"]} diff --git a/cras/client/libcras/src/cras_server_socket.rs b/cras/client/libcras/src/cras_server_socket.rs index dd2b9b063..ea8578410 100644 --- a/cras/client/libcras/src/cras_server_socket.rs +++ b/cras/client/libcras/src/cras_server_socket.rs @@ -3,8 +3,8 @@ // found in the LICENSE file. use std::io; use std::mem; +use std::os::fd::AsFd; use std::os::unix::io::AsRawFd; -use std::os::unix::io::FromRawFd; use std::os::unix::io::OwnedFd; use std::os::unix::io::RawFd; use std::path::PathBuf; @@ -68,14 +68,12 @@ impl CrasServerSocket { /// Returns the `io::Error` generated when connecting to the socket on failure. pub fn with_type(socket_type: CrasSocketType) -> io::Result { // SAFETY: Safe since OwnedFd is created from a newly created FD. - let fd = unsafe { - OwnedFd::from_raw_fd(socket::socket( - socket::AddressFamily::Unix, - socket::SockType::SeqPacket, - socket::SockFlag::empty(), - None, - )?) - }; + let fd = socket::socket( + socket::AddressFamily::Unix, + socket::SockType::SeqPacket, + socket::SockFlag::empty(), + None, + )?; let socket_path = PathBuf::from(socket_type.sock_path()); let addr = socket::UnixAddr::new(&socket_path)?; socket::connect(fd.as_raw_fd(), &addr)?; @@ -100,8 +98,7 @@ impl CrasServerSocket { fds: &[RawFd], ) -> io::Result { match fds.len() { - 0 => nix::unistd::write(self.socket.as_raw_fd(), message.as_slice()) - .map_err(|e| e.into()), + 0 => nix::unistd::write(self.socket.as_fd(), message.as_slice()).map_err(|e| e.into()), _ => { let ioslice = io::IoSlice::new(message.as_slice()); match self.send_with_fds(&[ioslice], fds) { diff --git a/cras/client/libcras/src/cras_shm.rs b/cras/client/libcras/src/cras_shm.rs index e75f61184..19b50b4df 100644 --- a/cras/client/libcras/src/cras_shm.rs +++ b/cras/client/libcras/src/cras_shm.rs @@ -942,7 +942,7 @@ impl CrasServerStateShmFd { mod tests { use std::ffi::CString; use std::fs::File; - use std::os::fd::FromRawFd; + use std::os::fd::AsFd; use std::os::unix::io::IntoRawFd; use std::sync::Arc; use std::sync::Mutex; @@ -955,11 +955,9 @@ mod tests { use super::*; fn create_shm(size: usize) -> File { - let fd: i32 = - memfd_create(&CString::new("cras").unwrap(), MemFdCreateFlag::empty()).unwrap(); - ftruncate(fd, size as i64).unwrap(); - // SAFETY: Safe since the fd is newly created and not owned yet. `File` will own the fd. - unsafe { File::from_raw_fd(fd) } + let fd = memfd_create(&CString::new("cras").unwrap(), MemFdCreateFlag::empty()).unwrap(); + ftruncate(fd.as_fd(), size as i64).unwrap(); + File::from(fd) } #[test] diff --git a/cras/client/libcras/src/libcras.rs b/cras/client/libcras/src/libcras.rs index 337612696..09479184d 100644 --- a/cras/client/libcras/src/libcras.rs +++ b/cras/client/libcras/src/libcras.rs @@ -705,10 +705,15 @@ impl<'a> CrasClient<'a> { enum Token { ServerMsg, } - let poll_ctx: PollContext = - PollContext::new().and_then(|pc| pc.add(socket, Token::ServerMsg).and(Ok(pc)))?; - - let events = poll_ctx.wait()?; + let poll_ctx: PollContext = PollContext::new() + .and_then(|pc| pc.add(socket, Token::ServerMsg).and(Ok(pc))) + // TODO: Resolve the incompatible nix::Error across dependencies. + .map_err(|e| nix::Error::from_raw(e as i32))?; + + let events = poll_ctx + .wait() + // TODO: Resolve the incompatible nix::Error across dependencies. + .map_err(|e| nix::Error::from_raw(e as i32))?; // Check the first readable message let tokens: Vec = events.iter_readable().map(|e| e.token()).collect(); tokens diff --git a/cras/common/Cargo.toml b/cras/common/Cargo.toml index 6f939d5e5..52287951d 100644 --- a/cras/common/Cargo.toml +++ b/cras/common/Cargo.toml @@ -10,7 +10,7 @@ getrandom = "0.2.7" itertools = "0.11.0" libc = "0.2.44" log = "0.4.17" -nix = "0.26.2" +nix = { version = "0.28.0", features = ["process"] } once_cell = "1.17.0" openssl = "0.10.48" serde_json = "1.0.64"