+ fprintf(stderr, "usage: %s COMMAND PIDs...\n", progname);
+ fprintf(stderr, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
+\n\
+Commands:\n\
+ --start-trace\t\t\tStart tracing\n\
+ --stop-trace\t\t\tStop tracing\n\
+ --destroy-trace\t\t\tDestroy the trace\n\
+ --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
+ --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
+ --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
+\
+");
+}
+
+int parse_opts_long(int argc, char **argv, struct ust_opts *opts)
+{
+ int c;
+
+ opts->pids = NULL;
+ opts->regex = NULL;
+
+ while (1) {
+ int option_index = 0;
+ static struct option long_options[] = {
+ {"start-trace", 0, 0, 1000},
+ {"stop-trace", 0, 0, 1001},
+ {"destroy-trace", 0, 0, 1002},
+ {"list-markers", 0, 0, 1004},
+ {"print-markers", 0, 0, 1005},
+ {"pid", 1, 0, 1006},
+ {"enable-marker", 1, 0, 1007},
+ {"disable-marker", 1, 0, 1008},
+ {"start", 0, 0, 1009},
+ {"help", 0, 0, 'h'},
+ {"version", 0, 0, 1010},
+ {"online-pids", 0, 0, 1011},
+ {0, 0, 0, 0}
+ };
+
+ c = getopt_long(argc, argv, "h", long_options, &option_index);
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 0:
+ printf("option %s", long_options[option_index].name);
+ if (optarg)
+ printf(" with arg %s", optarg);
+ printf("\n");
+ break;
+
+ case 1000:
+ opts->cmd = START_TRACE;
+ break;
+ case 1001:
+ opts->cmd = STOP_TRACE;
+ break;
+ case 1009:
+ opts->cmd = START;
+ break;
+ case 1002:
+ opts->cmd = DESTROY;
+ break;
+ case 1004:
+ opts->cmd = LIST_MARKERS;
+ break;
+ case 1007:
+ opts->cmd = ENABLE_MARKER;
+ opts->regex = strdup(optarg);
+ break;
+ case 1008:
+ opts->cmd = DISABLE_MARKER;
+ opts->regex = strdup(optarg);
+ break;
+ case 1011:
+ opts->cmd = GET_ONLINE_PIDS;
+ break;
+ case 'h':
+ usage();
+ exit(0);
+ case 1010:
+ printf("Version 0.1\n");
+
+ default:
+ /* unknown option or other error; error is
+ printed by getopt, just return */
+ opts->cmd = UNKNOWN;
+ return 1;
+ }
+ }
+
+ if (argc - optind > 0 && opts->cmd != GET_ONLINE_PIDS) {
+ int i;
+ int pididx=0;
+ opts->pids = malloc((argc-optind+1) * sizeof(pid_t));
+
+ for(i=optind; i<argc; i++) {
+ /* don't take any chances, use a long long */
+ long long tmp;
+ char *endptr;
+ tmp = strtoull(argv[i], &endptr, 10);
+ if(*endptr != '\0') {
+ ERR("The pid \"%s\" is invalid.", argv[i]);
+ return 1;
+ }
+ opts->pids[pididx++] = (pid_t) tmp;