#include <sched.h>
#include <fcntl.h>
#include <poll.h>
+#include <regex.h>
#include <urcu.h>
return 0;
}
+static regex_t preg;
+static int regex_is_ok = -1;
+
static void auto_probe_connect(struct marker *m)
{
int result;
+ char* comp_name = NULL;
+ char* regex;
+
+ if (regex_is_ok != 0) {
+ goto end;
+ }
+
+ if (asprintf(&comp_name, "%s/%s", m->channel, m->name) == -1) {
+ ERR("auto_probe_connect: `asprintf' failed (marker %s/%s)",
+ m->channel, m->name);
+ return;
+ }
+ if (regexec(&preg, comp_name, 0, NULL, 0) != 0) {
+ goto end; /* Not matching */
+ }
+
+// connect:
+
result = ltt_marker_connect(m->channel, m->name, "default");
if(result && result != -EEXIST)
ERR("ltt_marker_connect (marker = %s/%s, errno = %d)", m->channel, m->name, -result);
DBG("just auto connected marker %s %s to probe default", m->channel, m->name);
+
+ end:
+ if (comp_name != NULL) {
+ free(comp_name);
+ }
}
static void __attribute__((constructor(101))) init0()
static void __attribute__((constructor(1000))) init()
{
int result;
+ char* regex = NULL;
/* Initialize RCU in case the constructor order is not good. */
urcu_init();
return;
}
- if(getenv("UST_AUTOPROBE")) {
+ regex = getenv("UST_AUTOPROBE");
+ if(regex) {
+ char* regex = NULL;
struct marker_iter iter;
DBG("IN AUTOPROBE\n");
* probe on new markers
*/
marker_set_new_marker_cb(auto_probe_connect);
-
+ regex_is_ok = regcomp(&preg, regex, 0);
+ if (regex_is_ok) {
+ ERR("cannot parse regex %s", regex);
+ }
/* Now, connect the probes that were already registered. */
marker_iter_reset(&iter);
marker_iter_start(&iter);
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <getopt.h>
pid_t* ustcmd_get_online_pids(void) {
struct dirent* dirent;
DIR* dir;
- char* ping_res;
+ unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
dir = opendir(SOCK_DIR);
if (!dir) {
return NULL;
}
- unsigned int ret_size = 1 * sizeof(pid_t), i = 0;
pid_t* ret = (pid_t*) malloc(ret_size);
while (dirent = readdir(dir)) {
* @param pid Traced process ID
* @return 0 if successful, or errors {USTCMD_ERR_GEN, USTCMD_ERR_ARG}
*/
-int ustcmd_set_marker_state(const char* mn, int state, pid_t pid) {
+int ustcmd_set_marker_state(const char* mn, int state, pid_t pid)
+{
+ char* cmd_str [] = {"disable_marker", "enable_marker"};
+ char* cmd;
+ int result;
+
if (mn == NULL) {
return USTCMD_ERR_ARG;
}
- char* cmd_str [] = {"disable_marker", "enable_marker"};
- char* cmd;
asprintf(&cmd, "%s %s", cmd_str[state], mn);
- int tres;
- if (tres = ustcmd_shoot(cmd, pid, NULL)) {
+ result = ustcmd_shoot(cmd, pid, NULL);
+ if (result) {
free(cmd);
return USTCMD_ERR_GEN;
}
* @return 0 if successful, or errors {USTCMD_ERR_ARG, USTCMD_ERR_GEN}
*/
int ustcmd_get_cmsf(struct USTcmd_cmsf** cmsf, const pid_t pid) {
+ char* big_str = NULL;
+ int result;
+ struct USTcmd_cmsf* tmp_cmsf = NULL;
+ unsigned int i = 0, cmsf_ind = 0;
+
if (cmsf == NULL) {
return USTCMD_ERR_ARG;
}
- char* big_str = NULL;
- int tres;
-
- if (tres = ustcmd_shoot("list_markers", pid, &big_str)) {
+ result = ustcmd_shoot("list_markers", pid, &big_str);
+ if (result) {
return USTCMD_ERR_GEN;
}
return USTCMD_ERR_GEN;
}
- struct USTcmd_cmsf* tmp_cmsf = NULL;
tmp_cmsf = (struct USTcmd_cmsf*) malloc(sizeof(struct USTcmd_cmsf) *
(ustcmd_count_nl(big_str) + 1));
if (tmp_cmsf == NULL) {
}
/* Parse received reply string (format: "[chan]/[mark] [st] [fs]"): */
- unsigned int i = 0, cur_st, cmsf_ind = 0;
while (big_str[i] != '\0') {
char state;
+
sscanf(big_str + i, "%a[^/]/%a[^ ] %c %a[^\n]",
&tmp_cmsf[cmsf_ind].channel,
&tmp_cmsf[cmsf_ind].marker,
return USTCMD_ERR_ARG;
}
- struct ustcomm_connection conn;
if (ustcomm_connect_app(pid, &conn)) {
fprintf(stderr, "ustcmd_shoot: could not connect to PID %u\n",
(unsigned int) pid);
#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;