Exemple #1
0
int main(int argc, char **argv) {
    int c;

    while (1) {
        static struct option long_options[] = {
                {"help", no_argument, 0, 'h'},
                {"watch", no_argument, 0, 'w'},
                {0, 0, 0, 0 }
        };
        /* getopt_long stores the option index here. */
        int option_index = 0;

        c = getopt_long(argc, argv, "hw", long_options, &option_index);

        /* Detect the end of the options. */
        if (c == -1)
            break;

        switch (c) {
        case 'h':
            usage();
            exit(EXIT_SUCCESS);
            break;
        case 'w':
            profiling_watch = 1;
            break;
        case '?':
            usage();
            exit(EXIT_SUCCESS);
            break;
        default:
            usage();
            exit(EXIT_FAILURE);
            break;
        }
    }

    if (argc - optind < 2) {
        usage();
        exit(EXIT_FAILURE);
    }

    if (! strchr(argv[optind], '@')) {
        usage();
        exit(EXIT_FAILURE);
    };

    profiled_service = strtok(argv[optind], "@");
    profiled_host = strtok(0, "@");
    profiling_port = 0;
    if (index(profiled_host, ':')) {
        profiled_host = strtok(profiled_host, ":");
        profiling_port = atoi(strtok(0, ":"));
    }
    profiling_cmde = argv[optind + 1];

    if (strcmp(profiled_service, "storaged") == 0) {
        profile_storaged(profiled_host, profiling_cmde);
    } else if (strcmp(profiled_service, "rozofsmount") == 0) {
        profile_rozofsmount(profiled_host, profiling_cmde);
    } else if (strcmp(profiled_service, "exportd") == 0) {
        profile_exportd(profiled_host, profiling_cmde);
    } else {
        usage();
        exit(EXIT_FAILURE);
    }

    exit(0);
}
Exemple #2
0
int main(int argc, char **argv) {
    int c;

    // Set timeout for RPC requests
    //timeo.tv_sec = RPROF_TIMEOUT_REQUESTS;
    //timeo.tv_usec = 0;

    while (1) {
        static struct option long_options[] = {
            {"help", no_argument, 0, 'h'},
            {"watch", no_argument, 0, 'w'},
            {0, 0, 0, 0}
        };
        /* getopt_long stores the option index here. */
        int option_index = 0;

        c = getopt_long(argc, argv, "hw", long_options, &option_index);

        /* Detect the end of the options. */
        if (c == -1)
            break;

        switch (c) {
            case 'h':
                usage();
                exit(EXIT_SUCCESS);
                break;
            case 'w':
                profiling_watch = 1;
                break;
            case '?':
                usage();
                exit(EXIT_SUCCESS);
                break;
            default:
                usage();
                exit(EXIT_FAILURE);
                break;
        }
    }

    if (argc - optind < 2) {
        usage();
        exit(EXIT_FAILURE);
    }

    if (!strchr(argv[optind], '@')) {
        usage();
        exit(EXIT_FAILURE);
    };

    profiled_service = strtok(argv[optind], "@");
    profiled_host = strtok(0, "@");

    if (strlen(profiled_host) >= ROZOFS_HOSTNAME_MAX) {
        fprintf(stderr, "The length of hostname must be lower than %d.\n",
                ROZOFS_HOSTNAME_MAX);
        exit(EXIT_FAILURE);
    }

    profiling_port = 0;
    if (index(profiled_host, ':')) {
        profiled_host = strtok(profiled_host, ":");
        profiling_port = atoi(strtok(0, ":"));
    }
    profiling_cmde = argv[optind + 1];

    if (strcmp(profiled_service, "storaged") == 0) {
        profile_storaged(profiled_host, profiling_cmde);
    } else if (strcmp(profiled_service, "rozofsmount") == 0) {
        profile_rozofsmount(profiled_host, profiling_cmde);
    } else if (strcmp(profiled_service, "exportd") == 0) {
        profile_exportd(profiled_host, profiling_cmde);
    } else {
        usage();
        exit(EXIT_FAILURE);
    }

    exit(0);
}