Skip to content

Commit

Permalink
fix a few bugs in supervise_api
Browse files Browse the repository at this point in the history
  • Loading branch information
catern committed May 5, 2017
1 parent 0199e9f commit 0809313
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name='supervise_api',
version='0.1.2',
version='0.1.5',
description='An API for running processes safely and securely',
long_description=("This package uses the supervise utility, a separately-available C binary,"
" to provide a better process API for Linux."),
Expand Down
20 changes: 14 additions & 6 deletions python/supervise_api/supervise.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
try:
O_CLOEXEC=os.O_CLOEXEC
except:
O_CLOEXEC=02000000
O_CLOEXEC=0o2000000
# ...or os.set_inheritable
try:
set_inheritable=os.set_inheritable
Expand Down Expand Up @@ -74,8 +74,11 @@ def update_fds(fds):
# copy fds, turning everything to a raw integer fd
orig_fds = fds
fds = {}
to_close = []
for target in orig_fds:
if isinstance(orig_fds[target], int):
if orig_fds[target] is None:
to_close.append(target)
elif isinstance(orig_fds[target], int):
fds[target] = orig_fds[target]
else:
fds[target] = orig_fds[target].fileno()
Expand Down Expand Up @@ -131,6 +134,9 @@ def dup(fd):
for copy in copied_sources.values():
os.close(copy)

for target in to_close:
os.close(target)

def dfork(args, env={}, fds={}, cwd=None, flags=O_CLOEXEC):
"""Create an fd-managed process, and return the fd.
Expand Down Expand Up @@ -183,12 +189,14 @@ def dfork(args, env={}, fds={}, cwd=None, flags=O_CLOEXEC):
raise TypeError("env key is not a string: {}".format(var))
if not isinstance(env[var], str):
raise TypeError("env value is not a string: {}".format(env[var]))
def good_fd(fd):
return fd is None or isinstance(fd, int) or hasattr(fd, "fileno")
for fd in fds:
if not isinstance(fd, str) and not getattr(fd, "fileno"):
raise TypeError("fds key is not an int and has no fileno() method: {}".format(fd))
if not isinstance(fd, int):
raise TypeError("fds key is not an int: {}".format(fd))
val = fds[fd]
if not isinstance(val, str) and not getattr(val, "fileno"):
raise TypeError("fds key is not an int and has no fileno() method: {}".format(val))
if not good_fd(val):
raise TypeError("fds val is not None or an int and has no fileno() method: {}".format(val))
if not is_on_path("supervise", path=env.get("PATH") or os.environ["PATH"]):
raise ValueError("supervise utility not found in path")

Expand Down

0 comments on commit 0809313

Please sign in to comment.