X-Git-Url: http://git.lttng.org./?a=blobdiff_plain;f=liblttng-ust-comm%2Flttng-ust-comm.c;h=087424fe66626a6dd393315ccb3fa896c54322ff;hb=725e63c5194bfdcde0a2a3507aca156ba36cf49f;hp=5d7a049b11568f620bd661c0a2dc73c8567f74d5;hpb=b869b5ae63308b47d929a7859623054e685c6332;p=lttng-ust.git diff --git a/liblttng-ust-comm/lttng-ust-comm.c b/liblttng-ust-comm/lttng-ust-comm.c index 5d7a049b..087424fe 100644 --- a/liblttng-ust-comm/lttng-ust-comm.c +++ b/liblttng-ust-comm/lttng-ust-comm.c @@ -79,7 +79,6 @@ const char *lttng_ust_strerror(int code) if (code >= LTTNG_UST_ERR_NR) code = LTTNG_UST_ERR; return ustcomm_readable_code[USTCOMM_CODE_OFFSET(code)]; - } /* @@ -117,11 +116,18 @@ int ustcomm_connect_unix_sock(const char *pathname) 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 && errno != EACCES) + PERROR("connect"); ret = -errno; + if (ret == -ECONNREFUSED || ret == -ECONNRESET) + ret = -EPIPE; goto error_connect; } @@ -275,10 +281,10 @@ ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len) if (ret < 0) { int shutret; - if (errno != EPIPE && errno != ECONNRESET) + if (errno != EPIPE && errno != ECONNRESET && errno != ECONNREFUSED) PERROR("recvmsg"); ret = -errno; - if (ret == -ECONNRESET) + if (ret == -ECONNRESET || ret == -ECONNREFUSED) ret = -EPIPE; shutret = shutdown(sock, SHUT_RDWR); @@ -426,8 +432,7 @@ ssize_t ustcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd) if (errno != EPIPE && errno != ECONNRESET) { PERROR("recvmsg fds"); } - if (errno == EPIPE || errno == ECONNRESET) - ret = -errno; + ret = -errno; if (ret == -ECONNRESET) ret = -EPIPE; goto end; @@ -514,15 +519,10 @@ int ustcomm_recv_app_reply(int sock, struct ustcomm_ust_reply *lur, } 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; } } @@ -546,10 +546,12 @@ int ustcomm_send_app_cmd(int sock, * 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; @@ -565,6 +567,18 @@ ssize_t ustcomm_recv_channel_from_sessiond(int sock, 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; @@ -642,6 +656,26 @@ int ustcomm_send_reg_msg(int sock, return 0; } +static +int serialize_string_encoding(enum ustctl_string_encodings *ue, + enum lttng_string_encodings le) +{ + switch (le) { + case lttng_encode_none: + *ue = ustctl_encode_none; + break; + case lttng_encode_UTF8: + *ue = ustctl_encode_UTF8; + break; + case lttng_encode_ASCII: + *ue = ustctl_encode_ASCII; + break; + default: + return -EINVAL; + } + return 0; +} + static int serialize_basic_type(enum ustctl_abstract_types *uatype, enum lttng_abstract_types atype, @@ -660,14 +694,17 @@ int serialize_basic_type(enum ustctl_abstract_types *uatype, uit->signedness = lit->signedness; uit->reverse_byte_order = lit->reverse_byte_order; uit->base = lit->base; - uit->encoding = lit->encoding; + if (serialize_string_encoding(&uit->encoding, lit->encoding)) + return -EINVAL; uit->alignment = lit->alignment; *uatype = ustctl_atype_integer; break; } case atype_string: { - ubt->string.encoding = lbt->string.encoding; + if (serialize_string_encoding(&ubt->string.encoding, + lbt->string.encoding)) + return -EINVAL; *uatype = ustctl_atype_string; break; } @@ -817,7 +854,7 @@ int ustcomm_register_event(int sock, struct ustcomm_notify_event_reply r; } reply; size_t signature_len, fields_len, model_emf_uri_len; - struct ustctl_field *fields; + struct ustctl_field *fields = NULL; size_t nr_write_fields = 0; int ret;