Skip to content

Commit

Permalink
Fixes for rust 1.81 (istio#1342)
Browse files Browse the repository at this point in the history
* Cleanup deadcode

Caught by new rust I think but not older one

* lints
  • Loading branch information
howardjohn authored Oct 11, 2024
1 parent 0245e84 commit dc17724
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
13 changes: 0 additions & 13 deletions src/proxy/socks5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,19 +398,6 @@ pub enum SocksError {
CommandNotSupported(Error),
}

impl SocksError {
pub fn into_inner(self) -> Error {
match self {
SocksError::General(e) => e,
SocksError::NotAllowed(e) => e,
SocksError::NetworkUnreachable(e) => e,
SocksError::HostUnreachable(e) => e,
SocksError::ConnectionRefused(e) => e,
SocksError::CommandNotSupported(e) => e,
}
}
}

impl SocksError {
pub fn invalid_protocol(reason: String) -> SocksError {
SocksError::CommandNotSupported(Error::Anyhow(anyhow::anyhow!(reason)))
Expand Down
29 changes: 27 additions & 2 deletions src/test_helpers/namespaced.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

use libc::getpid;
use nix::unistd::mkdtemp;
use std::fs;
use std::fs::File;
use std::path::PathBuf;
use std::{fs, io};

#[macro_export]
macro_rules! function {
Expand Down Expand Up @@ -116,5 +116,30 @@ pub fn initialize_namespace_tests() {
.expect("xtables bindmount");

let pid = unsafe { getpid() };
eprintln!("Starting test in {tmp:?}. Debug with `sudo nsenter --mount --net --setuid=0 --preserve-credentials --user -t {pid}`");

write_to_stderr(&format!("Starting test in {tmp:?}. Debug with `sudo nsenter --mount --net --setuid=0 --preserve-credentials --user -t {pid}`"))
.expect("write");
}

// write_to_stderr is a small helper to write a message to stderr.
// use of `std` in before-main code is not guaranteed to be legal, and does fail in Rust 1.81:
// https://users.rust-lang.org/t/ld-preload-with-init-array-fatal-runtime-error-thread-set-current-should-only-be-called-once-per-thread/117264/13
fn write_to_stderr(message: &str) -> io::Result<()> {
let c_str = std::ffi::CString::new(message)?;
let buf = c_str.as_bytes_with_nul();
let count = buf.len() as libc::size_t;

let result = unsafe {
libc::write(
libc::STDERR_FILENO,
buf.as_ptr() as *const std::ffi::c_void,
count,
) as libc::ssize_t
};

if result < 0 {
Err(io::Error::last_os_error())
} else {
Ok(())
}
}
5 changes: 1 addition & 4 deletions src/test_helpers/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ where
let mut buffer = [0; 512];
let mut read = 0;
let header = loop {
let n = match rw.read(&mut buffer[read..]).await {
Ok(n) => n,
_ => 0,
};
let n = rw.read(&mut buffer[read..]).await.unwrap_or_default();
read += n;
let header = HeaderResult::parse(&buffer[..read]);
if n == 0 || header.is_complete() || read >= 512 {
Expand Down

0 comments on commit dc17724

Please sign in to comment.