#include <getopt.h>
#include <stdlib.h>
#include <fcntl.h>
+#include <regex.h>
#include "ustcomm.h"
#include "ustcmd.h"
DISABLE_MARKER,
GET_ONLINE_PIDS,
UNKNOWN
-};
+};
struct ust_opts {
enum command cmd;
pid_t *pids;
- char* m_name;
+ char* regex;
+ regex_t preg;
+ int regex_state;
};
char *progname = NULL;
int c;
opts->pids = NULL;
- opts->m_name = NULL;
+ opts->regex = NULL;
+ opts->regex_state = -1;
while (1) {
int option_index = 0;
break;
case 1007:
opts->cmd = ENABLE_MARKER;
- opts->m_name = strdup(optarg);
+ opts->regex = strdup(optarg);
break;
case 1008:
opts->cmd = DISABLE_MARKER;
- opts->m_name = strdup(optarg);
+ opts->regex = strdup(optarg);
break;
case 1011:
opts->cmd = GET_ONLINE_PIDS;
usage();
exit(EXIT_FAILURE);
}
-
if (opts.cmd == GET_ONLINE_PIDS) {
pid_t* pp = ustcmd_get_online_pids();
unsigned int i = 0;
}
free(pp);
}
-
+
exit(EXIT_SUCCESS);
}
pidit = opts.pids;
struct USTcmd_cmsf* cmsf = NULL;
-
+
while(*pidit != -1) {
switch (opts.cmd) {
case START_TRACE:
printf("sucessfully started trace for PID %u\n",
(unsigned int) *pidit);
break;
-
+
case STOP_TRACE:
if (ustcmd_stop_trace(*pidit)) {
fprintf(stderr,
printf("sucessfully stopped trace for PID %u\n",
(unsigned int) *pidit);
break;
-
+
case START:
if (ustcmd_setup_and_start(*pidit)) {
fprintf(stderr,
printf("sucessfully setup/started trace for PID %u\n",
(unsigned int) *pidit);
break;
-
+
case DESTROY:
if (ustcmd_destroy_trace(*pidit)) {
fprintf(stderr,
printf("sucessfully destroyed trace for PID %u\n",
(unsigned int) *pidit);
break;
-
+
case LIST_MARKERS:
cmsf = NULL;
if (ustcmd_get_cmsf(&cmsf, *pidit)) {
}
ustcmd_free_cmsf(cmsf);
break;
-
+
case ENABLE_MARKER:
- if (ustcmd_set_marker_state(opts.m_name, USTCMD_MS_ON,
- *pidit)) {
-
- fprintf(stderr,
- "error while trying to enable marker"
- "\"%s\" for PID %u\n",
- opts.m_name,
- (unsigned int) *pidit);
- break;
- }
- printf("sucessfully enabled marker \"%s\" for PID %u\n",
- opts.m_name, (unsigned int) *pidit);
- break;
-
case DISABLE_MARKER:
- if (ustcmd_set_marker_state(opts.m_name, USTCMD_MS_OFF,
- *pidit)) {
- fprintf(stderr,
- "error while trying to disable marker"
- "\"%s\" for PID %u\n",
- opts.m_name,
- (unsigned int) *pidit);
- break;
- }
- printf("sucessfully disabled marker \"%s\" for PID %u\n",
- opts.m_name, (unsigned int) *pidit);
+ regex_change_m_state(&opts, *pidit);
break;
-
+
default:
fprintf(stderr, "error: unknown command...\n");
break;
}
-
+
pidit++;
}
- free(opts.pids);
- if (opts.m_name != NULL) {
- free(opts.m_name);
+ exit_free:
+ if (opts.pids != NULL) {
+ free(opts.pids);
+ }
+ if (opts.regex != NULL) {
+ free(opts.regex);
}
return 0;