In all paths errors from this function are treated like fatal error, there's no need to handle all manually potentially forgetting to handle errors. Also avoid to deal directly with logging moving the responsibility to other layers. Signed-off-by: Frediano Ziglio <fziglio@xxxxxxxxxx> --- src/spice-streaming-agent.cpp | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/spice-streaming-agent.cpp b/src/spice-streaming-agent.cpp index 1f41a6f..08f4b48 100644 --- a/src/spice-streaming-agent.cpp +++ b/src/spice-streaming-agent.cpp @@ -37,6 +37,7 @@ #include "hexdump.h" #include "concrete-agent.hpp" #include "mjpeg-fallback.hpp" +#include "utils.hpp" using namespace spice::streaming_agent; @@ -86,32 +87,21 @@ static int read_command_from_device(void) std::lock_guard<std::mutex> stream_guard(stream_mtx); n = read(streamfd, &hdr, sizeof(hdr)); if (n != sizeof(hdr)) { - syslog(LOG_WARNING, - "read command from device FAILED -- read %d expected %lu\n", - n, sizeof(hdr)); - return -1; + ERROR("read command from device FAILED -- read " << n << " expected " << sizeof(hdr)); } if (hdr.protocol_version != STREAM_DEVICE_PROTOCOL) { - syslog(LOG_WARNING, "BAD VERSION %d (expected is %d)\n", hdr.protocol_version, - STREAM_DEVICE_PROTOCOL); - return -1; + ERROR("BAD VERSION " << hdr.protocol_version << + " (expected is " << STREAM_DEVICE_PROTOCOL << ")"); } if (hdr.type != STREAM_TYPE_START_STOP) { - syslog(LOG_WARNING, "UNKNOWN msg of type %d\n", hdr.type); - return -1; + ERROR("UNKNOWN msg of type " << hdr.type); } if (hdr.size >= sizeof(msg)) { - syslog(LOG_WARNING, - "msg size (%d) is too long (longer than %lu)\n", - hdr.size, sizeof(msg)); - return -1; + ERROR("msg size (" << hdr.size << ") is too long (longer than " << sizeof(msg)); } n = read(streamfd, &msg, hdr.size); if (n != hdr.size) { - syslog(LOG_WARNING, - "read command from device FAILED -- read %d expected %d\n", - n, hdr.size); - return -1; + ERROR("read command from device FAILED -- read " << n << " expected " << hdr.size); } streaming_requested = (msg[0] != 0); /* num_codecs */ syslog(LOG_INFO, "GOT START_STOP message -- request to %s streaming\n", -- 2.14.3 _______________________________________________ Spice-devel mailing list Spice-devel@xxxxxxxxxxxxxxxxxxxxx https://lists.freedesktop.org/mailman/listinfo/spice-devel