X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Frelayd%2Frelayd.c;h=9e10c83e02f7ec583bff72cd5b6d70b42870dca1;hb=ffe600149a7608221985751e1bf293234bf2545c;hp=c883ea5d7f44432ead4ecbc614f8a8abc52686b1;hpb=bb63afd9d236f8aa96935ce21f415d76452187e2;p=lttng-tools.git diff --git a/src/common/relayd/relayd.c b/src/common/relayd/relayd.c index c883ea5d7..9e10c83e0 100644 --- a/src/common/relayd/relayd.c +++ b/src/common/relayd/relayd.c @@ -90,8 +90,16 @@ static int recv_reply(struct lttcomm_sock *sock, void *data, size_t size) DBG3("Relayd waiting for reply of size %ld", size); ret = sock->ops->recvmsg(sock, data, size, 0); - if (ret < 0) { - ret = -errno; + if (ret <= 0 || ret != size) { + if (ret == 0) { + /* Orderly shutdown. */ + DBG("Socket %d has performed an orderly shutdown", sock->fd); + } else { + DBG("Receiving reply failed on sock %d for size %lu with ret %d", + sock->fd, size, ret); + } + /* Always return -1 here and the caller can use errno. */ + ret = -1; goto error; } @@ -103,8 +111,8 @@ error: * Send a RELAYD_CREATE_SESSION command to the relayd with the given socket and * set session_id of the relayd if we have a successful reply from the relayd. * - * On success, return 0 else a negative value being a lttng_error_code returned - * from the relayd. + * On success, return 0 else a negative value which is either an errno error or + * a lttng error code from the relayd. */ int relayd_create_session(struct lttcomm_sock *sock, uint64_t *session_id) { @@ -122,7 +130,7 @@ int relayd_create_session(struct lttcomm_sock *sock, uint64_t *session_id) goto error; } - /* Recevie response */ + /* Receive response */ ret = recv_reply(sock, (void *) &reply, sizeof(reply)); if (ret < 0) { goto error; @@ -228,7 +236,7 @@ int relayd_version_check(struct lttcomm_sock *sock, uint32_t major, goto error; } - /* Recevie response */ + /* Receive response */ ret = recv_reply(sock, (void *) &msg, sizeof(msg)); if (ret < 0) { goto error; @@ -319,15 +327,44 @@ int relayd_connect(struct lttcomm_sock *sock) /* * Close relayd socket with an allocated lttcomm_sock. + * + * If no socket operations are found, simply return 0 meaning that everything + * is fine. Without operations, the socket can not possibly be opened or used. + * This is possible if the socket was allocated but not created. However, the + * caller could simply use it to store a valid file descriptor for instance + * passed over a Unix socket and call this to cleanup but still without a valid + * ops pointer. + * + * Return the close returned value. On error, a negative value is usually + * returned back from close(2). */ int relayd_close(struct lttcomm_sock *sock) { + int ret; + /* Code flow error. Safety net. */ assert(sock); + /* An invalid fd is fine, return success. */ + if (sock->fd < 0) { + ret = 0; + goto end; + } + DBG3("Relayd closing socket %d", sock->fd); - return sock->ops->close(sock); + if (sock->ops) { + ret = sock->ops->close(sock); + } else { + /* Default call if no specific ops found. */ + ret = close(sock->fd); + if (ret < 0) { + PERROR("relayd_close default close"); + } + } + +end: + return ret; } /* @@ -389,7 +426,7 @@ int relayd_send_close_stream(struct lttcomm_sock *sock, uint64_t stream_id, goto error; } - /* Recevie response */ + /* Receive response */ ret = recv_reply(sock, (void *) &reply, sizeof(reply)); if (ret < 0) { goto error; @@ -439,7 +476,7 @@ int relayd_data_pending(struct lttcomm_sock *sock, uint64_t stream_id, goto error; } - /* Recevie response */ + /* Receive response */ ret = recv_reply(sock, (void *) &reply, sizeof(reply)); if (ret < 0) { goto error; @@ -485,7 +522,7 @@ int relayd_quiescent_control(struct lttcomm_sock *sock, goto error; } - /* Recevie response */ + /* Receive response */ ret = recv_reply(sock, (void *) &reply, sizeof(reply)); if (ret < 0) { goto error; @@ -529,7 +566,7 @@ int relayd_begin_data_pending(struct lttcomm_sock *sock, uint64_t id) goto error; } - /* Recevie response */ + /* Receive response */ ret = recv_reply(sock, (void *) &reply, sizeof(reply)); if (ret < 0) { goto error; @@ -576,7 +613,7 @@ int relayd_end_data_pending(struct lttcomm_sock *sock, uint64_t id, goto error; } - /* Recevie response */ + /* Receive response */ ret = recv_reply(sock, (void *) &reply, sizeof(reply)); if (ret < 0) { goto error;