• Jonathan Nieder's avatar
    unix-socket: do not let close() or chdir() clobber errno during cleanup · 06121a0a
    Jonathan Nieder authored
    unix_stream_connect and unix_stream_listen return -1 on error, with
    errno set by the failing underlying call to allow the caller to write
    a useful diagnosis.
    
    Unfortunately the error path involves a few system calls itself, such
    as close(), that can themselves touch errno.
    
    This is not as worrisome as it might sound.  If close() fails, this
    just means substituting one meaningful error message for another,
    which is perfectly fine.  However, when the call _succeeds_, it is
    allowed to (and sometimes might) clobber errno along the way with some
    undefined value, so it is good higiene to save errno and restore it
    immediately before returning to the caller.  Do so.
    Signed-off-by: default avatarJonathan Nieder <[email protected]>
    Signed-off-by: default avatarJunio C Hamano <[email protected]>
    06121a0a
unix-socket.c 2.36 KB