Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nix on FreeBSD #396

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ addons:
- binutils-dev

rust:
- 1.1.0 # Oldest supported version
- 1.2.0 # Oldest supported version
- 1.7.0
- 1.8.0
- stable
Expand Down Expand Up @@ -50,10 +50,10 @@ matrix:
rust: stable
- os: osx
env: ARCH=x86_64
rust: 1.1.0
rust: 1.2.0
- os: osx
env: ARCH=i686
rust: 1.1.0
rust: 1.2.0
# Docker builds for other targets
- os: linux
env: TARGET=aarch64-unknown-linux-gnu DOCKER_IMAGE=posborne/rust-cross:arm
Expand Down
90 changes: 90 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Change Log

All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- Added `lseek` and `lseek64` in `::nix::unistd`
([#377](https://github.com/nix-rust/nix/pull/377))
- Added accessors `sigmask_mut` and `sigmask` to `UContext` in
`::nix::ucontext`.
([#370](https://github.com/nix-rust/nix/pull/370))
- Added `WUNTRACED` to `WaitPidFlag` in `::nix::sys::wait` for non-_linux_
targets.
([#379](https://github.com/nix-rust/nix/pull/379))
- Added new module `::nix::sys::reboot` with enumeration `RebootMode` and
functions `reboot` and `set_cad_enabled`. Currently for _linux_ only.
([#386](https://github.com/nix-rust/nix/pull/386))

### Changed
- Replaced the reexported integer constants for signals by the enumeration
`Signal` in `::nix::sys::signal`.
([#362](https://github.com/nix-rust/nix/pull/362))
- Renamed `EventFdFlag` to `EfdFlags` in `::nix::sys::eventfd`.
([#383](https://github.com/nix-rust/nix/pull/383))

### Removed
- Type alias `SigNum` from `::nix::sys::signal`.
([#362](https://github.com/nix-rust/nix/pull/362))

### Fixed
- Fixed the build problem for NetBSD (Note, that we currently do not support
it, so it might already be broken again).
([#389](https://github.com/nix-rust/nix/pull/389))

## [0.6.0] 2016-06-10

### Added
- Added `gettid` in `::nix::unistd` for _linux_ and _android_.
([#293](https://github.com/nix-rust/nix/pull/293))
- Some _mips_ support in `::nix::sched` and `::nix::sys::syscall`.
([#301](https://github.com/nix-rust/nix/pull/301))
- Added `SIGNALFD_SIGINFO_SIZE` in `::nix::sys::signalfd`.
([#309](https://github.com/nix-rust/nix/pull/309))
- Added new module `::nix::ucontext` with struct `UContext`. Currently for
_linux_ only.
([#311](https://github.com/nix-rust/nix/pull/311))
- Added `EPOLLEXCLUSIVE` to `EpollEventKind` in `::nix::sys::epoll`.
([#330](https://github.com/nix-rust/nix/pull/330))
- Added `pause` to `::nix::unistd`.
([#336](https://github.com/nix-rust/nix/pull/336))
- Added `sleep` to `::nix::unistd`.
([#351](https://github.com/nix-rust/nix/pull/351))
- Added `S_IFDIR`, `S_IFLNK`, `S_IFMT` to `SFlag` in `::nix::sys::stat`.
([#359](https://github.com/nix-rust/nix/pull/359))
- Added `clear` and `extend` functions to `SigSet`'s implementation in
`::nix::sys::signal`.
([#347](https://github.com/nix-rust/nix/pull/347))
- `sockaddr_storage_to_addr` in `::nix::sys::socket` now supports `sockaddr_nl`
on _linux_ and _android_.
([#366](https://github.com/nix-rust/nix/pull/366))
- Added support for `SO_ORIGINAL_DST` in `::nix::sys::socket` on _linux_.
([#367](https://github.com/nix-rust/nix/pull/367))
- Added `SIGINFO` in `::nix::sys::signal` for the _macos_ target as well as
`SIGPWR` and `SIGSTKFLT` in `::nix::sys::signal` for non-_macos_ targets.
([#361](https://github.com/nix-rust/nix/pull/361))

### Changed
- Changed the structure `IoVec` in `::nix::sys::uio`.
([#304](https://github.com/nix-rust/nix/pull/304))
- Replaced `CREATE_NEW_FD` by `SIGNALFD_NEW` in `::nix::sys::signalfd`.
([#309](https://github.com/nix-rust/nix/pull/309))
- Renamed `SaFlag` to `SaFlags` and `SigFlag` to `SigFlags` in
`::nix::sys::signal`.
([#314](https://github.com/nix-rust/nix/pull/314))
- Renamed `Fork` to `ForkResult` and changed its fields in `::nix::unistd`.
([#332](https://github.com/nix-rust/nix/pull/332))
- Added the `signal` parameter to `clone`'s signature in `::nix::sched`.
([#344](https://github.com/nix-rust/nix/pull/344))
- `execv`, `execve`, and `execvp` now return `Result<Void>` instead of
`Result<()>` in `::nix::unistd`.
([#357](https://github.com/nix-rust/nix/pull/357))

### Fixed
- Improved the conversion from `std::net::SocketAddr` to `InetAddr` in
`::nix::sys::socket::addr`.
([#335](https://github.com/nix-rust/nix/pull/335))

## [0.5.0] 2016-03-01
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ pull' model described there.

Please make pull requests against the `master` branch.

[pr-docs]: https://help.github.com/articles/using-pull-requests/
If you change the API by way of adding, removing or changing something or if
you fix a bug, please add an appropriate note to the [change log][cl]. We
follow the conventions of [Keep A CHANGELOG][kacl].

[cl]: https://github.com/nix-rust/nix/blob/master/CHANGELOG.md
[kacl]: https://github.com/olivierlacan/keep-a-changelog/tree/18adb5f5be7a898d046f6a4acb93e39dcf40c4ad
[pr-docs]: https://help.github.com/articles/using-pull-requests/

## Testing

Expand Down
5 changes: 5 additions & 0 deletions CONVENTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ conventions we try to follow have been documented here. If you find an instance
of either, feel free to remedy the flaw by opening a pull request with
appropriate changes or additions.

## Change Log

We follow the conventions laid out in [Keep A CHANGELOG][kacl].

[kacl]: https://github.com/olivierlacan/keep-a-changelog/tree/18adb5f5be7a898d046f6a4acb93e39dcf40c4ad

## libc constants, functions and structs

Expand Down
18 changes: 18 additions & 0 deletions RELEASE_PROCEDURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
This document lists the steps that lead to a successful release of the Nix
library.

# Before Release

The release is prepared by a commit with the following changes.

- In CHANGELOG.md, rename the Unreleased section to the new version followed by
the date of the release.

# Create Release

# After Release

After the release a commit with the following changes is added to the master
branch.

- Add a new Unreleased section header to CHANGELOG.md.
2 changes: 1 addition & 1 deletion src/sys/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ pub fn ev_set(ev: &mut KEvent,
filter: EventFilter,
flags: EventFlag,
fflags: FilterFlag,
udata: i64) {
udata: isize) {

ev.ident = ident as uintptr_t;
ev.filter = filter;
Expand Down
2 changes: 1 addition & 1 deletion src/sys/mman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod consts {
const MAP_RENAME = libc::MAP_RENAME,
const MAP_NORESERVE = libc::MAP_NORESERVE,
const MAP_HASSEMAPHORE = libc::MAP_HASSEMAPHORE,
#[cfg(not(target_os = "openbsd"))]
#[cfg(not(any(target_os = "openbsd", target_os = "netbsd")))]
const MAP_STACK = libc::MAP_STACK,
#[cfg(target_os = "netbsd")]
const MAP_WIRED = libc::MAP_WIRED,
Expand Down
3 changes: 3 additions & 0 deletions src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub mod stat;
#[cfg(any(target_os = "linux", target_os = "android"))]
pub mod syscall;

#[cfg(any(target_os = "linux"))]
pub mod reboot;

#[cfg(not(target_os = "ios"))]
pub mod termios;

Expand Down
43 changes: 43 additions & 0 deletions src/sys/reboot.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Reboot/shutdown or enable/disable Ctrl-Alt-Delete.

use {Errno, Error, Result};
use libc;
use void::Void;
use std::mem::drop;

/// How exactly should the system be rebooted.
///
/// See [`set_cad_enabled()`](fn.set_cad_enabled.html) for
/// enabling/disabling Ctrl-Alt-Delete.
#[repr(i32)]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum RebootMode {
RB_HALT_SYSTEM = libc::RB_HALT_SYSTEM,
RB_KEXEC = libc::RB_KEXEC,
RB_POWER_OFF = libc::RB_POWER_OFF,
RB_AUTOBOOT = libc::RB_AUTOBOOT,
// we do not support Restart2,
RB_SW_SUSPEND = libc::RB_SW_SUSPEND,
}

pub fn reboot(how: RebootMode) -> Result<Void> {
unsafe {
libc::reboot(how as libc::c_int)
};
Err(Error::Sys(Errno::last()))
}

/// Enable or disable the reboot keystroke (Ctrl-Alt-Delete).
///
/// Corresponds to calling `reboot(RB_ENABLE_CAD)` or `reboot(RB_DISABLE_CAD)` in C.
pub fn set_cad_enabled(enable: bool) -> Result<()> {
let cmd = if enable {
libc::RB_ENABLE_CAD
} else {
libc::RB_DISABLE_CAD
};
let res = unsafe {
libc::reboot(cmd)
};
Errno::result(res).map(drop)
}
12 changes: 6 additions & 6 deletions src/sys/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum Signal {
SIGPIPE = libc::SIGPIPE,
SIGALRM = libc::SIGALRM,
SIGTERM = libc::SIGTERM,
#[cfg(not(target_os = "macos"))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
SIGSTKFLT = libc::SIGSTKFLT,
SIGCHLD = libc::SIGCHLD,
SIGCONT = libc::SIGCONT,
Expand All @@ -43,18 +43,18 @@ pub enum Signal {
SIGPROF = libc::SIGPROF,
SIGWINCH = libc::SIGWINCH,
SIGIO = libc::SIGIO,
#[cfg(not(target_os = "macos"))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
SIGPWR = libc::SIGPWR,
SIGSYS = libc::SIGSYS,
#[cfg(target_os = "macos")]
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "emscripten")))]
SIGEMT = libc::SIGEMT,
#[cfg(target_os = "macos")]
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "emscripten")))]
SIGINFO = libc::SIGINFO,
}

pub use self::Signal::*;

#[cfg(not(target_os = "macos"))]
#[cfg(any(target_os = "linux", target_os = "android", target_os = "emscripten"))]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
Expand Down Expand Up @@ -87,7 +87,7 @@ const SIGNALS: [Signal; 31] = [
SIGIO,
SIGPWR,
SIGSYS];
#[cfg(target_os = "macos")]
#[cfg(not(any(target_os = "linux", target_os = "android", target_os = "emscripten")))]
const SIGNALS: [Signal; 31] = [
SIGHUP,
SIGINT,
Expand Down
14 changes: 12 additions & 2 deletions src/sys/socket/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,25 @@
pub use libc::{socket, listen, bind, accept, connect, setsockopt, sendto, recvfrom, getsockname, getpeername, recv, send};

use libc::{c_int, c_void, socklen_t, size_t, ssize_t};
use sys::uio::IoVec;

#[cfg(target_os = "macos")]
use libc::c_uint;

use sys::uio::IoVec;

#[cfg(target_os = "linux")]
pub type type_of_cmsg_len = size_t;

#[cfg(not(target_os = "linux"))]
pub type type_of_cmsg_len = socklen_t;

// OSX always aligns struct cmsghdr as if it were a 32-bit OS
#[cfg(target_os = "macos")]
pub type type_of_cmsg_data = c_uint;

#[cfg(not(target_os = "macos"))]
pub type type_of_cmsg_data = size_t;

// Private because we don't expose any external functions that operate
// directly on this type; we just use it internally at FFI boundaries.
// Note that in some cases we store pointers in *const fields that the
Expand All @@ -37,7 +47,7 @@ pub struct cmsghdr {
pub cmsg_len: type_of_cmsg_len,
pub cmsg_level: c_int,
pub cmsg_type: c_int,
pub cmsg_data: [type_of_cmsg_len; 0]
pub cmsg_data: [type_of_cmsg_data; 0]
}

extern {
Expand Down
27 changes: 13 additions & 14 deletions src/sys/socket/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ unsafe fn copy_bytes<'a, 'b, T: ?Sized>(src: &T, dst: &'a mut &'b mut [u8]) {
}


use self::ffi::{cmsghdr, msghdr, type_of_cmsg_len};
use self::ffi::{cmsghdr, msghdr, type_of_cmsg_len, type_of_cmsg_data};

/// A structure used to make room in a cmsghdr passed to recvmsg. The
/// size and alignment match that of a cmsghdr followed by a T, but the
Expand Down Expand Up @@ -169,8 +169,7 @@ impl<'a> Iterator for CmsgIterator<'a> {
(SOL_SOCKET, SCM_RIGHTS) => unsafe {
Some(ControlMessage::ScmRights(
slice::from_raw_parts(
&cmsg.cmsg_data as *const _ as *const _,
len / mem::size_of::<RawFd>())))
&cmsg.cmsg_data as *const _ as *const _, 1)))
},
(_, _) => unsafe {
Some(ControlMessage::Unknown(UnknownCmsg(
Expand Down Expand Up @@ -201,12 +200,8 @@ pub enum ControlMessage<'a> {
pub struct UnknownCmsg<'a>(&'a cmsghdr, &'a [u8]);

fn cmsg_align(len: usize) -> usize {
let round_to = mem::size_of::<type_of_cmsg_len>();
if len % round_to == 0 {
len
} else {
len + round_to - (len % round_to)
}
let align_bytes = mem::size_of::<type_of_cmsg_data>() - 1;
(len + align_bytes) & !align_bytes
Copy link
Contributor

@fiveop fiveop Aug 7, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change is fine, but regarding usize (see above)

}

impl<'a> ControlMessage<'a> {
Expand All @@ -217,7 +212,7 @@ impl<'a> ControlMessage<'a> {

/// The value of CMSG_LEN on this message.
fn len(&self) -> usize {
mem::size_of::<cmsghdr>() + match *self {
cmsg_align(mem::size_of::<cmsghdr>()) + match *self {
ControlMessage::ScmRights(fds) => {
mem::size_of_val(fds)
},
Expand All @@ -240,7 +235,11 @@ impl<'a> ControlMessage<'a> {
cmsg_data: [],
};
copy_bytes(&cmsg, buf);
copy_bytes(fds, buf);

let padlen = cmsg_align(mem::size_of_val(&cmsg)) -
mem::size_of_val(&cmsg);
let buf2 = &mut &mut buf[padlen..];
copy_bytes(fds, buf2);
},
ControlMessage::Unknown(UnknownCmsg(orig_cmsg, bytes)) => {
copy_bytes(orig_cmsg, buf);
Expand All @@ -267,10 +266,10 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<'
// multiple of size_t. Note also that the resulting vector claims
// to have length == capacity, so it's presently uninitialized.
let mut cmsg_buffer = unsafe {
let mut vec = Vec::<size_t>::with_capacity(capacity / mem::size_of::<size_t>());
let mut vec = Vec::<u8>::with_capacity(len);
let ptr = vec.as_mut_ptr();
mem::forget(vec);
Vec::<u8>::from_raw_parts(ptr as *mut _, capacity, capacity)
Vec::<u8>::from_raw_parts(ptr as *mut _, len, len)
};
{
let mut ptr = &mut cmsg_buffer[..];
Expand All @@ -290,7 +289,7 @@ pub fn sendmsg<'a>(fd: RawFd, iov: &[IoVec<&'a [u8]>], cmsgs: &[ControlMessage<'
msg_iov: iov.as_ptr(),
msg_iovlen: iov.len() as size_t,
msg_control: cmsg_buffer.as_ptr() as *const c_void,
msg_controllen: len as size_t,
msg_controllen: capacity as size_t,
msg_flags: 0,
};
let ret = unsafe { ffi::sendmsg(fd, &mhdr, flags.bits()) };
Expand Down
Loading