Skip to content

Commit f10d0ba

Browse files
committed
Port to OpenBSD
Updates the libc version for the required constants and symbols for OpenBSD.
1 parent d882b3a commit f10d0ba

File tree

4 files changed

+22
-7
lines changed

4 files changed

+22
-7
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ default = []
2020
nightly = []
2121

2222
[dependencies]
23-
libc = { version = "0.2.179", default-features = false }
23+
libc = { version = "0.2.181", default-features = false }
2424
log = { version = "0.4.21", default-features = false, features = ["kv_std"] }
2525

2626
[dev-dependencies]

src/kqueue/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl_fd_op!(TruncateOp);
276276
pub(crate) use libc::stat as Stat;
277277

278278
pub(crate) const fn file_type(stat: &Stat) -> FileType {
279-
FileType(stat.st_mode)
279+
FileType(stat.st_mode as u16)
280280
}
281281

282282
pub(crate) const fn len(stat: &Stat) -> u64 {
@@ -288,7 +288,7 @@ pub(crate) const fn block_size(stat: &Stat) -> u32 {
288288
}
289289

290290
pub(crate) const fn permissions(stat: &Stat) -> Permissions {
291-
Permissions(stat.st_mode)
291+
Permissions(stat.st_mode as u16)
292292
}
293293

294294
pub(crate) fn modified(stat: &Stat) -> SystemTime {

src/kqueue/process.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,11 @@ impl crate::op::Op for WaitIdOp {
5656
let options = options.0.cast_signed() | libc::WNOHANG; // Don't block.
5757
syscall!(waitid(id_type, pid.into(), &raw mut info.0, options))?;
5858

59-
if info.0.si_pid == 0 {
59+
#[cfg(not(target_os = "openbsd"))]
60+
let pid = info.0.si_pid;
61+
#[cfg(any(target_os = "openbsd"))]
62+
let pid = unsafe { info.0.si_pid() };
63+
if pid == 0 {
6064
// Got polled without the process stopping, will have to
6165
// wait again.
6266
Poll::Pending
@@ -134,7 +138,7 @@ fn sigaction(signals: &SignalSet, action: libc::sighandler_t) -> io::Result<()>
134138
target_os = "watchos",
135139
))]
136140
let sa_mask = 0;
137-
#[cfg(target_os = "freebsd")]
141+
#[cfg(any(target_os = "freebsd", target_os = "openbsd"))]
138142
let sa_mask = SignalSet::empty()?.0;
139143

140144
let action = libc::sigaction {

src/net.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ new_flag!(
5151
#[cfg(any(target_os = "android", target_os = "linux"))]
5252
PACKET = libc::AF_PACKET,
5353
/// Domain for low-level VSOCK interface.
54-
#[cfg(not(target_os = "freebsd"))]
54+
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd")))]
5555
VSOCK = libc::AF_VSOCK,
5656
}
5757

@@ -95,6 +95,7 @@ new_flag!(
9595
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
9696
DCCP = libc::IPPROTO_DCCP,
9797
/// Stream Control Transport Protocol.
98+
#[cfg(not(target_os = "openbsd"))]
9899
SCTP = libc::IPPROTO_SCTP,
99100
/// UDP-Lite.
100101
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
@@ -628,17 +629,20 @@ new_flag!(
628629
ADD_MEMBERSHIP = libc::IP_ADD_MEMBERSHIP,
629630
/// Join a multicast group and allow receiving data only from a
630631
/// specified source.
632+
#[cfg(not(target_os = "openbsd"))]
631633
ADD_SOURCE_MEMBERSHIP = libc::IP_ADD_SOURCE_MEMBERSHIP,
632634
/// Do not reserve an ephemeral port when using `bind(2)` with a port
633635
/// number of 0.
634636
#[cfg(any(target_os = "android", target_os = "linux"))]
635637
BIND_ADDRESS_NO_PORT = libc::IP_BIND_ADDRESS_NO_PORT,
636638
/// Stop receiving multicast data from a specific source in a given
637639
/// group.
640+
#[cfg(not(target_os = "openbsd"))]
638641
BLOCK_SOURCE = libc::IP_BLOCK_SOURCE,
639642
/// Leave a multicast group.
640643
DROP_MEMBERSHIP = libc::IP_DROP_MEMBERSHIP,
641644
/// Leave a source-specific group.
645+
#[cfg(not(target_os = "openbsd"))]
642646
DROP_SOURCE_MEMBERSHIP = libc::IP_DROP_SOURCE_MEMBERSHIP,
643647
/// Allow binding to an IP address that is nonlocal or does not (yet)
644648
/// exist.
@@ -679,7 +683,7 @@ new_flag!(
679683
#[cfg(any(target_os = "android", target_os = "linux"))]
680684
PASS_SEC = libc::IP_PASSSEC,
681685
/// Collect information about this socket.
682-
#[cfg(not(target_os = "freebsd"))]
686+
#[cfg(not(any(target_os = "freebsd", target_os = "openbsd")))]
683687
PKT_INFO = libc::IP_PKTINFO,
684688
/// Enable extended reliable error message passing.
685689
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -693,9 +697,11 @@ new_flag!(
693697
RECV_ORIG_DST_ADDR = libc::IP_RECVORIGDSTADDR,
694698
/// Enable passing of `IP_TOS` in ancillary message with incoming
695699
/// packets.
700+
#[cfg(not(target_os = "openbsd"))]
696701
RECV_TOS = libc::IP_RECVTOS,
697702
/// Enable passing of `IP_TTL` in ancillary message with incoming
698703
/// packets.
704+
#[cfg(not(target_os = "openbsd"))]
699705
RECV_TTL = libc::IP_RECVTTL,
700706
/// Identical to [`IPv4Opt::RECV_OPTS`], but returns raw unprocessed
701707
/// options with timestamp and route record options not filled in for
@@ -716,6 +722,7 @@ new_flag!(
716722
/// this socket.
717723
TTL = libc::IP_TTL,
718724
/// Unblock previously blocked multicast source.
725+
#[cfg(not(target_os = "openbsd"))]
719726
UNBLOCK_SOURCE = libc::IP_UNBLOCK_SOURCE,
720727
}
721728

@@ -765,6 +772,7 @@ new_flag!(
765772
#[cfg(any(target_os = "android", target_os = "linux"))]
766773
FLOW_INFO = libc::IPV6_FLOWINFO,
767774
/// Set hop limit.
775+
#[cfg(not(target_os = "openbsd"))]
768776
HOP_LIMIT = libc::IPV6_HOPLIMIT,
769777
/// Control receiving of asynchronous error options.
770778
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -799,12 +807,14 @@ new_flag!(
799807
INFO = libc::TCP_INFO,
800808
/// The maximum number of keepalive probes TCP should send before
801809
/// dropping the connection.
810+
#[cfg(not(target_os = "openbsd"))]
802811
KEEP_CNT = libc::TCP_KEEPCNT,
803812
/// The time (in seconds) the connection needs to remain idle before TCP
804813
/// starts sending keepalive probes.
805814
#[cfg(any(target_os = "android", target_os = "freebsd", target_os = "linux"))]
806815
KEEP_IDLE = libc::TCP_KEEPIDLE,
807816
/// The time (in seconds) between individual keepalive probes.
817+
#[cfg(not(target_os = "openbsd"))]
808818
KEEP_INTVL = libc::TCP_KEEPINTVL,
809819
/// The lifetime of orphaned FIN_WAIT2 state sockets.
810820
#[cfg(any(target_os = "android", target_os = "linux"))]
@@ -829,6 +839,7 @@ new_flag!(
829839
#[cfg(any(target_os = "android", target_os = "linux"))]
830840
WINDOW_CLAMP = libc::TCP_WINDOW_CLAMP,
831841
/// This option enables Fast Open on the listener socket.
842+
#[cfg(not(target_os = "openbsd"))]
832843
FASTOPEN = libc::TCP_FASTOPEN,
833844
/// This option enables an alternative way to perform Fast Open on the
834845
/// client side.

0 commit comments

Comments
 (0)