Skip to content

Commit 8c196d5

Browse files
author
Markus Wanner (mwa)
committed
Merge branch 'master' into support-getifaddrs
2 parents 6d6ae0b + b335685 commit 8c196d5

28 files changed

+949
-265
lines changed

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
3030
- Added socket option variant that enables the timestamp socket
3131
control message: `nix::sys::socket::sockopt::ReceiveTimestamp`
3232
([#663](https://github.com/nix-rust/nix/pull/663))
33+
- Added more accessor methods for `AioCb`
34+
([#773](https://github.com/nix-rust/nix/pull/773))
35+
- Add nix::sys::fallocate
36+
([#768](https:://github.com/nix-rust/nix/pull/768))
37+
- Added `nix::unistd::mkfifo`.
38+
([#602](https://github.com/nix-rust/nix/pull/774))
39+
- Added `ptrace::Options::PTRACE_O_EXITKILL` on Linux and Android.
40+
([#771](https://github.com/nix-rust/nix/pull/771))
41+
- Added `nix::sys::uio::{process_vm_readv, process_vm_writev}` on Linux
42+
([#568](https://github.com/nix-rust/nix/pull/568))
43+
- Added `nix::unistd::{getgroups, setgroups, getgrouplist, initgroups}`. ([#733](https://github.com/nix-rust/nix/pull/733))
3344

3445
### Changed
3546
- Renamed existing `ptrace` wrappers to encourage namespacing ([#692](https://github.com/nix-rust/nix/pull/692))
@@ -59,14 +70,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5970
([#749](https://github.com/nix-rust/nix/pull/749))
6071
- `AioCb::Drop` will now panic if the `AioCb` is still in-progress ([#715](https://github.com/nix-rust/nix/pull/715))
6172

62-
# Fixed
73+
### Fixed
6374
- Fix compilation and tests for OpenBSD targets
6475
([#688](https://github.com/nix-rust/nix/pull/688))
6576
- Fixed error handling in `AioCb::fsync`, `AioCb::read`, and `AioCb::write`.
6677
It is no longer an error to drop an `AioCb` that failed to enqueue in the OS.
6778
([#715](https://github.com/nix-rust/nix/pull/715))
6879

69-
# Removed
80+
### Removed
7081
- The syscall module has been removed. This only exposed enough functionality for
7182
`memfd_create()` and `pivot_root()`, which are still exposed as separate functions.
7283
([#747](https://github.com/nix-rust/nix/pull/747))

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[package]
2-
32
name = "nix"
43
description = "Rust friendly bindings to *nix APIs"
54
version = "0.10.0-pre"
@@ -10,7 +9,6 @@ categories = ["os::unix-apis"]
109
exclude = [
1110
".gitignore",
1211
".travis.yml",
13-
"deploy.sh",
1412
"test/**/*"
1513
]
1614

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Tier 1:
5454
* arm-unknown-linux-gnueabi
5555
* armv7-unknown-linux-gnueabihf
5656
* i686-apple-darwin
57+
* i686-unknown-freebsd
5758
* i686-unknown-linux-gnu
5859
* i686-unknown-linux-musl
5960
* mips-unknown-linux-gnu
@@ -77,7 +78,6 @@ Tier 2:
7778
* armv7s-apple-ios
7879
* i386-apple-ios
7980
* i686-linux-android (requires Rust >= 1.18)
80-
* i686-unknown-freebsd
8181
* powerpc-unknown-linux-gnu
8282
* s390x-unknown-linux-gnu
8383
* x86_64-apple-ios

deploy.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

nix-test/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub fn main() {
1313
"UNKNOWN"
1414
};
1515

16-
gcc::Config::new()
16+
gcc::Build::new()
1717
.file("src/const.c")
1818
.file("src/sizes.c")
1919
.define(os, None)

src/fcntl.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,43 @@ pub fn vmsplice(fd: RawFd, iov: &[IoVec<&[u8]>], flags: SpliceFFlags) -> Result<
341341
Errno::result(ret).map(|r| r as usize)
342342
}
343343

344+
#[cfg(any(target_os = "linux"))]
345+
libc_bitflags!(
346+
/// Mode argument flags for fallocate determining operation performed on a given range.
347+
pub struct FallocateFlags: libc::c_int {
348+
/// File size is not changed.
349+
///
350+
/// offset + len can be greater than file size.
351+
FALLOC_FL_KEEP_SIZE;
352+
/// Deallocates space by creating a hole.
353+
///
354+
/// Must be ORed with FALLOC_FL_KEEP_SIZE. Byte range starts at offset and continues for len bytes.
355+
FALLOC_FL_PUNCH_HOLE;
356+
/// Removes byte range from a file without leaving a hole.
357+
///
358+
/// Byte range to collapse starts at offset and continues for len bytes.
359+
FALLOC_FL_COLLAPSE_RANGE;
360+
/// Zeroes space in specified byte range.
361+
///
362+
/// Byte range starts at offset and continues for len bytes.
363+
FALLOC_FL_ZERO_RANGE;
364+
/// Increases file space by inserting a hole within the file size.
365+
///
366+
/// Does not overwrite existing data. Hole starts at offset and continues for len bytes.
367+
FALLOC_FL_INSERT_RANGE;
368+
/// Shared file data extants are made private to the file.
369+
///
370+
/// Gaurantees that a subsequent write will not fail due to lack of space.
371+
FALLOC_FL_UNSHARE_RANGE;
372+
}
373+
);
374+
375+
/// Manipulates file space.
376+
///
377+
/// Allows the caller to directly manipulate the allocated disk space for the
378+
/// file referred to by fd.
379+
#[cfg(any(target_os = "linux"))]
380+
pub fn fallocate(fd: RawFd, mode: FallocateFlags, offset: libc::off_t, len: libc::off_t) -> Result<c_int> {
381+
let res = unsafe { libc::fallocate(fd, mode.bits(), offset, len) };
382+
Errno::result(res)
383+
}

src/mqueue.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ impl MqAttr {
6363
}
6464

6565

66+
/// Open a message queue
67+
///
68+
/// See also [mq_open(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_open.html)
6669
pub fn mq_open(name: &CString,
6770
oflag: MQ_OFlag,
6871
mode: Mode,
@@ -80,16 +83,25 @@ pub fn mq_open(name: &CString,
8083
Errno::result(res)
8184
}
8285

86+
/// Remove a message queue
87+
///
88+
/// See also [mq_unlink(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_unlink.html)
8389
pub fn mq_unlink(name: &CString) -> Result<()> {
8490
let res = unsafe { libc::mq_unlink(name.as_ptr()) };
8591
Errno::result(res).map(drop)
8692
}
8793

94+
/// Close a message queue
95+
///
96+
/// See also [mq_close(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_close.html)
8897
pub fn mq_close(mqdes: mqd_t) -> Result<()> {
8998
let res = unsafe { libc::mq_close(mqdes) };
9099
Errno::result(res).map(drop)
91100
}
92101

102+
/// Receive a message from a message queue
103+
///
104+
/// See also [mq_receive(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_receive.html)
93105
pub fn mq_receive(mqdes: mqd_t, message: &mut [u8], msg_prio: &mut u32) -> Result<usize> {
94106
let len = message.len() as size_t;
95107
let res = unsafe {
@@ -101,6 +113,9 @@ pub fn mq_receive(mqdes: mqd_t, message: &mut [u8], msg_prio: &mut u32) -> Resul
101113
Errno::result(res).map(|r| r as usize)
102114
}
103115

116+
/// Send a message to a message queue
117+
///
118+
/// See also [mq_send(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_send.html)
104119
pub fn mq_send(mqdes: mqd_t, message: &[u8], msq_prio: u32) -> Result<()> {
105120
let res = unsafe {
106121
libc::mq_send(mqdes,
@@ -111,6 +126,9 @@ pub fn mq_send(mqdes: mqd_t, message: &[u8], msq_prio: u32) -> Result<()> {
111126
Errno::result(res).map(drop)
112127
}
113128

129+
/// Get message queue attributes
130+
///
131+
/// See also [mq_getattr(2)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_getattr.html)
114132
pub fn mq_getattr(mqd: mqd_t) -> Result<MqAttr> {
115133
let mut attr = unsafe { mem::uninitialized::<libc::mq_attr>() };
116134
let res = unsafe { libc::mq_getattr(mqd, &mut attr) };
@@ -121,7 +139,7 @@ pub fn mq_getattr(mqd: mqd_t) -> Result<MqAttr> {
121139
/// Returns the old attributes
122140
/// It is recommend to use the `mq_set_nonblock()` and `mq_remove_nonblock()` convenience functions as they are easier to use
123141
///
124-
/// [Further reading](http://man7.org/linux/man-pages/man3/mq_setattr.3.html)
142+
/// [Further reading](http://pubs.opengroup.org/onlinepubs/9699919799/functions/mq_setattr.html)
125143
pub fn mq_setattr(mqd: mqd_t, newattr: &MqAttr) -> Result<MqAttr> {
126144
let mut attr = unsafe { mem::uninitialized::<libc::mq_attr>() };
127145
let res = unsafe { libc::mq_setattr(mqd, &newattr.mq_attr as *const libc::mq_attr, &mut attr) };

src/poll.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ libc_bitflags! {
9191
}
9292

9393
/// `poll` waits for one of a set of file descriptors to become ready to perform I/O.
94-
/// ([`poll(2)`](http://man7.org/linux/man-pages/man2/poll.2.html))
94+
/// ([`poll(2)`](http://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html))
9595
///
9696
/// `fds` contains all [`PollFd`](struct.PollFd.html) to poll.
9797
/// The function will return as soon as any event occur for any of these `PollFd`s.

src/pty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Drop for PtyMaster {
6161
}
6262

6363
/// Grant access to a slave pseudoterminal (see
64-
/// [grantpt(3)](http://man7.org/linux/man-pages/man3/grantpt.3.html))
64+
/// [grantpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/grantpt.html))
6565
///
6666
/// `grantpt()` changes the mode and owner of the slave pseudoterminal device corresponding to the
6767
/// master pseudoterminal referred to by `fd`. This is a necessary step towards opening the slave.
@@ -75,7 +75,7 @@ pub fn grantpt(fd: &PtyMaster) -> Result<()> {
7575
}
7676

7777
/// Open a pseudoterminal device (see
78-
/// [posix_openpt(3)](http://man7.org/linux/man-pages/man3/posix_openpt.3.html))
78+
/// [posix_openpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/posix_openpt.html))
7979
///
8080
/// `posix_openpt()` returns a file descriptor to an existing unused pseuterminal master device.
8181
///
@@ -176,7 +176,7 @@ pub fn ptsname_r(fd: &PtyMaster) -> Result<String> {
176176
}
177177

178178
/// Unlock a pseudoterminal master/slave pseudoterminal pair (see
179-
/// [unlockpt(3)](http://man7.org/linux/man-pages/man3/unlockpt.3.html))
179+
/// [unlockpt(3)](http://pubs.opengroup.org/onlinepubs/9699919799/functions/unlockpt.html))
180180
///
181181
/// `unlockpt()` unlocks the slave pseudoterminal device corresponding to the master pseudoterminal
182182
/// referred to by `fd`. This must be called before trying to open the slave side of a

src/sys/aio.rs

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,44 @@ use sys::time::TimeSpec;
1313

1414
/// Mode for `AioCb::fsync`. Controls whether only data or both data and
1515
/// metadata are synced.
16-
#[repr(i32)]
17-
#[derive(Clone, Copy, Debug, PartialEq)]
18-
pub enum AioFsyncMode {
19-
/// do it like `fsync`
20-
O_SYNC = libc::O_SYNC,
21-
/// on supported operating systems only, do it like `fdatasync`
22-
#[cfg(any(target_os = "openbsd", target_os = "bitrig",
23-
target_os = "netbsd", target_os = "macos", target_os = "ios",
24-
target_os = "linux"))]
25-
O_DSYNC = libc::O_DSYNC
16+
libc_enum! {
17+
#[repr(i32)]
18+
pub enum AioFsyncMode {
19+
/// do it like `fsync`
20+
O_SYNC,
21+
/// on supported operating systems only, do it like `fdatasync`
22+
#[cfg(any(target_os = "bitrig",
23+
target_os = "ios",
24+
target_os = "linux",
25+
target_os = "macos",
26+
target_os = "netbsd",
27+
target_os = "openbsd"))]
28+
O_DSYNC
29+
}
2630
}
2731

28-
/// When used with `lio_listio`, determines whether a given `aiocb` should be
29-
/// used for a read operation, a write operation, or ignored. Has no effect for
30-
/// any other aio functions.
31-
#[repr(i32)]
32-
#[derive(Clone, Copy, Debug, PartialEq)]
33-
pub enum LioOpcode {
34-
LIO_NOP = libc::LIO_NOP,
35-
LIO_WRITE = libc::LIO_WRITE,
36-
LIO_READ = libc::LIO_READ
32+
libc_enum! {
33+
/// When used with `lio_listio`, determines whether a given `aiocb` should be
34+
/// used for a read operation, a write operation, or ignored. Has no effect for
35+
/// any other aio functions.
36+
#[repr(i32)]
37+
pub enum LioOpcode {
38+
LIO_NOP,
39+
LIO_WRITE,
40+
LIO_READ,
41+
}
3742
}
3843

39-
/// Mode for `lio_listio`.
40-
#[repr(i32)]
41-
#[derive(Clone, Copy, Debug, PartialEq)]
42-
pub enum LioMode {
43-
/// Requests that `lio_listio` block until all requested operations have
44-
/// been completed
45-
LIO_WAIT = libc::LIO_WAIT,
46-
/// Requests that `lio_listio` return immediately
47-
LIO_NOWAIT = libc::LIO_NOWAIT,
44+
libc_enum! {
45+
/// Mode for `lio_listio`.
46+
#[repr(i32)]
47+
pub enum LioMode {
48+
/// Requests that `lio_listio` block until all requested operations have
49+
/// been completed
50+
LIO_WAIT,
51+
/// Requests that `lio_listio` return immediately
52+
LIO_NOWAIT,
53+
}
4854
}
4955

5056
/// Return values for `AioCb::cancel and aio_cancel_all`
@@ -84,6 +90,11 @@ pub struct AioCb<'a> {
8490
}
8591

8692
impl<'a> AioCb<'a> {
93+
/// Returns the underlying file descriptor associated with the `AioCb`
94+
pub fn fd(&self) -> RawFd {
95+
self.aiocb.aio_fildes
96+
}
97+
8798
/// Constructs a new `AioCb` with no associated buffer.
8899
///
89100
/// The resulting `AioCb` structure is suitable for use with `AioCb::fsync`.
@@ -239,6 +250,38 @@ impl<'a> AioCb<'a> {
239250
})
240251
}
241252

253+
/// Returns the `aiocb`'s `LioOpcode` field
254+
///
255+
/// If the value cannot be represented as an `LioOpcode`, returns `None`
256+
/// instead.
257+
pub fn lio_opcode(&self) -> Option<LioOpcode> {
258+
match self.aiocb.aio_lio_opcode {
259+
libc::LIO_READ => Some(LioOpcode::LIO_READ),
260+
libc::LIO_WRITE => Some(LioOpcode::LIO_WRITE),
261+
libc::LIO_NOP => Some(LioOpcode::LIO_NOP),
262+
_ => None
263+
}
264+
}
265+
266+
/// Returns the requested length of the aio operation in bytes
267+
///
268+
/// This method returns the *requested* length of the operation. To get the
269+
/// number of bytes actually read or written by a completed operation, use
270+
/// `aio_return` instead.
271+
pub fn nbytes(&self) -> usize {
272+
self.aiocb.aio_nbytes
273+
}
274+
275+
/// Returns the file offset stored in the `AioCb`
276+
pub fn offset(&self) -> off_t {
277+
self.aiocb.aio_offset
278+
}
279+
280+
/// Returns the priority of the `AioCb`
281+
pub fn priority(&self) -> libc::c_int {
282+
self.aiocb.aio_reqprio
283+
}
284+
242285
/// Asynchronously reads from a file descriptor into a buffer
243286
pub fn read(&mut self) -> Result<()> {
244287
assert!(self.mutable, "Can't read into an immutable buffer");
@@ -250,6 +293,11 @@ impl<'a> AioCb<'a> {
250293
})
251294
}
252295

296+
/// Returns the `SigEvent` stored in the `AioCb`
297+
pub fn sigevent(&self) -> SigEvent {
298+
SigEvent::from(&self.aiocb.aio_sigevent)
299+
}
300+
253301
/// Retrieve return status of an asynchronous operation. Should only be
254302
/// called once for each `AioCb`, after `AioCb::error` indicates that it has
255303
/// completed. The result is the same as for `read`, `write`, of `fsync`.

0 commit comments

Comments
 (0)