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;
}
}
* expected var_len.
*/
ssize_t ustcomm_recv_channel_from_sessiond(int sock,
- void **_chan_data, uint64_t var_len)
+ void **_chan_data, uint64_t var_len,
+ int *_wakeup_fd)
{
void *chan_data;
- ssize_t len;
+ ssize_t len, nr_fd;
+ int wakeup_fd;
if (var_len > LTTNG_UST_CHANNEL_DATA_MAX_LEN) {
len = -EINVAL;
if (len != var_len) {
goto error_recv;
}
+ /* recv wakeup fd */
+ nr_fd = ustcomm_recv_fds_unix_sock(sock, &wakeup_fd, 1);
+ if (nr_fd <= 0) {
+ if (nr_fd < 0) {
+ len = nr_fd;
+ goto error_recv;
+ } else {
+ len = -EIO;
+ goto error_recv;
+ }
+ }
+ *_wakeup_fd = wakeup_fd;
*_chan_data = chan_data;
return len;
}
static
-int serialize_basic_type(enum lttng_abstract_types atype,
+int serialize_basic_type(enum ustctl_abstract_types *uatype,
+ enum lttng_abstract_types atype,
union _ustctl_basic_type *ubt,
const union _lttng_basic_type *lbt)
{
uit->base = lit->base;
uit->encoding = lit->encoding;
uit->alignment = lit->alignment;
+ *uatype = ustctl_atype_integer;
break;
}
case atype_string:
{
ubt->string.encoding = lbt->string.encoding;
+ *uatype = ustctl_atype_string;
break;
}
case atype_float:
uft->mant_dig = lft->mant_dig;
uft->alignment = lft->alignment;
uft->reverse_byte_order = lft->reverse_byte_order;
+ *uatype = ustctl_atype_float;
break;
}
case atype_enum:
return -EINVAL;
}
return 0;
-
}
static
case atype_integer:
case atype_float:
case atype_string:
- ret = serialize_basic_type(lt->atype,
+ ret = serialize_basic_type(&ut->atype, lt->atype,
&ut->u.basic, <->u.basic);
if (ret)
return ret;
ubt = &ut->u.array.elem_type;
lbt = <->u.array.elem_type;
ut->u.array.length = lt->u.array.length;
- ret = serialize_basic_type(lbt->atype,
+ ret = serialize_basic_type(&ubt->atype, lbt->atype,
&ubt->u.basic, &lbt->u.basic);
if (ret)
return -EINVAL;
+ ut->atype = ustctl_atype_array;
break;
}
case atype_sequence:
ubt = &ut->u.sequence.length_type;
lbt = <->u.sequence.length_type;
- ret = serialize_basic_type(lbt->atype,
+ ret = serialize_basic_type(&ubt->atype, lbt->atype,
&ubt->u.basic, &lbt->u.basic);
if (ret)
return -EINVAL;
ubt = &ut->u.sequence.elem_type;
lbt = <->u.sequence.elem_type;
- ret = serialize_basic_type(lbt->atype,
+ ret = serialize_basic_type(&ubt->atype, lbt->atype,
&ubt->u.basic, &lbt->u.basic);
if (ret)
return -EINVAL;
+ ut->atype = ustctl_atype_sequence;
break;
}
case atype_enum:
}
}
}
+
+/*
+ * 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;
+}