#include <getopt.h>
#include <stdlib.h>
#include <fcntl.h>
-#include <regex.h>
#include "ustcomm.h"
#include "ustcmd.h"
enum command cmd;
pid_t *pids;
char *regex;
- regex_t preg;
- int regex_state;
};
char *progname = NULL;
opts->pids = NULL;
opts->regex = NULL;
- opts->regex_state = -1;
while (1) {
int option_index = 0;
opts->pids[pididx] = -1;
}
- if (opts->cmd == ENABLE_MARKER || opts->cmd == DISABLE_MARKER) {
- opts->regex_state = regcomp(&opts->preg, opts->regex, 0);
- if (opts->regex_state) {
- ERR("invalid regular expression\n");
- }
- }
-
return 0;
}
-static void regex_change_m_state(struct ust_opts *opts, pid_t pid)
-{
- struct marker_status *cmsf = NULL;
- unsigned int i = 0;
- int e = (opts->cmd == ENABLE_MARKER);
-
- if (opts->regex_state != 0) {
- return;
- }
-
- if (ustcmd_get_cmsf(&cmsf, pid)) {
- fprintf(stderr, "error while trying to get markers for PID "
- "%u\n", (unsigned int) pid);
- return;
- }
- while (cmsf[i].channel != NULL) {
- char *mc;
- asprintf(&mc, "%s/%s", cmsf[i].channel, cmsf[i].marker);
- if (regexec(&opts->preg, mc, 0, NULL, 0) == 0) {
- /* We got a match! */
- if (ustcmd_set_marker_state(mc,
- e ? USTCMD_MS_ON : USTCMD_MS_OFF, pid)) {
- fprintf(stderr,
- "error while trying to %sable marker"
- "\"%s\" for PID %u\n",
- e ? "en" : "dis", mc,
- (unsigned int) pid);
- } else {
- printf("sucessfully %sabled marker "
- "\"%s\" for PID %u\n",
- e ? "en" : "dis", mc,
- (unsigned int) pid);
- }
- }
- free(mc);
- ++i;
- }
- ustcmd_free_cmsf(cmsf);
-}
-
int main(int argc, char *argv[])
{
pid_t *pidit;
break;
case ENABLE_MARKER:
+ if(opts.regex)
+ ustcmd_set_marker_state(opts.regex, 1, *pidit);
+ break;
case DISABLE_MARKER:
- regex_change_m_state(&opts, *pidit);
- break;
+ if(opts.regex)
+ ustcmd_set_marker_state(opts.regex, 0, *pidit);
+ break;
default:
ERR("unknown command\n");