diff options
| author | ksss <[email protected]> | 2014-12-04 10:21:29 +0900 |
|---|---|---|
| committer | ksss <[email protected]> | 2014-12-04 10:25:03 +0900 |
| commit | e61c46972482ca2b4e9b338f9ccfa4ee13efa62d (patch) | |
| tree | a050a34dc2ac07995530f438d39850ae0cd2fa5d | |
| parent | 9439b981d816a25883bd9d8f05af62664f21e0bc (diff) | |
| download | mruby-e61c46972482ca2b4e9b338f9ccfa4ee13efa62d.tar.gz mruby-e61c46972482ca2b4e9b338f9ccfa4ee13efa62d.zip | |
IO.popen fd set close_on_exec flag by default
| -rw-r--r-- | src/io.c | 21 | ||||
| -rw-r--r-- | test/io.rb | 1 |
2 files changed, 16 insertions, 6 deletions
@@ -223,13 +223,22 @@ mrb_io_s_popen(mrb_state *mrb, mrb_value klass) doexec = (strcmp("-", pname) != 0); - if ((flags & FMODE_READABLE) && pipe(pr) == -1) { - mrb_sys_fail(mrb, "pipe"); + if (flags & FMODE_READABLE) { + if (pipe(pr) == -1) { + mrb_sys_fail(mrb, "pipe"); + } + mrb_fd_cloexec(mrb, pr[0]); + mrb_fd_cloexec(mrb, pr[1]); } - if ((flags & FMODE_WRITABLE) && pipe(pw) == -1) { - if (pr[0] != -1) close(pr[0]); - if (pr[1] != -1) close(pr[1]); - mrb_sys_fail(mrb, "pipe"); + + if (flags & FMODE_WRITABLE) { + if (pipe(pw) == -1) { + if (pr[0] != -1) close(pr[0]); + if (pr[1] != -1) close(pr[1]); + mrb_sys_fail(mrb, "pipe"); + } + mrb_fd_cloexec(mrb, pw[0]); + mrb_fd_cloexec(mrb, pw[1]); } if (!doexec) { diff --git a/test/io.rb b/test/io.rb index 9c7ce741f..b828fef49 100644 --- a/test/io.rb +++ b/test/io.rb @@ -321,6 +321,7 @@ end assert('IO.popen') do io = IO.popen("ls") + assert_true io.close_on_exec? assert_equal Fixnum, io.pid.class ls = io.read assert_equal ls.class, String |
