Skip to content

Commit

Permalink
Fix -d fd option
Browse files Browse the repository at this point in the history
If -d was 4, then it would match the fd of write_pipe, dup2 would be
a no-op and the file descriptor wouldn't be inherited. Fixed by special
casing fd == write_pipe.
  • Loading branch information
holesch committed Jan 30, 2024
1 parent 602f65b commit 8337590
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions sdnotify_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ def main():
return run_child(read_pipe, args.timeout_ms, main_pid)

os.close(read_pipe)
os.dup2(write_pipe, args.fd)
os.close(write_pipe)

if write_pipe == args.fd:
# by default pipes aren't inheritable
os.set_inheritable(write_pipe, True)
else:
os.dup2(write_pipe, args.fd)
os.close(write_pipe)

if not args.keep:
del os.environ["NOTIFY_SOCKET"]
Expand All @@ -59,7 +64,7 @@ def parse(cls):
init_args = {}
for opt, arg in opts:
if opt == "-d":
init_args["fd"] = arg
init_args["fd"] = int(arg)
elif opt == "-f":
init_args["fork_once"] = True
elif opt == "-t":
Expand Down

0 comments on commit 8337590

Please sign in to comment.