~ubuntu-branches/ubuntu/vivid/mir/vivid

« back to all changes in this revision

Viewing changes to src/common/fd/fd_socket_transmission.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-11-20 16:41:15 UTC
  • mto: This revision was merged to the branch mainline in revision 86.
  • Revision ID: package-import@ubuntu.com-20141120164115-a3j4vq6cq2u78m47
Tags: upstream-0.9.0+15.04.20141120.1
ImportĀ upstreamĀ versionĀ 0.9.0+15.04.20141120.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
{
36
36
}
37
37
 
38
 
mir::fd_reception_error::fd_reception_error() :
39
 
    std::runtime_error("Invalid control message for receiving file descriptors")
 
38
mir::fd_reception_error::fd_reception_error(std::string const& message) :
 
39
    std::runtime_error(message)
40
40
{
41
41
}
42
42
 
81
81
        for (auto& fd : fds)
82
82
            data[i++] = fd;
83
83
 
84
 
        auto const sent = sendmsg(socket, &header, 0);
 
84
        auto const sent = sendmsg(socket, &header, MSG_NOSIGNAL);
85
85
        if (sent < 0)
86
86
            BOOST_THROW_EXCEPTION(std::runtime_error("Failed to send fds: " + std::string(strerror(errno))));
87
87
    }
129
129
        {
130
130
            if (socket_error_is_transient(errno))
131
131
                continue;
 
132
            if (errno == EAGAIN)
 
133
                continue;
132
134
            if (errno == EPIPE)
133
135
                BOOST_THROW_EXCEPTION(
134
136
                    boost::enable_error_info(socket_disconnected_error("Failed to read message from server"))
149
151
            // NOTE: This relies on the file descriptor cmsg being read
150
152
            // (and written) atomically.
151
153
            if (cmsg->cmsg_len > CMSG_LEN(fds_bytes) || (header.msg_flags & MSG_CTRUNC))
152
 
            {
153
154
                BOOST_THROW_EXCEPTION(std::runtime_error("Received more fds than expected"));
154
 
            }
 
155
            if ((cmsg->cmsg_level == SOL_SOCKET) && (cmsg->cmsg_type == SCM_CREDENTIALS))
 
156
                BOOST_THROW_EXCEPTION(fd_reception_error("received SCM_CREDENTIALS when expecting fd"));
155
157
            if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
156
 
            {
157
 
                BOOST_THROW_EXCEPTION(fd_reception_error());
158
 
            }
 
158
                BOOST_THROW_EXCEPTION(fd_reception_error("Invalid control message for receiving file descriptors"));
159
159
            int const* const data = reinterpret_cast<int const*>CMSG_DATA(cmsg);
160
160
            ptrdiff_t const header_size = reinterpret_cast<char const*>(data) - reinterpret_cast<char const*>(cmsg);
161
161
            int const nfds = (cmsg->cmsg_len - header_size) / sizeof(int);