X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=ustctl%2Fustctl.c;h=aad3834a4ccfeb597bc21f22bd95b09de80262ee;hb=d89b81916428a3e7e5dfe1612e87218502a40a3b;hp=bf149d11f8b6b4c666467f91505d5686783d3076;hpb=a3adfb05f9a9d0bb3f49b6696a0c233d6e9f6626;p=ust.git diff --git a/ustctl/ustctl.c b/ustctl/ustctl.c index bf149d1..aad3834 100644 --- a/ustctl/ustctl.c +++ b/ustctl/ustctl.c @@ -169,6 +169,55 @@ int parse_opts_long(int argc, char **argv, struct ust_opts *opts) return 0; } +static int scan_ch_marker(const char *channel_marker, char **channel, + char **marker) +{ + int result; + + *channel = NULL; + *marker = NULL; + + result = sscanf(channel_marker, "%a[^/]/%as", channel, marker); + if (result != 2) { + if (errno) { + PERROR("Failed to read channel and marker names"); + } else { + ERR("Failed to parse marker and channel names"); + } + if (*channel) { + free(*channel); + } + if (*marker) { + free(*marker); + } + return -1; + } else { + return 0; + } +} + +static int scan_ch_and_num(const char *ch_num, char **channel, unsigned int *num) +{ + int result; + + *channel = NULL; + + result = sscanf(ch_num, "%a[^/]/%u", channel, num); + if (result != 2) { + if (errno) { + PERROR("Failed to parse channel and number"); + } else { + ERR("Failed to parse channel and number"); + } + if (*channel) { + free(*channel); + } + return -1; + } +} + +char *trace = "auto"; + int main(int argc, char *argv[]) { pid_t *pidit; @@ -225,7 +274,7 @@ int main(int argc, char *argv[]) while(*pidit != -1) { switch (opts.cmd) { case CREATE_TRACE: - result = ustcmd_create_trace(*pidit); + result = ustcmd_create_trace(trace, *pidit); if (result) { ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -234,7 +283,7 @@ int main(int argc, char *argv[]) break; case START_TRACE: - result = ustcmd_start_trace(*pidit); + result = ustcmd_start_trace(trace, *pidit); if (result) { ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -243,7 +292,7 @@ int main(int argc, char *argv[]) break; case STOP_TRACE: - result = ustcmd_stop_trace(*pidit); + result = ustcmd_stop_trace(trace, *pidit); if (result) { ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -252,7 +301,7 @@ int main(int argc, char *argv[]) break; case DESTROY_TRACE: - result = ustcmd_destroy_trace(*pidit); + result = ustcmd_destroy_trace(trace, *pidit); if (result) { ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -301,16 +350,31 @@ int main(int argc, char *argv[]) break; case ENABLE_MARKER: if (opts.regex) { - if (ustcmd_set_marker_state(opts.regex, 1, *pidit)) { - ERR("error while trying to enable marker %s with PID %u\n", - opts.regex, (unsigned int) *pidit); + char *channel, *marker; + + if (scan_ch_marker(opts.regex, + &channel, &marker)) { + retval = EXIT_FAILURE; + break; + } + if (ustcmd_set_marker_state(trace, channel, marker, 1, *pidit)) { + PERROR("error while trying to enable marker %s with PID %u", + opts.regex, (unsigned int) *pidit); retval = EXIT_FAILURE; } } + break; case DISABLE_MARKER: if (opts.regex) { - if (ustcmd_set_marker_state(opts.regex, 0, *pidit)) { + char *channel, *marker; + + if (scan_ch_marker(opts.regex, + &channel, &marker)) { + retval = EXIT_FAILURE; + break; + } + if (ustcmd_set_marker_state(trace, channel, marker, 0, *pidit)) { ERR("error while trying to disable marker %s with PID %u\n", opts.regex, (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -320,7 +384,14 @@ int main(int argc, char *argv[]) case SET_SUBBUF_SIZE: if (opts.regex) { - if (ustcmd_set_subbuf_size(opts.regex, *pidit)) { + char *channel; + unsigned int size; + if (scan_ch_and_num(opts.regex, &channel, &size)) { + retval = EXIT_FAILURE; + break; + } + + if (ustcmd_set_subbuf_size(trace, channel, size, *pidit)) { ERR("error while trying to set the size of subbuffers with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -330,7 +401,19 @@ int main(int argc, char *argv[]) case SET_SUBBUF_NUM: if (opts.regex) { - if (ustcmd_set_subbuf_num(opts.regex, *pidit)) { + char *channel; + unsigned int num; + if (scan_ch_and_num(opts.regex, &channel, &num)) { + retval = EXIT_FAILURE; + break; + } + + if (num < 2) { + ERR("Subbuffer count should be greater or equal to 2"); + retval = EXIT_FAILURE; + break; + } + if (ustcmd_set_subbuf_num(trace, channel, num, *pidit)) { ERR("error while trying to set the number of subbuffers with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -339,7 +422,7 @@ int main(int argc, char *argv[]) break; case GET_SUBBUF_SIZE: - result = ustcmd_get_subbuf_size(opts.regex, *pidit); + result = ustcmd_get_subbuf_size(trace, opts.regex, *pidit); if (result == -1) { ERR("error while trying to get_subuf_size with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -350,7 +433,7 @@ int main(int argc, char *argv[]) break; case GET_SUBBUF_NUM: - result = ustcmd_get_subbuf_num(opts.regex, *pidit); + result = ustcmd_get_subbuf_num(trace, opts.regex, *pidit); if (result == -1) { ERR("error while trying to get_subuf_num with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE; @@ -361,7 +444,7 @@ int main(int argc, char *argv[]) break; case ALLOC_TRACE: - result = ustcmd_alloc_trace(*pidit); + result = ustcmd_alloc_trace(trace, *pidit); if (result) { ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit); retval = EXIT_FAILURE;