Commit 769cac66 authored by Marcin Siodelski's avatar Marcin Siodelski

[3461] Addressed review comments.

parent b22d5d37
// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") // Copyright (C) 2010, 2014 Internet Systems Consortium, Inc. ("ISC")
// //
// Permission to use, copy, modify, and/or distribute this software for any // Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above // purpose with or without fee is hereby granted, provided that the above
...@@ -107,13 +107,15 @@ recv_fd(const int sock) { ...@@ -107,13 +107,15 @@ recv_fd(const int sock) {
std::memcpy(&fd, CMSG_DATA(cmsg), sizeof(int)); std::memcpy(&fd, CMSG_DATA(cmsg), sizeof(int));
} }
free(msghdr.msg_control); free(msghdr.msg_control);
// It is strange, but the call can return the same file descriptor as int new_fd = -1;
// one returned previously, even if that one is not closed yet. So, int close_error = -1;
// we just re-number every one we get, so they are unique. if (fd >= 0) {
int new_fd(dup(fd)); // It is strange, but the call can return the same file descriptor as
// Only call close() if the descriptor is valid. Otherwise return // one returned previously, even if that one is not closed yet. So,
// an error. // we just re-number every one we get, so they are unique.
int close_error(fd >=0 ? close(fd) : -1); new_fd = dup(fd);
close_error = close(fd);
}
if (close_error == -1 || new_fd == -1) { if (close_error == -1 || new_fd == -1) {
// We need to return an error, because something failed. But in case // We need to return an error, because something failed. But in case
// it was the previous close, we at least try to close the duped FD. // it was the previous close, we at least try to close the duped FD.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment