Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install/bin/stdin-killer: macOs (Darwin) compatibility #1895

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions teuthology/task/install/bin/stdin-killer
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ NAME = "stdin-killer"
log = logging.getLogger(NAME)
PAGE_SIZE = 4096

POLL_HANGUP = select.POLLHUP | select.POLLRDHUP | select.POLLERR
POLL_HANGUP = select.POLLHUP | (select.POLLRDHUP if hasattr(select, 'POLLRDHUP') else 0) | select.POLLERR


def handle_event(poll, buffer, fd, event, p):
Expand Down Expand Up @@ -149,7 +149,17 @@ def listen_for_events(sigfdr, p, timeout):

if __name__ == "__main__":
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
(sigfdr, sigfdw) = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC)
try:
(sigfdr, sigfdw) = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC)
except AttributeError:
# pipe2 is only available on "some flavors of Unix"
# https://docs.python.org/3.10/library/os.html?highlight=pipe2#os.pipe2
pipe_ends = os.pipe()
for fd in pipe_ends:
flags = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK | os.O_CLOEXEC)
(sigfdr, sigfdw) = pipe_ends

signal.set_wakeup_fd(sigfdw)

def do_nothing(signum, frame):
Expand Down
Loading