2fb7500 Do not leak fds in case of failures setting up a child process

Authored and Committed by jhrozek 7 years ago
    Do not leak fds in case of failures setting up a child process
    
    Resolves:
        https://fedorahosted.org/sssd/ticket/3006
    
    The handling of open pipes in failure cases was suboptimal. Moreover,
    the faulty logic was copied all over the place. This patch introduces
    helper macros to:
        - initialize the pipe endpoints to -1
        - close an open pipe fd and set it to -1 afterwards
        - close both ends unless already closed
    These macros are used in the child handling code.
    
    The patch also uses child_io_destructor in the p11_child code for safer
    fd handling.
    
    Reviewed-by: Petr Cech <pcech@redhat.com>
    
        
file modified
+19 -17
file modified
+11 -5
file modified
+15 -12
file modified
+25 -19
file modified
+14 -0