- int c;
-
- opts->pids = NULL;
- opts->regex = NULL;
-
- while (1) {
- int option_index = 0;
- static struct option long_options[] = {
- { "create-trace", 0, 0, CREATE_TRACE },
- { "alloc-trace", 0, 0, ALLOC_TRACE },
- { "start-trace", 0, 0, START_TRACE },
- { "stop-trace", 0, 0, STOP_TRACE },
- { "destroy-trace", 0, 0, DESTROY_TRACE },
- { "list-markers", 0, 0, LIST_MARKERS },
- { "list-trace-events", 0, 0, LIST_TRACE_EVENTS},
- { "enable-marker", 1, 0, ENABLE_MARKER },
- { "disable-marker", 1, 0, DISABLE_MARKER },
- { "help", 0, 0, 'h' },
- { "online-pids", 0, 0, GET_ONLINE_PIDS },
- { "set-subbuf-size", 1, 0, SET_SUBBUF_SIZE },
- { "set-subbuf-num", 1, 0, SET_SUBBUF_NUM },
- { "get-subbuf-size", 1, 0, GET_SUBBUF_SIZE },
- { "get-subbuf-num", 1, 0, GET_SUBBUF_NUM },
- { "get-sock-path", 0, 0, GET_SOCK_PATH },
- { "set-sock-path", 1, 0, SET_SOCK_PATH },
- { "force-switch", 0, 0, FORCE_SWITCH },
- { 0, 0, 0, 0 }
- };
-
- c = getopt_long(argc, argv, "h", long_options, &option_index);
- if (c == -1)
- break;
-
- if(c >= 1000)
- opts->cmd = c;
-
- switch (c) {
- case 0:
- printf("option %s", long_options[option_index].name);
- if (optarg)
- printf(" with arg %s", optarg);
- printf("\n");
- break;
-
- case ENABLE_MARKER:
- case DISABLE_MARKER:
- case SET_SUBBUF_SIZE:
- case SET_SUBBUF_NUM:
- case GET_SUBBUF_SIZE:
- case GET_SUBBUF_NUM:
- case SET_SOCK_PATH:
- opts->regex = strdup(optarg);
- break;
-
- case 'h':
- usage();
- exit(0);
-
- case '?':
- fprintf(stderr, "Invalid argument\n\n");
- usage();
- exit(1);
- }
- }
-
- if (argc - optind > 0 && opts->cmd != GET_ONLINE_PIDS) {
- int i;
- int pididx=0;
- opts->pids = zmalloc((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;
- }
- opts->pids[pididx] = -1;
- }
-
- return 0;
-}