Fix c10d checking errno unconditionally (#15986)
authorSsnL <tongzhou.wang.1994@gmail.com>
Mon, 14 Jan 2019 23:59:29 +0000 (15:59 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 15 Jan 2019 00:02:05 +0000 (16:02 -0800)
commit774705ba0509878cb2e8141b52164d090bfef5d7
treec08f3d26c89fad906bd50c31aa2c8f370e5f2fc5
parent4fb39318963fd6ac64d4fc312d850004858641da
Fix c10d checking errno unconditionally (#15986)

Summary:
In #15964, I learned that `errno` is only meaningful if the function call fails. E.g., on some macos, a successful `fork()` sets `errno` to `EINVAL` in child process. This commit changes the `SYSCALL` macro so error checking is only done when an error happens. This means checking whether `rv == -1` for most calls, but is checking `rv == nullptr` for `inet_ntop`.

Now `SYSCALL` accepts a second argument `success_cond`, which should be an expression returning whether the call succeeded. `SYSCHECK_ERR_RETURN_NEG1` is the shorthand for checking if rv is `-1`.

Any suggestion on better macro names is welcomed.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/15986

Reviewed By: janewangfb

Differential Revision: D13661790

Pulled By: pietern

fbshipit-source-id: 9551b14b9f88805454a7bfb8e4d39e0f3aed8131
torch/lib/c10d/TCPStore.cpp
torch/lib/c10d/Utils.cpp
torch/lib/c10d/Utils.hpp