ruby-changes:21419
From: nobu <ko1@a...>
Date: Fri, 14 Oct 2011 12:14:13 +0900 (JST)
Subject: [ruby-changes:21419] nobu:r33468 (trunk): * ext/pty/pty.c (pty_check): should return nil until the child
nobu 2011-10-14 12:14:00 +0900 (Fri, 14 Oct 2011) New Revision: 33468 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=33468 Log: * ext/pty/pty.c (pty_check): should return nil until the child terminates or stops. [ruby-dev:44600] [Bug #2642] Modified files: trunk/ChangeLog trunk/ext/pty/pty.c trunk/test/test_pty.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 33467) +++ ChangeLog (revision 33468) @@ -1,3 +1,8 @@ +Fri Oct 14 12:13:57 2011 Nobuyoshi Nakada <nobu@r...> + + * ext/pty/pty.c (pty_check): should return nil until the child + terminates or stops. [ruby-dev:44600] [Bug #2642] + Fri Oct 14 11:19:37 2011 Nobuyoshi Nakada <nobu@r...> * include/ruby/intern.h (rb_ary_reverse): export. Index: ext/pty/pty.c =================================================================== --- ext/pty/pty.c (revision 33467) +++ ext/pty/pty.c (revision 33468) @@ -658,7 +658,7 @@ rb_scan_args(argc, argv, "11", &pid, &exc); cpid = rb_waitpid(NUM2PIDT(pid), &status, WNOHANG|WUNTRACED); - if (cpid == -1) return Qnil; + if (cpid == -1 || cpid == 0) return Qnil; if (!RTEST(exc)) return rb_last_status_get(); raise_from_check(cpid, status); Index: test/test_pty.rb =================================================================== --- test/test_pty.rb (revision 33467) +++ test/test_pty.rb (revision 33468) @@ -163,5 +163,37 @@ } end end + + def test_pty_check_default + st1 = st2 = pid = nil + `echo` # preset $? + PTY.spawn("cat") do |r,w,id| + pid = id + st1 = PTY.check(pid) + w.close + r.close + sleep(0.1) + st2 = PTY.check(pid) + end + assert_equal(pid, st1.pid) if st1 + assert_nil(st1) + assert_equal(pid, st2.pid) + end + + def test_pty_check_raise + bug2642 = '[ruby-dev:44600]' + st1 = st2 = pid = nil + PTY.spawn("cat") do |r,w,id| + pid = id + assert_nothing_raised(PTY::ChildExited, bug2642) {st1 = PTY.check(pid, true)} + w.close + r.close + sleep(0.1) + st2 = assert_raise(PTY::ChildExited, bug2642) {PTY.check(pid, true)}.status + end + assert_equal(pid, st1.pid) if st1 + assert_nil(st1) + assert_equal(pid, st2.pid) + end end if defined? PTY -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/