summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHomu <homu@barosl.com>2016-11-15 05:25:22 +0900
committerHomu <homu@barosl.com>2016-11-15 05:25:22 +0900
commit6b26884efa2189ef13695b9e7d1e572854a15878 (patch)
tree697c567d2b1ba5ea2aedf471040adc09f93889ad
parenta9f630ed00ec9d98dfdd0d84127c8f44ca92bcb9 (diff)
parent45d8beea46ec06ce52c512c8de5976cff85b67a2 (diff)
downloadnix-6b26884efa2189ef13695b9e7d1e572854a15878.zip
Auto merge of #445 - fiveop:kill_optional_signal, r=@kamalmarhubi
Make signal argument to kill optional Fixes #441
-rw-r--r--CHANGELOG.md6
-rw-r--r--src/sys/signal.rs8
-rw-r--r--test/sys/mod.rs1
-rw-r--r--test/sys/test_signal.rs7
-rw-r--r--test/sys/test_wait.rs2
5 files changed, 21 insertions, 3 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 34bc73bc..ea41e330 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
([#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`
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 345e69e3..d9744b94 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -387,8 +387,12 @@ pub fn pthread_sigmask(how: SigFlags,
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/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_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