X-Git-Url: http://git.efficios.com/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Frelayd%2Frelayd.c;h=9e10c83e02f7ec583bff72cd5b6d70b42870dca1;hp=63a55c22756fd8737c00cb0158bdbb5a01b7c007;hb=ffe600149a7608221985751e1bf293234bf2545c;hpb=ccf7af6c78ba7a206baa9d0b9578468a1af734e1 diff --git a/src/common/relayd/relayd.c b/src/common/relayd/relayd.c index 63a55c227..9e10c83e0 100644 --- a/src/common/relayd/relayd.c +++ b/src/common/relayd/relayd.c @@ -327,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; } /*