summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorCyril Plisko <cyril.plisko@mountall.com>2016-11-10 14:50:02 +0200
committerCyril Plisko <cyril.plisko@mountall.com>2016-11-10 14:50:02 +0200
commitce07c661f0478d83a587c33d4b9c751c4d9f7d30 (patch)
tree10ef33b53589e89e37df93be3f70cac51d7feba8 /src
parentb2c0cb9c35be0c4b49f81389dda3a5868b08d42b (diff)
Fix CString ownership issue
fixes #4
Diffstat (limited to 'src')
-rw-r--r--src/utils.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/utils.rs b/src/utils.rs
index d880b90..ac48fb4 100644
--- a/src/utils.rs
+++ b/src/utils.rs
@@ -23,20 +23,12 @@ pub fn fork() -> libc::pid_t {
}
pub fn execvp(cmd: &OsString) {
- // println!("cmd {:?}", cmd);
- let mut args = Vec::with_capacity(2);
- for arg in split_string(cmd) {
- // println!("arg {:?}", arg);
- args.push(osstring2cstring(&arg).as_ptr())
- }
+ let cstrings = split_string(cmd).iter().map(osstring2cstring).collect::<Vec<_>>();
+ let mut args = cstrings.iter().map(|c| c.as_ptr()).collect::<Vec<_>>();
+
args.push(ptr::null());
- // println!("args {:?}", args);
errno::set_errno(errno::Errno(0));
- // println!("errno pre {}", errno::errno());
- // println!("Going to run execvp({:?}, {:?})", args[0], args.as_ptr());
unsafe { libc::execvp(args[0], args.as_ptr()) };
- // println!("errno post {}", errno::errno());
- assert!(false);
}
pub fn dup2(fd1: i32, fd2: i32) {