Fix: ustcomm: application name uses the '-ust'-suffixed thread name
[lttng-ust.git] / src / common / ustcomm.c
index 00cbf5a73bae82b0a30568490eb9923706036125..319e84ac923530d790de9afd22ba595849399e31 100644 (file)
@@ -37,7 +37,8 @@ ssize_t count_fields_recursive(size_t nr_fields,
 static
 int serialize_one_field(struct lttng_ust_session *session,
                struct lttng_ust_ctl_field *fields, size_t *iter_output,
-               const struct lttng_ust_event_field *lf);
+               const struct lttng_ust_event_field *lf,
+               const char **prev_field_name);
 static
 int serialize_fields(struct lttng_ust_session *session,
                struct lttng_ust_ctl_field *lttng_ust_ctl_fields,
@@ -213,7 +214,7 @@ int ustcomm_listen_unix_sock(int sock)
 /*
  * ustcomm_close_unix_sock
  *
- * Shutdown cleanly a unix socket.
+ * Close unix socket.
  *
  * Handles fd tracker internally.
  */
@@ -234,6 +235,24 @@ int ustcomm_close_unix_sock(int sock)
        return ret;
 }
 
+/*
+ * ustcomm_shutdown_unix_sock
+ *
+ * Shutdown unix socket. Keeps the file descriptor open, but shutdown
+ * communication.
+ */
+int ustcomm_shutdown_unix_sock(int sock)
+{
+       int ret;
+
+       ret = shutdown(sock, SHUT_RDWR);
+       if (ret) {
+               PERROR("Socket shutdown error");
+               ret = -errno;
+       }
+       return ret;
+}
+
 /*
  * ustcomm_recv_unix_sock
  *
@@ -267,17 +286,13 @@ ssize_t ustcomm_recv_unix_sock(int sock, void *buf, size_t len)
        } while ((ret > 0 && ret < len_last) || (ret < 0 && errno == EINTR));
 
        if (ret < 0) {
-               int shutret;
-
                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)
-                       ERR("Socket shutdown error");
+               (void) ustcomm_shutdown_unix_sock(sock);
        } else if (ret > 0) {
                ret = len;
        }
@@ -317,17 +332,13 @@ ssize_t ustcomm_send_unix_sock(int sock, const void *buf, size_t len)
        } while (ret < 0 && errno == EINTR);
 
        if (ret < 0) {
-               int shutret;
-
                if (errno != EPIPE && errno != ECONNRESET)
                        PERROR("sendmsg");
                ret = -errno;
                if (ret == -ECONNRESET)
                        ret = -EPIPE;
 
-               shutret = shutdown(sock, SHUT_RDWR);
-               if (shutret)
-                       ERR("Socket shutdown error");
+               (void) ustcomm_shutdown_unix_sock(sock);
        }
 
        return ret;
@@ -792,7 +803,8 @@ int ustcomm_send_reg_msg(int sock,
                uint32_t uint16_t_alignment,
                uint32_t uint32_t_alignment,
                uint32_t uint64_t_alignment,
-               uint32_t long_alignment)
+               uint32_t long_alignment,
+               const char *procname)
 {
        ssize_t len;
        struct lttng_ust_ctl_reg_msg reg_msg;
@@ -811,7 +823,8 @@ int ustcomm_send_reg_msg(int sock,
        reg_msg.uint64_t_alignment = uint64_t_alignment;
        reg_msg.long_alignment = long_alignment;
        reg_msg.socket_type = type;
-       lttng_pthread_getname_np(reg_msg.name, LTTNG_UST_ABI_PROCNAME_LEN);
+       memset(reg_msg.name, 0, sizeof(reg_msg.name));
+       strncpy(reg_msg.name, procname, sizeof(reg_msg.name) - 1);
        memset(reg_msg.padding, 0, sizeof(reg_msg.padding));
 
        len = ustcomm_send_unix_sock(sock, &reg_msg, sizeof(reg_msg));
@@ -973,7 +986,7 @@ int serialize_dynamic_type(struct lttng_ust_session *session,
                LTTNG_UST_ABI_SYM_NAME_LEN - strlen(tag_field_name) - 1);
        tag_field.type = tag_type;
        ret = serialize_one_field(session, fields, iter_output,
-               &tag_field);
+               &tag_field, NULL);
        if (ret)
                return ret;
 
@@ -997,7 +1010,7 @@ int serialize_dynamic_type(struct lttng_ust_session *session,
        /* Serialize choice fields after variant. */
        for (i = 0; i < nr_choices; i++) {
                ret = serialize_one_field(session, fields,
-                       iter_output, choices[i]);
+                       iter_output, choices[i], NULL);
                if (ret)
                        return ret;
        }
