- if(opts.pids == NULL && opts.cmd != GET_ONLINE_PIDS) {
- fprintf(stderr, "No pid specified.\n");
- usage();
- exit(EXIT_FAILURE);
- }
- if(opts.cmd == UNKNOWN) {
- fprintf(stderr, "No command specified.\n");
- usage();
- exit(EXIT_FAILURE);
- }
- if (opts.cmd == GET_ONLINE_PIDS) {
- pid_t *pp = ustcmd_get_online_pids();
- unsigned int i = 0;
-
- if (pp) {
- while (pp[i] != 0) {
- printf("%u\n", (unsigned int) pp[i]);
- ++i;
- }
- free(pp);
- }
-
- exit(EXIT_SUCCESS);
- }
-
- pidit = opts.pids;
- struct marker_status *cmsf = NULL;
- struct trace_event_status *tes = NULL;
- unsigned int i = 0;
-
- while(*pidit != -1) {
- switch (opts.cmd) {
- case CREATE_TRACE:
- 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;
- break;
- }
- break;
-
- case START_TRACE:
- 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;
- break;
- }
- break;
-
- case STOP_TRACE:
- 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;
- break;
- }
- break;
-
- case DESTROY_TRACE:
- 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;
- break;
- }
- break;
-
- case LIST_MARKERS:
- cmsf = NULL;
- if (ustcmd_get_cmsf(&cmsf, *pidit)) {
- ERR("error while trying to list markers for PID %u\n", (unsigned int) *pidit);
- retval = EXIT_FAILURE;
- break;
- }
- i = 0;
- while (cmsf[i].channel != NULL) {
- printf("{PID: %u, channel/marker: %s/%s, "
- "state: %u, fmt: %s}\n",
- (unsigned int) *pidit,
- cmsf[i].channel,
- cmsf[i].marker,
- cmsf[i].state,
- cmsf[i].fs);
- ++i;
- }
- ustcmd_free_cmsf(cmsf);
- break;
-
- case LIST_TRACE_EVENTS:
- tes = NULL;
- if (ustcmd_get_tes(&tes, *pidit)) {
- ERR("error while trying to list "
- "trace_events for PID %u\n",
- (unsigned int) *pidit);
- break;
- }
- i = 0;
- while (tes[i].name != NULL) {
- printf("{PID: %u, trace_event: %s}\n",
- (unsigned int) *pidit,
- tes[i].name);
- ++i;
- }
- ustcmd_free_tes(tes);
-
- break;
- case ENABLE_MARKER:
- if (opts.regex) {
- 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) {
- 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;
- }
- }
- break;
-
- case SET_SUBBUF_SIZE:
- if (opts.regex) {
- 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;
- }
- }
- break;
-
- case SET_SUBBUF_NUM:
- if (opts.regex) {
- 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;
- }
- }
- break;
-
- case GET_SUBBUF_SIZE:
- 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;
- break;
- }
-
- printf("the size of subbufers is %d\n", result);
- break;
-
- case GET_SUBBUF_NUM:
- 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;
- break;
- }
-
- printf("the number of subbufers is %d\n", result);
- break;
-
- case ALLOC_TRACE:
- 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;
- }
- break;
-
- case GET_SOCK_PATH:
- result = ustcmd_get_sock_path(&tmp, *pidit);
- if (result) {
- ERR("error while trying to get sock path for PID %u\n", (unsigned int) *pidit);
- retval = EXIT_FAILURE;
- break;
- }
- printf("the socket path is %s\n", tmp);
- free(tmp);
- break;
-
- case SET_SOCK_PATH:
- result = ustcmd_set_sock_path(opts.regex, *pidit);
- if (result) {
- ERR("error while trying to set sock path for PID %u\n", (unsigned int) *pidit);
- retval = EXIT_FAILURE;
- }
- break;
-
- case FORCE_SWITCH:
- result = ustcmd_force_switch(*pidit);
- if (result) {
- ERR("error while trying to force switch for PID %u\n", (unsigned int) *pidit);
- retval = EXIT_FAILURE;
- }
- break;
-
- default:
- ERR("unknown command\n");
- retval = EXIT_FAILURE;
- break;
- }
-
- pidit++;
- }
-
- if (opts.pids != NULL) {
- free(opts.pids);
- }
- if (opts.regex != NULL) {
- free(opts.regex);