summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md14
-rw-r--r--src/sys/event.rs12
-rw-r--r--src/sys/signal.rs8
-rw-r--r--src/unistd.rs30
-rw-r--r--test/sys/mod.rs1
-rw-r--r--test/sys/test_signal.rs7
-rw-r--r--test/sys/test_uio.rs2
-rw-r--r--test/sys/test_wait.rs2
-rw-r--r--test/test_mount.rs2
-rw-r--r--test/test_unistd.rs12
10 files changed, 67 insertions, 23 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 79bb6c9c..e3235bd0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,15 +16,25 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#448](https://github.com/nix-rust/nix/pull/448))
- Added `getpgid` in `::nix::unistd`
([#433](https://github.com/nix-rust/nix/pull/433))
+- Added `tcgetpgrp` and `tcsetpgrp` in `::nix::unistd`
+ ([#451](https://github.com/nix-rust/nix/pull/451))
+- Added `CLONE_NEWCGROUP` in `::nix::sched`
+ ([#457](https://github.com/nix-rust/nix/pull/457))
### Changed
+- `kill`'s signature, defined in `::nix::sys::signal`, changed, so that the
+ signal parameter has type `T: Into<Option<Signal>>`. `None` as an argument
+ for that parameter will result in a 0 passed to libc's `kill`, while a
+ `Some`-argument will result in the previous behavior for the contained
+ `Signal`.
+ ([#445](https://github.com/nix-rust/nix/pull/410))
- The minimum supported version of rustc is now 1.7.0.
([#444](https://github.com/nix-rust/nix/pull/444))
-- Implement `Send` for `KEvent`
- ([#442](https://github.com/nix-rust/nix/pull/442))
- Changed `KEvent` to an opaque structure that may only be modified by its
constructor and the `ev_set` method.
([#415](https://github.com/nix-rust/nix/pull/415))
+ ([#442](https://github.com/nix-rust/nix/pull/442))
+ ([#463](https://github.com/nix-rust/nix/pull/463))
- `pipe2` now calls `libc::pipe2` where available. Previously it was emulated
using `pipe`, which meant that setting `O_CLOEXEC` was not atomic.
([#427](https://github.com/nix-rust/nix/pull/427))
diff --git a/src/sys/event.rs b/src/sys/event.rs
index 68528c9e..0ada5bd6 100644
--- a/src/sys/event.rs
+++ b/src/sys/event.rs
@@ -193,14 +193,14 @@ pub fn kqueue() -> Result<RawFd> {
// KEvent can't derive Send because on some operating systems, udata is defined
-// as a void*. However, KEvent's public API always treats udata as a uintptr_t,
+// as a void*. However, KEvent's public API always treats udata as an intptr_t,
// which is safe to Send.
unsafe impl Send for KEvent {
}
impl KEvent {
pub fn new(ident: uintptr_t, filter: EventFilter, flags: EventFlag,
- fflags:FilterFlag, data: intptr_t, udata: uintptr_t) -> KEvent {
+ fflags:FilterFlag, data: intptr_t, udata: intptr_t) -> KEvent {
KEvent { kevent: libc::kevent {
ident: ident,
filter: filter as type_of_event_filter,
@@ -231,8 +231,8 @@ impl KEvent {
self.kevent.data
}
- pub fn udata(&self) -> uintptr_t {
- self.kevent.udata as uintptr_t
+ pub fn udata(&self) -> intptr_t {
+ self.kevent.udata as intptr_t
}
}
@@ -282,7 +282,7 @@ pub fn ev_set(ev: &mut KEvent,
filter: EventFilter,
flags: EventFlag,
fflags: FilterFlag,
- udata: uintptr_t) {
+ udata: intptr_t) {
ev.kevent.ident = ident as uintptr_t;
ev.kevent.filter = filter as type_of_event_filter;
@@ -294,7 +294,7 @@ pub fn ev_set(ev: &mut KEvent,
#[test]
fn test_struct_kevent() {
- let udata : uintptr_t = 12345;
+ let udata : intptr_t = 12345;
let expected = libc::kevent{ident: 0xdeadbeef,
filter: libc::EVFILT_READ,
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 2a403b08..797b25f9 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -387,8 +387,12 @@ pub fn pthread_sigmask(how: SigmaskHow,
Errno::result(res).map(drop)
}
-pub fn kill(pid: libc::pid_t, signal: Signal) -> Result<()> {
- let res = unsafe { libc::kill(pid, signal as libc::c_int) };
+pub fn kill<T: Into<Option<Signal>>>(pid: libc::pid_t, signal: T) -> Result<()> {
+ let res = unsafe { libc::kill(pid,
+ match signal.into() {
+ Some(s) => s as libc::c_int,
+ None => 0,
+ }) };
Errno::result(res).map(drop)
}
diff --git a/src/unistd.rs b/src/unistd.rs
index 31b55f83..68a22ea1 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -129,6 +129,28 @@ pub fn setsid() -> Result<pid_t> {
Errno::result(unsafe { libc::setsid() })
}
+
+/// Get the terminal foreground process group (see
+/// [tcgetpgrp(3)](http://man7.org/linux/man-pages/man3/tcgetpgrp.3.html)).
+///
+/// Get the group process id (GPID) of the foreground process group on the
+/// terminal associated to file descriptor (FD).
+#[inline]
+pub fn tcgetgrp(fd: c_int) -> Result<pid_t> {
+ let res = unsafe { libc::tcgetpgrp(fd) };
+ Errno::result(res)
+}
+/// Set the terminal foreground process group (see
+/// [tcgetpgrp(3)](http://man7.org/linux/man-pages/man3/tcgetpgrp.3.html)).
+///
+/// Get the group process id (PGID) to the foreground process group on the
+/// terminal associated to file descriptor (FD).
+#[inline]
+pub fn tcsetpgrp(fd: c_int, pgrp: pid_t) -> Result<()> {
+ let res = unsafe { libc::tcsetpgrp(fd, pgrp) };
+ Errno::result(res).map(drop)
+}
+
/// Get the caller's thread ID (see
/// [gettid(2)](http://man7.org/linux/man-pages/man2/gettid.2.html).
///
@@ -240,12 +262,12 @@ pub fn chdir<P: ?Sized + NixPath>(path: &P) -> Result<()> {
/// use tempdir::TempDir;
///
/// fn main() {
-/// let mut tmp_dir = TempDir::new("test_mkdir").unwrap().into_path();
-/// tmp_dir.push("new_dir");
+/// let tmp_dir1 = TempDir::new("test_mkdir").unwrap();
+/// let tmp_dir2 = tmp_dir1.path().join("new_dir");
///
/// // create new directory and give read, write and execute rights to the owner
-/// match unistd::mkdir(&tmp_dir, stat::S_IRWXU) {
-/// Ok(_) => println!("created {:?}", tmp_dir),
+/// match unistd::mkdir(&tmp_dir2, stat::S_IRWXU) {
+/// Ok(_) => println!("created {:?}", tmp_dir2),
/// Err(err) => println!("Error creating directory: {}", err),
/// }
/// }
diff --git a/test/sys/mod.rs b/test/sys/mod.rs
index a5f3351d..6176eb32 100644
--- a/test/sys/mod.rs
+++ b/test/sys/mod.rs
@@ -1,3 +1,4 @@
+mod test_signal;
mod test_socket;
mod test_sockopt;
mod test_termios;
diff --git a/test/sys/test_signal.rs b/test/sys/test_signal.rs
new file mode 100644
index 00000000..4084a0da
--- /dev/null
+++ b/test/sys/test_signal.rs
@@ -0,0 +1,7 @@
+use nix::unistd::*;
+use nix::sys::signal::*;
+
+#[test]
+fn test_kill_none() {
+ kill(getpid(), None).ok().expect("Should be able to send signal to myself.");
+}
diff --git a/test/sys/test_uio.rs b/test/sys/test_uio.rs
index dda97cde..90cda56f 100644
--- a/test/sys/test_uio.rs
+++ b/test/sys/test_uio.rs
@@ -2,7 +2,7 @@ use nix::sys::uio::*;
use nix::unistd::*;
use rand::{thread_rng, Rng};
use std::{cmp, iter};
-use std::fs::{OpenOptions, remove_file};
+use std::fs::{OpenOptions};
use std::os::unix::io::AsRawFd;
use tempdir::TempDir;
diff --git a/test/sys/test_wait.rs b/test/sys/test_wait.rs
index c2112bac..d8ac94e4 100644
--- a/test/sys/test_wait.rs
+++ b/test/sys/test_wait.rs
@@ -9,7 +9,7 @@ fn test_wait_signal() {
match fork() {
Ok(Child) => pause().unwrap_or(()),
Ok(Parent { child }) => {
- kill(child, SIGKILL).ok().expect("Error: Kill Failed");
+ kill(child, Some(SIGKILL)).ok().expect("Error: Kill Failed");
assert_eq!(waitpid(child, None), Ok(WaitStatus::Signaled(child, SIGKILL, false)));
},
// panic, fork should never fail unless there is a serious problem with the OS
diff --git a/test/test_mount.rs b/test/test_mount.rs
index 73d26891..42670216 100644
--- a/test/test_mount.rs
+++ b/test/test_mount.rs
@@ -128,8 +128,6 @@ exit 23";
}
pub fn test_mount_bind() {
- use std::env;
-
let tempdir = TempDir::new("nix-test_mount")
.unwrap_or_else(|e| panic!("tempdir failed: {}", e));
let file_name = "test";
diff --git a/test/test_unistd.rs b/test/test_unistd.rs
index 856693f6..d281f9b2 100644
--- a/test/test_unistd.rs
+++ b/test/test_unistd.rs
@@ -143,19 +143,21 @@ macro_rules! execve_test_factory(
#[test]
fn test_getcwd() {
- let mut tmp_dir = TempDir::new("test_getcwd").unwrap().into_path();
- assert!(chdir(tmp_dir.as_path()).is_ok());
+ let tmp_dir = TempDir::new("test_getcwd").unwrap();
+ assert!(chdir(tmp_dir.path()).is_ok());
assert_eq!(getcwd().unwrap(), current_dir().unwrap());
// make path 500 chars longer so that buffer doubling in getcwd kicks in.
// Note: One path cannot be longer than 255 bytes (NAME_MAX)
// whole path cannot be longer than PATH_MAX (usually 4096 on linux, 1024 on macos)
+ let mut inner_tmp_dir = tmp_dir.path().to_path_buf();
for _ in 0..5 {
let newdir = iter::repeat("a").take(100).collect::<String>();
- tmp_dir.push(newdir);
- assert!(mkdir(tmp_dir.as_path(), stat::S_IRWXU).is_ok());
+ //inner_tmp_dir = inner_tmp_dir.join(newdir).path();
+ inner_tmp_dir.push(newdir);
+ assert!(mkdir(inner_tmp_dir.as_path(), stat::S_IRWXU).is_ok());
}
- assert!(chdir(tmp_dir.as_path()).is_ok());
+ assert!(chdir(inner_tmp_dir.as_path()).is_ok());
assert_eq!(getcwd().unwrap(), current_dir().unwrap());
}