File pacemaker-meaningful-error-codes-sending-remote-messages.patch of Package pacemaker.14737

commit 170d63cc959ea61d28e90e85ee3b94c9e2530229
Author: Ken Gaillot <kgaillot@redhat.com>
Date:   Thu Oct 26 12:35:56 2017 -0500

    Low: libcrmcommon,lrmd: meaningful error codes when sending remote messages
    
    On error, functions for sending remote messages were inconsistent about return
    codes, sometimes using -1, sometimes using -errno, and sometimes using GnuTLS
    error codes. Now, they always use -errno.

diff --git a/lib/common/remote.c b/lib/common/remote.c
index 192e5f089..a3e472003 100644
--- a/lib/common/remote.c
+++ b/lib/common/remote.c
@@ -230,7 +230,7 @@ crm_send_tls(gnutls_session_t * session, const char *buf, size_t len)
     int total_send;
 
     if (buf == NULL) {
-        return -1;
+        return -EINVAL;
     }
 
     total_send = len;
@@ -246,6 +246,7 @@ crm_send_tls(gnutls_session_t * session, const char *buf, size_t len)
         } else if (rc < 0) {
             crm_err("Connection terminated: %s " CRM_XS " rc=%d",
                     gnutls_strerror(rc), rc);
+            rc = -ECONNABORTED;
             break;
 
         } else if (rc < len) {
@@ -271,7 +272,7 @@ crm_send_plaintext(int sock, const char *buf, size_t len)
     int total_send;
 
     if (buf == NULL) {
-        return -1;
+        return -EINVAL;
     }
     total_send = len;
 
@@ -280,6 +281,7 @@ crm_send_plaintext(int sock, const char *buf, size_t len)
   retry:
     rc = write(sock, unsent, len);
     if (rc < 0) {
+        rc = -errno;
         switch (errno) {
             case EINTR:
             case EAGAIN:
@@ -332,7 +334,7 @@ crm_remote_sendv(crm_remote_t * remote, struct iovec * iov, int iovs)
 int
 crm_remote_send(crm_remote_t * remote, xmlNode * msg)
 {
-    int rc = -1;
+    int rc = pcmk_ok;
     static uint64_t id = 0;
     char *xml_text = dump_xml_unformatted(msg);
 
@@ -341,7 +343,7 @@ crm_remote_send(crm_remote_t * remote, xmlNode * msg)
 
     if (xml_text == NULL) {
         crm_err("Invalid XML, can not send msg");
-        return -1;
+        return -EINVAL;
     }
 
     header = calloc(1, sizeof(struct crm_remote_header_v0));
diff --git a/lrmd/main.c b/lrmd/main.c
index 9670015a1..0a4ce3915 100644
--- a/lrmd/main.c
+++ b/lrmd/main.c
@@ -235,7 +235,7 @@ lrmd_server_send_reply(crm_client_t * client, uint32_t id, xmlNode * reply)
         default:
             crm_err("Unknown lrmd client type %d", client->kind);
     }
-    return -1;
+    return -ENOTCONN;
 }
 
 int
@@ -246,21 +246,21 @@ lrmd_server_send_notify(crm_client_t * client, xmlNode * msg)
         case CRM_CLIENT_IPC:
             if (client->ipcs == NULL) {
                 crm_trace("Asked to send event to disconnected local client");
-                return -1;
+                return -ENOTCONN;
             }
             return crm_ipcs_send(client, 0, msg, crm_ipc_server_event);
 #ifdef ENABLE_PCMK_REMOTE
         case CRM_CLIENT_TLS:
             if (client->remote == NULL) {
                 crm_trace("Asked to send event to disconnected remote client");
-                return -1;
+                return -ENOTCONN;
             }
             return lrmd_tls_send_msg(client->remote, msg, 0, "notify");
 #endif
         default:
             crm_err("Unknown lrmd client type %d", client->kind);
     }
-    return -1;
+    return -ENOTCONN;
 }
 
 /*!
openSUSE Build Service is sponsored by