if (code >= LTTNG_UST_ERR_NR)
code = LTTNG_UST_ERR;
return ustcomm_readable_code[USTCOMM_CODE_OFFSET(code)];
-
}
/*
ret = connect(fd, (struct sockaddr *) &sun, sizeof(sun));
if (ret < 0) {
/*
- * Don't print message on connect error, because connect
- * is used in normal execution to detect if sessiond is
- * alive.
+ * Don't print message on connect ENOENT error, because
+ * connect is used in normal execution to detect if
+ * sessiond is alive. ENOENT is when the unix socket
+ * file does not exist, and ECONNREFUSED is when the
+ * file exists but no sessiond is listening.
*/
+ if (errno != ECONNREFUSED && errno != ECONNRESET
+ && errno != ENOENT)
+ PERROR("connect");
ret = -errno;
+ if (ret == -ECONNREFUSED || ret == -ECONNRESET)
+ ret = -EPIPE;
goto error_connect;
}
/* Blocking call */
new_fd = accept(sock, (struct sockaddr *) &sun, &len);
if (new_fd < 0) {
- PERROR("accept");
- return -errno;
+ if (errno != ECONNABORTED)
+ PERROR("accept");
+ new_fd = -errno;
+ if (new_fd == -ECONNABORTED)
+ new_fd = -EPIPE;
}
return new_fd;
}
if (ret < 0) {
int shutret;
- if (errno != EPIPE && errno != ECONNRESET)
+ if (errno != EPIPE && errno != ECONNRESET && errno != ECONNREFUSED)
PERROR("recvmsg");
ret = -errno;
+ if (ret == -ECONNRESET || ret == -ECONNREFUSED)
+ ret = -EPIPE;
shutret = shutdown(sock, SHUT_RDWR);
if (shutret)
if (errno != EPIPE && errno != ECONNRESET)
PERROR("sendmsg");
ret = -errno;
+ if (ret == -ECONNRESET)
+ ret = -EPIPE;
shutret = shutdown(sock, SHUT_RDWR);
if (shutret)
if (errno != EPIPE && errno != ECONNRESET) {
PERROR("sendmsg");
}
+ ret = -errno;
+ if (ret == -ECONNRESET)
+ ret = -EPIPE;
}
return ret;
}
if (errno != EPIPE && errno != ECONNRESET) {
PERROR("recvmsg fds");
}
- if (errno == EPIPE || errno == ECONNRESET)
- ret = -errno;
+ ret = -errno;
+ if (ret == -ECONNRESET)
+ ret = -EPIPE;
goto end;
}
if (ret == 0) {
}
return lur->ret_code;
default:
- if (len < 0) {
- /* Transport level error */
- if (errno == EPIPE || errno == ECONNRESET)
- len = -errno;
- return len;
- } else {
+ if (len >= 0) {
ERR("incorrect message size: %zd\n", len);
- return len;
}
+ return len;
}
}
}
}
}
+
+/*
+ * Set socket reciving timeout.
+ */
+int ustcomm_setsockopt_rcv_timeout(int sock, unsigned int msec)
+{
+ int ret;
+ struct timeval tv;
+
+ tv.tv_sec = msec / 1000;
+ tv.tv_usec = (msec * 1000 % 1000000);
+
+ ret = setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
+ if (ret < 0) {
+ PERROR("setsockopt SO_RCVTIMEO");
+ ret = -errno;
+ }
+
+ return ret;
+}
+
+/*
+ * Set socket sending timeout.
+ */
+int ustcomm_setsockopt_snd_timeout(int sock, unsigned int msec)
+{
+ int ret;
+ struct timeval tv;
+
+ tv.tv_sec = msec / 1000;
+ tv.tv_usec = (msec * 1000) % 1000000;
+
+ ret = setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
+ if (ret < 0) {
+ PERROR("setsockopt SO_SNDTIMEO");
+ ret = -errno;
+ }
+
+ return ret;
+}