X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=libustcmd%2Fustcmd.c;h=ac90f6cae099c681218ffc73cd3ec0f0777e368d;hb=4723ca096d740ff93da400df304c9902e9834e5f;hp=f0a6ae0a25059cfcaead24f313c0b926e5ccb02a;hpb=9d20cbf2e908c3bc8a1950e48c2d630f2e0d0794;p=ust.git diff --git a/libustcmd/ustcmd.c b/libustcmd/ustcmd.c index f0a6ae0..ac90f6c 100644 --- a/libustcmd/ustcmd.c +++ b/libustcmd/ustcmd.c @@ -52,7 +52,12 @@ pid_t *ustcmd_get_online_pids(void) !!strcmp(dirent->d_name, "ustd")) { sscanf(dirent->d_name, "%u", (unsigned int *) &ret[i]); - if (pid_is_online(ret[i])) { + /* FIXME: Here we previously called pid_is_online, which + * always returned 1, now I replaced it with just 1. + * We need to figure out an intelligent way of solving + * this, maybe connect-disconnect. + */ + if (1) { ret_size += sizeof(pid_t); ret = (pid_t *) realloc(ret, ret_size); ++i; @@ -395,10 +400,6 @@ int ustcmd_get_cmsf(struct marker_status **cmsf, const pid_t pid) return -1; } result = ustcmd_send_cmd("list_markers", pid, &big_str); - if (result != 1) { - return -1; - } - if (result != 1) { ERR("error while getting markers list"); return -1; @@ -407,6 +408,7 @@ int ustcmd_get_cmsf(struct marker_status **cmsf, const pid_t pid) tmp_cmsf = (struct marker_status *) malloc(sizeof(struct marker_status) * (ustcmd_count_nl(big_str) + 1)); if (tmp_cmsf == NULL) { + ERR("Failed to allocate CMSF array"); return -1; } @@ -438,6 +440,83 @@ int ustcmd_get_cmsf(struct marker_status **cmsf, const pid_t pid) return 0; } + +/** + * Frees a TES array. + * + * @param tes TES array to free + * @return 0 if successful, or error USTCMD_ERR_ARG + */ +int ustcmd_free_tes(struct trace_event_status *tes) +{ + if (tes == NULL) { + return USTCMD_ERR_ARG; + } + + unsigned int i = 0; + while (tes[i].name != NULL) { + free(tes[i].name); + ++i; + } + free(tes); + + return 0; +} + +/** + * Gets trace_events string for a given PID. + * + * @param tes Pointer to TES array to be filled (callee allocates, caller + * frees with `ustcmd_free_tes') + * @param pid Targeted PID + * @return 0 if successful, or -1 on error + */ +int ustcmd_get_tes(struct trace_event_status **tes, + const pid_t pid) +{ + char *big_str = NULL; + int result; + struct trace_event_status *tmp_tes = NULL; + unsigned int i = 0, tes_ind = 0; + + if (tes == NULL) { + return -1; + } + + result = ustcmd_send_cmd("list_trace_events", pid, &big_str); + if (result != 1) { + ERR("error while getting trace_event list"); + return -1; + } + + tmp_tes = (struct trace_event_status *) + zmalloc(sizeof(struct trace_event_status) * + (ustcmd_count_nl(big_str) + 1)); + if (tmp_tes == NULL) { + ERR("Failed to allocate TES array"); + return -1; + } + + /* Parse received reply string (format: "[name]"): */ + while (big_str[i] != '\0') { + char state; + + sscanf(big_str + i, "trace_event: %a[^\n]", + &tmp_tes[tes_ind].name); + while (big_str[i] != '\n') { + ++i; /* Go to next '\n' */ + } + ++i; /* Skip current pointed '\n' */ + ++tes_ind; + } + tmp_tes[tes_ind].name = NULL; + + *tes = tmp_tes; + + free(big_str); + return 0; +} + /** * Set socket path * @@ -518,17 +597,17 @@ int ustcmd_force_switch(pid_t pid) int ustcmd_send_cmd(const char *cmd, const pid_t pid, char **reply) { - struct ustcomm_connection conn; + int app_fd; int retval; - if (ustcomm_connect_app(pid, &conn)) { + if (ustcomm_connect_app(pid, &app_fd)) { ERR("could not connect to PID %u", (unsigned int) pid); return -1; } - retval = ustcomm_send_request(&conn, cmd, reply); + retval = ustcomm_send_request(app_fd, cmd, reply); - ustcomm_close_app(&conn); + close(app_fd); return retval; }