diff --git a/src/dinit-iostream.cc b/src/dinit-iostream.cc index 930a26a1..a9eb94fa 100644 --- a/src/dinit-iostream.cc +++ b/src/dinit-iostream.cc @@ -73,20 +73,13 @@ ssize_t ostream::put(const char *msg, size_t count) noexcept // io_error was set by flush_nx() call return -1; } - while (count > static_cast(buf->get_free())) { - int prev_freespace = buf->get_free(); - buf->append(msg, prev_freespace); - msg += prev_freespace; - output_count += prev_freespace; - count -= prev_freespace; - bool r = flush_nx(); - if (!r) { - // io_error was set by flush_nx() call - return (output_count > 0) ? output_count : -1; - } + // It's better to write the whole message. + ssize_t res = bp_sys::write(get_fd(), msg, count); + // Note: Set io_error on both -1 and partial write. + if (res < count) { + io_error = errno; } - buf->append(msg, count); - return output_count + count; + return res; } while (count > static_cast(buf->get_free())) { // If we haven't enough storage for caputring the message Firstly we try to fill buffer as