Skip to content
Permalink
Browse files

Merge pull request #732 from jstepien/errno-echild

Errno::ECHILD thrown from Process.waitpid, some Process methods
  • Loading branch information
alex committed May 27, 2013
2 parents 78f5ca1 + 5bd31a2 commit 9c3d4187c93e442f047f37d9d59d8da86cfd080a
@@ -11,6 +11,7 @@
load_bootstrap.call("comparable.rb")
load_bootstrap.call("enumerable.rb")
load_bootstrap.call("enumerator.rb")
load_bootstrap.call("errno.rb")
load_bootstrap.call("file.rb")
load_bootstrap.call("fixnum.rb")
load_bootstrap.call("hash.rb")
@@ -0,0 +1,4 @@
module Errno
class ECHILD < SystemCallError
end
end
@@ -8,8 +8,15 @@ def self.waitpid2(pid = -1)
return [pid, $?]
end

def self.wait2(pid = -1)
waitpid2(pid)
end

def self.waitall
raise NotImplementedError.new("Process.waitall")
result = []
result << wait2 while true
rescue Errno::ECHILD
result
end

class Status

This file was deleted.

@@ -1,4 +1,3 @@
fails:Process.wait raises a Errno::ECHILD if there are no child processes
fails:Process.wait waits for any child process if no pid is given
fails:Process.wait waits for a specific child if a pid is given
fails:Process.wait coerces the pid to an Integer
@@ -1,3 +1 @@
fails:Process.waitall returns an empty array when there are no children
fails:Process.waitall waits for all children
fails:Process.waitall returns an array of pid/status pairs
@@ -63,7 +63,6 @@ class MSpecScript
"^#{Rubyspec}/core/process/status/signaled_spec.rb",
"^#{Rubyspec}/core/process/status/success_spec.rb",
"^#{Rubyspec}/core/process/status/termsig_spec.rb",
"^#{Rubyspec}/core/process/wait_spec.rb",
"^#{Rubyspec}/core/file/ctime_spec.rb"
]

@@ -1,4 +1,5 @@
import os
import errno


class RubyError(Exception):
@@ -25,9 +26,22 @@ def print_traceback(space, w_exc, top_filepath=None):
os.write(2, line)


def error_for_oserror(space, exc):
_errno_for_oserror_map = {
errno.ECHILD: "ECHILD",
}

def error_for_oserror(space, exc, callee=None):
if callee:
try:
name = _errno_for_oserror_map[exc.errno]
except KeyError:
type = space.w_SystemCallError
else:
type = space.find_const(space.find_const(callee, "Errno"), name)
else:
type = space.w_SystemCallError
return space.error(
space.w_SystemCallError,
type,
os.strerror(exc.errno),
[space.newint(exc.errno)]
)
@@ -4,6 +4,7 @@

from topaz.module import ModuleDef
from topaz.system import IS_WINDOWS
from topaz.error import error_for_oserror


if IS_WINDOWS:
@@ -35,7 +36,10 @@ def method_pid(self, space):

@moduledef.function("waitpid", pid="int")
def method_waitpid(self, space, pid=-1):
pid, status = os.waitpid(pid, 0)
try:
pid, status = os.waitpid(pid, 0)
except OSError as e:
raise error_for_oserror(space, e, self)
status = WEXITSTATUS(status)
w_status = space.send(
space.find_const(self, "Status"),

0 comments on commit 9c3d418

Please sign in to comment.
You can’t perform that action at this time.