浏览代码

test and fixes

Paul Sajna 7 年之前
父节点
当前提交
b35abd1065
共有 8 个文件被更改,包括 29 次插入5 次删除
  1. 1 0
      src/lib.rs
  2. 1 1
      src/platform/src/linux/mod.rs
  3. 6 1
      src/platform/src/redox/mod.rs
  4. 2 2
      src/resource/cbindgen.toml
  5. 1 1
      src/wait/src/lib.rs
  6. 1 0
      tests/.gitignore
  7. 1 0
      tests/Makefile
  8. 16 0
      tests/waitpid.c

+ 1 - 0
src/lib.rs

@@ -17,6 +17,7 @@ extern crate string;
 extern crate sys_time;
 extern crate time;
 extern crate unistd;
+extern crate wait;
 extern crate wctype;
 
 #[lang = "eh_personality"]

+ 1 - 1
src/platform/src/linux/mod.rs

@@ -160,7 +160,7 @@ pub fn unlink(path: *const c_char) -> c_int {
 }
 
 pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
-    e(unsafe { syscall!(WAIT4, pid, stat_loc, options) }) as pid_t
+    e(unsafe { syscall!(WAIT4, pid, stat_loc, options, 0) }) as pid_t
 }
 
 pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {

+ 6 - 1
src/platform/src/redox/mod.rs

@@ -203,7 +203,12 @@ pub fn unlink(path: *const c_char) -> c_int {
 }
 
 pub fn waitpid(pid: pid_t, stat_loc: *mut c_int, options: c_int) -> pid_t {
-    e(syscall::waitpid(pid as usize, stat_loc as &mut usize, options as usize))
+    unsafe {
+        let mut temp: usize = *stat_loc as usize;
+        let res = e(syscall::waitpid(pid as usize, &mut temp, options as usize));
+        *stat_loc = temp as c_int;
+        res
+    }
 }
 
 pub fn write(fd: c_int, buf: &[u8]) -> ssize_t {

+ 2 - 2
src/resource/cbindgen.toml

@@ -1,7 +1,7 @@
-sys_includes = ["sys/types.h", "sys/time.h"]
+sys_includes = ["sys/types.h", "stdint.h", "sys/time.h"]
 include_guard = "_SYS_RESOURCE_H"
 language = "C"
-style = "Tag"
+style = "Both"
 
 [enum]
 prefix_with_name = true

+ 1 - 1
src/wait/src/lib.rs

@@ -11,7 +11,7 @@ use resource::rusage;
 
 #[no_mangle]
 pub unsafe extern "C" fn wait(stat_loc: *mut c_int) -> pid_t {
-    waitpid(-1, stat_loc, 0)
+    waitpid(0-1, stat_loc, 0)
 }
 
 #[no_mangle]

+ 1 - 0
tests/.gitignore

@@ -33,5 +33,6 @@
 /string/strrchr
 /string/strspn
 /unlink
+/waitpid
 /write
 

+ 1 - 0
tests/Makefile

@@ -28,6 +28,7 @@ EXPECT_BINS=\
 	string/strrchr \
 	string/strspn \
 	unlink \
+	waitpid \
 	write
 
 # Binaries that may generate varied output

+ 16 - 0
tests/waitpid.c

@@ -0,0 +1,16 @@
+#include <sys/wait.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+int main(int argc, char** argv) {
+    pid_t pid = fork();
+    if (pid == 0) {
+    // child
+    sleep(1);
+    exit(0);
+} else {
+    // parent
+    int* stat_loc;
+    waitpid(pid, stat_loc, 0);
+    }
+}