File pacemaker-report-meaningful-async-connection-errors.patch of Package pacemaker.8397
commit 459e71b2d6537fe308ca1533634f38129dee1557
Author: Ken Gaillot <kgaillot@redhat.com>
Date: Wed Oct 25 17:49:53 2017 -0500
Low: libcrmcommon,liblrmd: report meaningful async connection errors
For errors, report_async_connection_result() would set connection_rc to -errno
sometimes, and -1 other times. Now, it always uses -errno.
diff --git a/lib/common/remote.c b/lib/common/remote.c
index 3f423e5cb..c84238dc2 100644
--- a/lib/common/remote.c
+++ b/lib/common/remote.c
@@ -835,13 +835,21 @@ internal_tcp_connect(int sock, const struct sockaddr *addr, socklen_t addrlen)
/*!
* \internal
- * \brief tcp connection to server at specified port
- * \retval negative, failed to connect.
- * \retval positive, sock fd
+ * \brief Connect to server at specified TCP port
+ *
+ * \param[in] host Name of server to connect to
+ * \param[in] port Server port to connect to
+ * \param[in] timeout Report error if not connected in this many milliseconds
+ * \param[out] timer_id If non-NULL, will be set to timer ID, if asynchronous
+ * \param[in] userdata Data to pass to callback, if asynchronous
+ * \param[in] callback If non-NULL, connect asynchronously then call this
+ *
+ * \return File descriptor of connected socket on success, -ENOTCONN otherwise
*/
int
-crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */
- int *timer_id, void *userdata, void (*callback) (void *userdata, int sock))
+crm_remote_tcp_connect_async(const char *host, int port, int timeout,
+ int *timer_id, void *userdata,
+ void (*callback) (void *userdata, int sock))
{
char buffer[INET6_ADDRSTRLEN];
struct addrinfo *res = NULL;
@@ -849,7 +857,7 @@ crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */
struct addrinfo hints;
const char *server = host;
int ret_ga;
- int sock = -1;
+ int sock = -ENOTCONN;
// Get host's IP address(es)
memset(&hints, 0, sizeof(struct addrinfo));
@@ -884,6 +892,7 @@ crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */
if (sock == -1) {
crm_perror(LOG_WARNING, "creating socket for connection to %s",
server);
+ sock = -ENOTCONN;
continue;
}
@@ -910,7 +919,7 @@ crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */
}
close(sock);
- sock = -1;
+ sock = -ENOTCONN;
}
async_cleanup:
diff --git a/lib/lrmd/lrmd_client.c b/lib/lrmd/lrmd_client.c
index 828133bc3..44b7f2ace 100644
--- a/lib/lrmd/lrmd_client.c
+++ b/lib/lrmd/lrmd_client.c
@@ -1078,27 +1078,23 @@ set_key(gnutls_datum_t * key, const char *location)
int
lrmd_tls_set_key(gnutls_datum_t * key)
{
- int rc = 0;
const char *specific_location = getenv("PCMK_authkey_location");
if (set_key(key, specific_location) == 0) {
crm_debug("Using custom authkey location %s", specific_location);
- return 0;
+ return pcmk_ok;
} else if (specific_location) {
crm_err("No valid lrmd remote key found at %s, trying default location", specific_location);
}
- if (set_key(key, DEFAULT_REMOTE_KEY_LOCATION) != 0) {
- rc = set_key(key, ALT_REMOTE_KEY_LOCATION);
- }
-
- if (rc) {
+ if ((set_key(key, DEFAULT_REMOTE_KEY_LOCATION) != 0)
+ && (set_key(key, ALT_REMOTE_KEY_LOCATION) != 0)) {
crm_err("No valid lrmd remote key found at %s", DEFAULT_REMOTE_KEY_LOCATION);
- return -1;
+ return -ENOKEY;
}
- return rc;
+ return pcmk_ok;
}
static void
@@ -1179,7 +1175,7 @@ lrmd_tcp_connect_cb(void *userdata, int sock)
gnutls_free(native->remote->tls_session);
native->remote->tls_session = NULL;
lrmd_tls_connection_destroy(lrmd);
- report_async_connection_result(lrmd, -1);
+ report_async_connection_result(lrmd, -EKEYREJECTED);
return;
}
@@ -1224,6 +1220,7 @@ lrmd_tls_connect(lrmd_t * lrmd, int *fd)
.dispatch = lrmd_tls_dispatch,
.destroy = lrmd_tls_connection_destroy,
};
+ int rc;
lrmd_private_t *native = lrmd->private;
int sock;
@@ -1240,9 +1237,10 @@ lrmd_tls_connect(lrmd_t * lrmd, int *fd)
native->sock = sock;
- if (lrmd_tls_set_key(&psk_key) != 0) {
+ rc = lrmd_tls_set_key(&psk_key);
+ if (rc < 0) {
lrmd_tls_connection_destroy(lrmd);
- return -1;
+ return rc;
}
gnutls_psk_allocate_client_credentials(&native->psk_cred_c);
@@ -1257,7 +1255,7 @@ lrmd_tls_connect(lrmd_t * lrmd, int *fd)
gnutls_free(native->remote->tls_session);
native->remote->tls_session = NULL;
lrmd_tls_connection_destroy(lrmd);
- return -1;
+ return -EKEYREJECTED;
}
crm_info("Remote lrmd client TLS connection established with server %s:%d", native->server,