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
1 changed files with 11 additions and 15 deletions

View File

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