Skip to content

Commit

Permalink
Make syscalls explicit prior to SysCallResult init
Browse files Browse the repository at this point in the history
Signed-off-by: Venil Noronha <veniln@vmware.com>
  • Loading branch information
venilnoronha committed Jul 24, 2018
1 parent bb2841e commit 7e05d55
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions source/common/network/address_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,15 @@ bool Ipv4Instance::operator==(const Instance& rhs) const {
}

Api::SysCallResult Ipv4Instance::bind(int fd) const {
return {::bind(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv4_.address_),
sizeof(ip_.ipv4_.address_)),
errno};
const int rc = ::bind(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv4_.address_),
sizeof(ip_.ipv4_.address_));
return {rc, errno};
}

Api::SysCallResult Ipv4Instance::connect(int fd) const {
return {::connect(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv4_.address_),
sizeof(ip_.ipv4_.address_)),
errno};
const int rc = ::connect(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv4_.address_),
sizeof(ip_.ipv4_.address_));
return {rc, errno};
}

Api::SysCallResult Ipv4Instance::socket(SocketType type) const {
Expand Down Expand Up @@ -280,15 +280,15 @@ bool Ipv6Instance::operator==(const Instance& rhs) const {
}

Api::SysCallResult Ipv6Instance::bind(int fd) const {
return {::bind(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv6_.address_),
sizeof(ip_.ipv6_.address_)),
errno};
const int rc = ::bind(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv6_.address_),
sizeof(ip_.ipv6_.address_));
return {rc, errno};
}

Api::SysCallResult Ipv6Instance::connect(int fd) const {
return {::connect(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv6_.address_),
sizeof(ip_.ipv6_.address_)),
errno};
const int rc = ::connect(fd, reinterpret_cast<const sockaddr*>(&ip_.ipv6_.address_),
sizeof(ip_.ipv6_.address_));
return {rc, errno};
}

Api::SysCallResult Ipv6Instance::socket(SocketType type) const {
Expand Down Expand Up @@ -341,24 +341,26 @@ bool PipeInstance::operator==(const Instance& rhs) const { return asString() ==

Api::SysCallResult PipeInstance::bind(int fd) const {
if (abstract_namespace_) {
return {::bind(fd, reinterpret_cast<const sockaddr*>(&address_),
offsetof(struct sockaddr_un, sun_path) + address_length_),
errno};
const int rc = ::bind(fd, reinterpret_cast<const sockaddr*>(&address_),
offsetof(struct sockaddr_un, sun_path) + address_length_);
return {rc, errno};
}
// Try to unlink an existing filesystem object at the requested path. Ignore
// errors -- it's fine if the path doesn't exist, and if it exists but can't
// be unlinked then `::bind()` will generate a reasonable errno.
unlink(address_.sun_path);
return {::bind(fd, reinterpret_cast<const sockaddr*>(&address_), sizeof(address_)), errno};
const int rc = ::bind(fd, reinterpret_cast<const sockaddr*>(&address_), sizeof(address_));
return {rc, errno};
}

Api::SysCallResult PipeInstance::connect(int fd) const {
if (abstract_namespace_) {
return {::connect(fd, reinterpret_cast<const sockaddr*>(&address_),
offsetof(struct sockaddr_un, sun_path) + address_length_),
errno};
const int rc = ::connect(fd, reinterpret_cast<const sockaddr*>(&address_),
offsetof(struct sockaddr_un, sun_path) + address_length_);
return {rc, errno};
}
return {::connect(fd, reinterpret_cast<const sockaddr*>(&address_), sizeof(address_)), errno};
const int rc = ::connect(fd, reinterpret_cast<const sockaddr*>(&address_), sizeof(address_));
return {rc, errno};
}

Api::SysCallResult PipeInstance::socket(SocketType type) const {
Expand Down

0 comments on commit 7e05d55

Please sign in to comment.