fix(ipc): Always close file descriptor on receive

This commit is contained in:
Michael Carlberg 2017-01-09 23:09:16 +01:00
parent 7a26254844
commit 0f0d786cbd

View File

@ -59,12 +59,7 @@ void ipc::receive_message() {
if ((bytes_read = read(*m_fd, &buffer, BUFSIZ)) == -1) { if ((bytes_read = read(*m_fd, &buffer, BUFSIZ)) == -1) {
m_log.err("Failed to read from ipc channel (err: %s)", strerror(errno)); m_log.err("Failed to read from ipc channel (err: %s)", strerror(errno));
} } else if (bytes_read > 0) {
if (!bytes_read) {
return;
}
string payload{string_util::trim(string{buffer}, '\n')}; string payload{string_util::trim(string{buffer}, '\n')};
if (payload.find(ipc_command::prefix) == 0) { if (payload.find(ipc_command::prefix) == 0) {
@ -76,6 +71,7 @@ void ipc::receive_message() {
} else if (!payload.empty()) { } else if (!payload.empty()) {
m_log.warn("Received unknown ipc message: (payload=%s)", payload); m_log.warn("Received unknown ipc message: (payload=%s)", payload);
} }
}
m_fd = file_util::make_file_descriptor(m_path, O_RDONLY | O_NONBLOCK); m_fd = file_util::make_file_descriptor(m_path, O_RDONLY | O_NONBLOCK);
} }