From 75e3580b52ba630ef980e9f387bfdcdb433a4cf0 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 15 Oct 2019 11:04:56 +0200 Subject: [PATCH] printer: ignore EAGAIN and EINTR errno in callback When using libnetconf2 via the UNIX or FD transport and sending large configs, we can get the following error from libyang: Print error (Resource temporarily unavailable). Do not fail when errno holds EAGAIN or EINTR. These are not errors. This can occur when using ly_print_clb with a callback that does I/O on a non-blocking file or if the application received a signal during the write syscall. If the callback function returns a zero or positive value, reset errno so that LY_PRINT_RET does not return an error. Fixes: 609d708ca567 ("printer CHANGE use errno to check for printer errors") Signed-off-by: Robin Jarry --- src/printer.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/printer.c b/src/printer.c index 9b940bf71..0301ec00c 100644 --- a/src/printer.c +++ b/src/printer.c @@ -127,6 +127,15 @@ ly_print(struct lyout *out, const char *format, ...) case LYOUT_CALLBACK: count = vasprintf(&msg, format, ap); count = out->method.clb.f(out->method.clb.arg, msg, count); + if (count >= 0) { + /* + * Depending on what the callback function does, errno might + * contain non-zero values that are not real "errors" (EAGAIN or + * EINTR). Reset errno if the callback returns a zero or positive + * value. + */ + errno = 0; + } free(msg); break; }