@@ -1008,7 +1021,8 @@ static
 int serialize_one_type(struct lttng_ust_session *session,
                struct lttng_ust_ctl_field *fields, size_t *iter_output,
                const char *field_name, const struct lttng_ust_type_common *lt,
-               enum lttng_ust_string_encoding parent_encoding)
+               enum lttng_ust_string_encoding parent_encoding,
+               const char *prev_field_name)
 {
        int ret;
 
@@ -1098,7 +1112,7 @@ int serialize_one_type(struct lttng_ust_session *session,
 
                ret = serialize_one_type(session, fields, iter_output, NULL,
                                lttng_ust_get_type_array(lt)->elem_type,
-                               lttng_ust_get_type_array(lt)->encoding);
+                               lttng_ust_get_type_array(lt)->encoding, NULL);
                if (ret)
                        return -EINVAL;
                break;
@@ -1107,6 +1121,7 @@ int serialize_one_type(struct lttng_ust_session *session,
        {
                struct lttng_ust_ctl_field *uf = &fields[*iter_output];
                struct lttng_ust_ctl_type *ut = &uf->type;
+               const char *length_name = lttng_ust_get_type_sequence(lt)->length_name;
 
                if (field_name) {
                        strncpy(uf->name, field_name, LTTNG_UST_ABI_SYM_NAME_LEN);
@@ -1115,16 +1130,23 @@ int serialize_one_type(struct lttng_ust_session *session,
                        uf->name[0] = '\0';
                }
                ut->atype = lttng_ust_ctl_atype_sequence_nestable;
+               /*
+                * If length_name field is NULL, use the previous field
+                * as length.
+                */
+               if (!length_name)
+                       length_name = prev_field_name;
+               if (!length_name)
+                       return -EINVAL;
                strncpy(ut->u.sequence_nestable.length_name,
-                       lttng_ust_get_type_sequence(lt)->length_name,
-                       LTTNG_UST_ABI_SYM_NAME_LEN);
+                       length_name, LTTNG_UST_ABI_SYM_NAME_LEN);
                ut->u.sequence_nestable.length_name[LTTNG_UST_ABI_SYM_NAME_LEN - 1] = '\0';
                ut->u.sequence_nestable.alignment = lttng_ust_get_type_sequence(lt)->alignment;
                (*iter_output)++;
 
                ret = serialize_one_type(session, fields, iter_output, NULL,
                                lttng_ust_get_type_sequence(lt)->elem_type,
-                               lttng_ust_get_type_sequence(lt)->encoding);
+                               lttng_ust_get_type_sequence(lt)->encoding, NULL);
                if (ret)
                        return -EINVAL;
                break;
@@ -1178,7 +1200,7 @@ int serialize_one_type(struct lttng_ust_session *session,
 
                ret = serialize_one_type(session, fields, iter_output, NULL,
                                lttng_ust_get_type_enum(lt)->container_type,
-                               lttng_ust_string_encoding_none);
+                               lttng_ust_string_encoding_none, NULL);
                if (ret)
                        return -EINVAL;
                if (session) {
@@ -1202,13 +1224,23 @@ int serialize_one_type(struct lttng_ust_session *session,
 static
 int serialize_one_field(struct lttng_ust_session *session,
                struct lttng_ust_ctl_field *fields, size_t *iter_output,
-               const struct lttng_ust_event_field *lf)
+               const struct lttng_ust_event_field *lf,
+               const char **prev_field_name_p)
 {
+       const char *prev_field_name = NULL;
+       int ret;
+
        /* skip 'nowrite' fields */
        if (lf->nowrite)
                return 0;
 
-       return serialize_one_type(session, fields, iter_output, lf->name, lf->type, lttng_ust_string_encoding_none);
+       if (prev_field_name_p)
+               prev_field_name = *prev_field_name_p;
+       ret = serialize_one_type(session, fields, iter_output, lf->name, lf->type,
+                       lttng_ust_string_encoding_none, prev_field_name);
+       if (prev_field_name_p)
+               *prev_field_name_p = lf->name;
+       return ret;
 }
 
 static
@@ -1217,12 +1249,14 @@ int serialize_fields(struct lttng_ust_session *session,
                size_t *iter_output, size_t nr_lttng_fields,
                const struct lttng_ust_event_field * const *lttng_fields)
 {
+       const char *prev_field_name = NULL;
        int ret;
        size_t i;
 
        for (i = 0; i < nr_lttng_fields; i++) {
                ret = serialize_one_field(session, lttng_ust_ctl_fields,
-                               iter_output, lttng_fields[i]);
+                               iter_output, lttng_fields[i],
+                               &prev_field_name);
                if (ret)
                        return ret;
        }
@@ -1307,9 +1341,10 @@ int serialize_ctx_fields(struct lttng_ust_session *session,
                struct lttng_ust_ctx_field *lttng_fields)
 {
        struct lttng_ust_ctl_field *fields;
-       int ret;
+       const char *prev_field_name = NULL;
        size_t i, iter_output = 0;
        ssize_t nr_write_fields;
+       int ret;
 
        nr_write_fields = count_ctx_fields_recursive(nr_fields,
                        lttng_fields);
@@ -1323,7 +1358,7 @@ int serialize_ctx_fields(struct lttng_ust_session *session,
 
        for (i = 0; i < nr_fields; i++) {
                ret = serialize_one_field(session, fields, &iter_output,
-                               lttng_fields[i].event_field);
+                               lttng_fields[i].event_field, &prev_field_name);
                if (ret)
                        goto error_type;
        }
This page took 0.026396 seconds and 4 git commands to generate.