Skip to content

Commit

Permalink
Add GNU/Hurd support
Browse files Browse the repository at this point in the history
  • Loading branch information
sthibaul committed Jul 10, 2024
1 parent 1ce1545 commit 0b50fa3
Show file tree
Hide file tree
Showing 15 changed files with 128 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ jobs:
- arm64_32-apple-watchos
- armv7-sony-vita-newlibeabihf
- i686-unknown-linux-gnu
- i686-unknown-hurd-gnu
- riscv32imc-esp-espidf
- sparcv9-sun-solaris
- wasm32-wasi
Expand Down
4 changes: 4 additions & 0 deletions src/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
target_os = "fuchsia",
target_os = "haiku",
target_os = "hermit",
target_os = "hurd",
target_os = "nto",
target_os = "solaris",
target_os = "vita"
Expand Down Expand Up @@ -443,6 +444,7 @@ impl Poll {
target_os = "fuchsia",
target_os = "haiku",
target_os = "hermit",
target_os = "hurd",
target_os = "nto",
target_os = "solaris",
target_os = "vita"
Expand Down Expand Up @@ -742,6 +744,7 @@ impl fmt::Debug for Registry {
target_os = "haiku",
target_os = "fuchsia",
target_os = "hermit",
target_os = "hurd",
target_os = "nto",
target_os = "solaris",
target_os = "vita"
Expand All @@ -760,6 +763,7 @@ cfg_os_poll! {
not(any(
target_os = "espidf",
target_os = "hermit",
target_os = "hurd",
target_os = "nto",
target_os = "solaris",
target_os = "vita"
Expand Down
3 changes: 3 additions & 0 deletions src/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cfg_os_poll! {
target_os = "fuchsia",
target_os = "haiku",
target_os = "hermit",
target_os = "hurd",
target_os = "nto",
target_os = "solaris",
target_os = "vita",
Expand Down Expand Up @@ -92,6 +93,7 @@ cfg_os_poll! {
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "hurd",
target_os = "netbsd",
target_os = "nto",
target_os = "openbsd",
Expand Down Expand Up @@ -138,6 +140,7 @@ cfg_os_poll! {
target_os = "aix",
target_os = "dragonfly",
target_os = "haiku",
target_os = "hurd",
target_os = "netbsd",
target_os = "nto",
target_os = "openbsd",
Expand Down
3 changes: 3 additions & 0 deletions src/sys/unix/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) fn new_socket(domain: libc::c_int, socket_type: libc::c_int) -> io::R
target_os = "android",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "hurd",
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
Expand Down Expand Up @@ -116,6 +117,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "hurd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand Down Expand Up @@ -151,6 +153,7 @@ pub(crate) fn socket_addr(addr: &SocketAddr) -> (SocketAddrCRepr, libc::socklen_
target_os = "dragonfly",
target_os = "freebsd",
target_os = "haiku",
target_os = "hurd",
target_os = "ios",
target_os = "macos",
target_os = "netbsd",
Expand Down
1 change: 1 addition & 0 deletions src/sys/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) fn new_raw() -> io::Result<[RawFd; 2]> {
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "linux",
target_os = "netbsd",
target_os = "openbsd",
Expand Down
1 change: 1 addition & 0 deletions src/sys/unix/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ pub(crate) fn accept(listener: &net::TcpListener) -> io::Result<(net::TcpStream,
target_os = "dragonfly",
target_os = "freebsd",
target_os = "fuchsia",
target_os = "hurd",
target_os = "illumos",
target_os = "linux",
target_os = "netbsd",
Expand Down
2 changes: 2 additions & 0 deletions tests/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ fn drop_cancels_interest_and_shuts_down() {

let handle = thread::spawn(move || {
let mut stream = listener.incoming().next().unwrap().unwrap();
// SO_RCVTIMEO not supported on GNU/Hurd
#[cfg(not(target_os = "hurd"))]
stream
.set_read_timeout(Some(Duration::from_secs(5)))
.expect("set_read_timeout");
Expand Down
2 changes: 2 additions & 0 deletions tests/regressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ fn issue_776() {

let handle = thread::spawn(move || {
let mut stream = listener.accept().expect("accept").0;
// SO_RCVTIMEO not supported on GNU/Hurd
#[cfg(not(target_os = "hurd"))]
stream
.set_read_timeout(Some(Duration::from_secs(5)))
.expect("set_read_timeout");
Expand Down
10 changes: 8 additions & 2 deletions tests/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,9 @@ fn connect_error() {

for event in &events {
if event.token() == Token(0) {
assert!(event.is_writable());
// With fastopen we would be able to write
// Without fastopen we would be getting the connection error
assert!(event.is_writable() || event.is_error());
// Solaris poll(2) says POLLHUP and POLLOUT are mutually exclusive.
#[cfg(not(target_os = "solaris"))]
assert!(event.is_write_closed());
Expand Down Expand Up @@ -702,7 +704,11 @@ fn write_shutdown() {
socket.shutdown(Shutdown::Write).unwrap();

// POLLRDHUP isn't supported on Solaris,
if cfg!(any(target_os = "solaris", target_os = "nto")) {
if cfg!(any(
target_os = "hurd",
target_os = "solaris",
target_os = "nto"
)) {
wait!(poll, is_readable, false);
} else {
wait!(poll, is_readable, true);
Expand Down
6 changes: 5 additions & 1 deletion tests/tcp_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ fn no_events_after_deregister() {
windows,
ignore = "fails on Windows; client read closed events are not triggered"
)]
#[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn tcp_shutdown_client_read_close_event() {
Expand Down Expand Up @@ -553,6 +554,7 @@ fn tcp_shutdown_client_read_close_event() {
#[cfg_attr(
any(
target_os = "android",
target_os = "hurd",
target_os = "illumos",
target_os = "solaris",
target_os = "linux",
Expand Down Expand Up @@ -591,6 +593,7 @@ fn tcp_shutdown_client_write_close_event() {
}

#[test]
#[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn tcp_shutdown_server_write_close_event() {
Expand Down Expand Up @@ -623,6 +626,7 @@ fn tcp_shutdown_server_write_close_event() {
}

#[test]
#[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn tcp_reset_close_event() {
Expand Down Expand Up @@ -673,7 +677,7 @@ fn tcp_reset_close_event() {
ignore = "fails on Windows; client close events are not found"
)]
#[cfg_attr(
any(target_os = "illumos", target_os = "solaris"),
any(target_os = "hurd", target_os = "illumos", target_os = "solaris"),
ignore = "fails; client write_closed events are not found"
)]
fn tcp_shutdown_client_both_close_event() {
Expand Down
26 changes: 22 additions & 4 deletions tests/udp_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ fn get_multicast_ttl_v4_without_previous_set() {
}

#[test]
#[cfg_attr(
target_os = "hurd",
ignore = "Multicast loop v6 isn't supported on GNU/Hurd"
)]
fn set_get_multicast_loop_v6() {
let socket1 = UdpSocket::bind(any_local_ipv6_address()).unwrap();

Expand All @@ -267,6 +271,10 @@ fn set_get_multicast_loop_v6() {
}

#[test]
#[cfg_attr(
target_os = "hurd",
ignore = "Multicast loop v6 isn't supported on GNU/Hurd"
)]
fn get_multicast_loop_v6_without_previous_set() {
let socket1 = UdpSocket::bind(any_local_ipv6_address()).unwrap();

Expand Down Expand Up @@ -553,7 +561,7 @@ fn unconnected_udp_socket_connected_methods() {
);

// Socket is unconnected, but we're using an connected method.
if cfg!(not(target_os = "windows")) {
if cfg!(not(any(target_os = "hurd", target_os = "windows"))) {
assert_error(socket1.send(DATA1), "address required");
}
if cfg!(target_os = "windows") {
Expand Down Expand Up @@ -616,12 +624,22 @@ fn connected_udp_socket_unconnected_methods() {
);

// Can't use `send_to`.
// Linux (and Android) and Windows actually allow `send_to` even if the
// Linux (and Android) and GNU/Hurd Windows actually allow `send_to` even if the
// socket is connected.
#[cfg(not(any(target_os = "android", target_os = "linux", target_os = "windows")))]
#[cfg(not(any(
target_os = "android",
target_os = "hurd",
target_os = "linux",
target_os = "windows"
)))]
assert_error(socket1.send_to(DATA1, address2), "already connected");
// Even if the address is the same.
#[cfg(not(any(target_os = "android", target_os = "linux", target_os = "windows")))]
#[cfg(not(any(
target_os = "android",
target_os = "hurd",
target_os = "linux",
target_os = "windows"
)))]
assert_error(socket1.send_to(DATA1, address3), "already connected");

checked_write!(socket2.send_to(DATA2, address3));
Expand Down
42 changes: 30 additions & 12 deletions tests/unix_datagram.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ fn is_send_and_sync() {
}

#[test]
#[cfg_attr(
target_os = "hurd",
ignore = "getting pathname isn't supported on GNU/Hurd"
)]
fn unix_datagram_smoke_unconnected() {
init();
let path1 = temp_file("unix_datagram_smoke_unconnected1");
Expand All @@ -52,6 +56,10 @@ fn unix_datagram_smoke_connected() {
}

#[test]
#[cfg_attr(
target_os = "hurd",
ignore = "getting pathname isn't supported on GNU/Hurd"
)]
fn unix_datagram_smoke_unconnected_from_std() {
init();
let path1 = temp_file("unix_datagram_smoke_unconnected_from_std1");
Expand Down Expand Up @@ -89,6 +97,10 @@ fn unix_datagram_smoke_connected_from_std() {
}

#[test]
#[cfg_attr(
target_os = "hurd",
ignore = "getting pathname isn't supported on GNU/Hurd"
)]
fn unix_datagram_connect() {
init();
let path1 = temp_file("unix_datagram_connect1");
Expand Down Expand Up @@ -166,6 +178,7 @@ fn unix_datagram_pair() {
}

#[test]
#[cfg_attr(target_os = "hurd", ignore = "POLLRDHUP isn't supported on GNU/Hurd")]
#[cfg_attr(target_os = "solaris", ignore = "POLLRDHUP isn't supported on Solaris")]
#[cfg_attr(target_os = "nto", ignore = "POLLRDHUP isn't supported on NTO")]
fn unix_datagram_shutdown() {
Expand Down Expand Up @@ -285,6 +298,7 @@ fn smoke_test_unconnected(mut datagram1: UnixDatagram, mut datagram2: UnixDatagr
assert_socket_non_blocking(&datagram2);
assert_socket_close_on_exec(&datagram2);

// "getting pathname isn't supported on GNU/Hurd")]
let addr1 = datagram1.local_addr().unwrap();
let addr2 = datagram2.local_addr().unwrap();
let path1 = addr1.as_pathname().expect("failed to get pathname");
Expand Down Expand Up @@ -343,18 +357,22 @@ fn smoke_test_connected(mut datagram1: UnixDatagram, mut datagram2: UnixDatagram
assert_socket_non_blocking(&datagram2);
assert_socket_close_on_exec(&datagram2);

let local_addr1 = datagram1.local_addr().unwrap();
let peer_addr1 = datagram1.peer_addr().unwrap();
let local_addr2 = datagram2.local_addr().unwrap();
let peer_addr2 = datagram2.peer_addr().unwrap();
assert_eq!(
local_addr1.as_pathname().expect("failed to get pathname"),
peer_addr2.as_pathname().expect("failed to get pathname")
);
assert_eq!(
local_addr2.as_pathname().expect("failed to get pathname"),
peer_addr1.as_pathname().expect("failed to get pathname")
);
// "getting pathname isn't supported on GNU/Hurd")]
#[cfg(not(target_os = "hurd"))]
{
let local_addr1 = datagram1.local_addr().unwrap();
let peer_addr1 = datagram1.peer_addr().unwrap();
let local_addr2 = datagram2.local_addr().unwrap();
let peer_addr2 = datagram2.peer_addr().unwrap();
assert_eq!(
local_addr1.as_pathname().expect("failed to get pathname"),
peer_addr2.as_pathname().expect("failed to get pathname")
);
assert_eq!(
local_addr2.as_pathname().expect("failed to get pathname"),
peer_addr1.as_pathname().expect("failed to get pathname")
);
}

poll.registry()
.register(
Expand Down
2 changes: 2 additions & 0 deletions tests/unix_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ fn unix_listener_local_addr() {
);

let (stream, expected_addr) = listener.accept().unwrap();
// getting pathname isn't supported on GNU/Hurd
#[cfg(not(target_os = "hurd"))]
assert_eq!(stream.local_addr().unwrap().as_pathname().unwrap(), &path);
assert!(expected_addr.as_pathname().is_none());

Expand Down
12 changes: 6 additions & 6 deletions tests/unix_pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ fn smoke() {

#[test]
#[cfg_attr(
target_os = "nto",
ignore = "Writer fd close events do not trigger POLLHUP on nto target"
any(target_os = "hurd", target_os = "nto"),
ignore = "Writer fd close events do not trigger POLLHUP on nto and GNU/Hurd targets"
)]
fn event_when_sender_is_dropped() {
let mut poll = Poll::new().unwrap();
Expand Down Expand Up @@ -96,8 +96,8 @@ fn event_when_sender_is_dropped() {

#[test]
#[cfg_attr(
target_os = "nto",
ignore = "Read fd close events do not trigger POLLHUP on nto target"
any(target_os = "hurd", target_os = "nto"),
ignore = "Writer fd close events do not trigger POLLHUP on nto and GNU/Hurd targets"
)]
fn event_when_receiver_is_dropped() {
let mut poll = Poll::new().unwrap();
Expand Down Expand Up @@ -133,8 +133,8 @@ fn event_when_receiver_is_dropped() {

#[test]
#[cfg_attr(
target_os = "nto",
ignore = "Read/Write close eventsdo not trigger POLLHUP on nto target"
any(target_os = "hurd", target_os = "nto"),
ignore = "Writer fd close events do not trigger POLLHUP on nto and GNU/Hurd targets"
)]
fn from_child_process_io() {
// `cat` simply echo everything that we write via standard in.
Expand Down
Loading

0 comments on commit 0b50fa3

Please sign in to comment.