Skip to content
Commit d9765a4c authored by Nick Kralevich's avatar Nick Kralevich
Browse files

fd_utils: carry over O_CLOEXEC on duplicated FDs

Due to b/30963384, every time zygote creates a new child, zygote reopens
all existing file descriptors, taking careful measures to preserve the
file status flags, file descriptor flags, and seek offset. However, dup2
resets the sole file descriptor flag (FD_CLOEXEC) on duplication,
defeating the hard work done to preserve the flag.

From "man dup"

  NAME
    dup, dup2, dup3 - duplicate a file descriptor

  DESCRIPTION
    The dup() system call creates a copy ...
    ...
    The two file descriptors do not share file descriptor flags
    (the  close-on-exec flag).  The close-on-exec flag
    (FD_CLOEXEC; see fcntl(2)) for the duplicate descriptor is off.
    ...
    The  dup2() system call performs the same task as dup() ...

Use dup3 instead to allow us to preserve the FD_CLOEXEC status.

Bug: 120983106
Test: Android compiles and boots
Change-Id: Idbb27c83092f30d8394c254cfbdf33406f74eb94
parent 1d709c96
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment