Skip to content
  • Dan McGee's avatar
    Use O_CLOEXEC as much as possible when opening files · 086bbc5b
    Dan McGee authored and Allan McRae's avatar Allan McRae committed
    
    
    When calling open(), use O_CLOEXEC as much as possible to ensure the
    file descriptor is closed when and if a process using libalpm forks.
    
    For most of these cases, and especially in utility functions, the file
    descriptor is opened and closed in the same function, so we don't have
    too much to worry about. However, for things like the log file and
    database lock file, we should ensure descriptors aren't left hanging
    around for children to touch.
    
    This patch is inspired by the problem in FS#36161, where an open file
    descriptor to the current working directory prevents chroot() from
    working on FreeBSD. We don't need this file descriptor in the child
    process, so open it (and now several others) with O_CLOEXEC.
    
    Signed-off-by: default avatarDan McGee <dan@archlinux.org>
    Signed-off-by: default avatarAllan McRae <allan@archlinux.org>
    086bbc5b