Example #1
0
static void process_arguments(int argc, char * const *argv)
{
    char c;
    char *v;
    int longindex = 0;
    opterr = 0;

    static struct option long_options[] = {
        { "config",        required_argument, 0, 'c' },
        { "decompressors", required_argument, 0, 's' },
        { "device-id",     required_argument, 0, 'd' },
        { "help",          no_argument,       0,  0  },
        { "hosts",         required_argument, 0, 'h' },
        { "input-port",    required_argument, 0, 'p' },
        { "io-threads",    required_argument, 0, 'i' },
        { "output-port",   required_argument, 0, 'P' },
        { "quiet",         no_argument,       0, 'q' },
        { "rcv-hwm",       required_argument, 0, 'R' },
        { "snd-hwm",       required_argument, 0, 'S' },
        { "subscribe",     required_argument, 0, 'e' },
        { "verbose",       no_argument,       0, 'v' },
        { 0,               0,                 0,  0  }
    };

    while ((c = getopt_long(argc, argv, "vqd:p:P:R:S:c:e:i:s:h:", long_options, &longindex)) != -1) {
        switch (c) {
        case 'v':
            if (verbose)
                debug= true;
            else
                verbose = true;
            break;
        case 'q':
            quiet = true;
            break;
        case 'e':
            subscriptions = split_delimited_string(optarg);
            break;
        case 'd':
            msg_meta.device_number = atoi(optarg);
            break;
        case 'p':
            pull_port = atoi(optarg);
            break;
        case 'P':
            pub_port = atoi(optarg);
            break;
        case 'c':
            config_file_name = optarg;
            break;
        case 'i':
            io_threads = atoi(optarg);
            if (io_threads == 0) {
                printf("[E] invalid io-threads value: must be greater than 0\n");
                exit(1);
            }
            break;
        case 's':
            num_compressors = atoi(optarg);
            if (num_compressors == 0) {
                printf("[E] invalid number of compressors: must be greater than 0\n");
                exit(1);
            }
            if (num_compressors > MAX_COMPRESSORS) {
                printf("[E] invalid number of compressors: must be less than %d\n", MAX_COMPRESSORS+1);
                exit(1);
            }
            break;
        case 'h':
            hosts = split_delimited_string(optarg);
            if (hosts == NULL || zlist_size(hosts) == 0) {
                printf("[E] must specifiy at least one device to connect to\n");
                exit(1);
            }
            break;
        case 'R':
            rcv_hwm = atoi(optarg);
            break;
        case 'S':
            snd_hwm = atoi(optarg);
            break;
        case 0:
            print_usage(argv);
            exit(0);
            break;
        case '?':
            if (strchr("depcish", optopt))
                fprintf(stderr, "option -%c requires an argument.\n", optopt);
            else if (isprint (optopt))
                fprintf(stderr, "unknown option `-%c'.\n", optopt);
            else
                fprintf(stderr, "unknown option character `\\x%x'.\n", optopt);
            print_usage(argv);
            exit(1);
        default:
            fprintf(stderr, "BUG: can't process option -%c\n", c);
            exit(1);
        }
    }

    if (hosts == NULL) {
        hosts = split_delimited_string(getenv("LOGJAM_DEVICES"));
        if (hosts == NULL)
            hosts = zlist_new();
        if (zlist_size(hosts) == 0)
            zlist_push(hosts, strdup("localhost"));
    }
    augment_zmq_connection_specs(&hosts, pull_port);

    if (subscriptions == NULL)
        subscriptions = split_delimited_string(getenv("LOGJAM_SUBSCRIPTIONS"));

    if (rcv_hwm == -1) {
        if (( v = getenv("LOGJAM_RCV_HWM") ))
            rcv_hwm = atoi(v);
        else
            rcv_hwm = DEFAULT_RCV_HWM;
    }

    if (snd_hwm == -1) {
        if (( v = getenv("LOGJAM_SND_HWM") ))
            snd_hwm = atoi(v);
        else
            snd_hwm = DEFAULT_SND_HWM;
    }
}
Example #2
0
static void process_arguments(int argc, char * const *argv)
{
    char c;
    char *v;
    int longindex = 0;
    opterr = 0;

    static struct option long_options[] = {
        { "compress",      no_argument,       0, 'z' },
        { "config",        required_argument, 0, 'c' },
        { "dryrun",        no_argument,       0, 'n' },
        { "help",          no_argument,       0,  0  },
        { "hosts",         required_argument, 0, 'h' },
        { "interface",     required_argument, 0, 'i' },
        { "parsers",       required_argument, 0, 'p' },
        { "quiet",         no_argument,       0, 'q' },
        { "rcv-hwm",       required_argument, 0, 'R' },
        { "snd-hwm",       required_argument, 0, 'S' },
        { "subscribe",     required_argument, 0, 'e' },
        { "verbose",       no_argument,       0, 'v' },
        { 0,               0,                 0,  0  }
    };

    while ((c = getopt_long(argc, argv, "vqc:np:zh:S:R:e", long_options, &longindex)) != -1) {
        switch (c) {
        case 'v':
            if (verbose)
                debug= true;
            else
                verbose = true;
            break;
        case 'q':
            quiet = true;
            break;
        case 'c':
            config_file_name = optarg;
            break;
        case 'n':
            dryrun = true;
            break;
        case 'z':
            compress_gelf = true;
            break;
        case 'p': {
            unsigned int n = strtoul(optarg, NULL, 0);
            if (n <= MAX_PARSERS)
                num_parsers = n;
            else {
                fprintf(stderr, "parameter value 'p' can not be greater than %d\n", MAX_PARSERS);
                exit(1);
            }
            break;
        }
        case 'h':
            hosts = split_delimited_string(optarg);
            if (hosts == NULL || zlist_size(hosts) == 0) {
                printf("[E] must specify at least one device to connect to\n");
                exit(1);
            }
            break;
        case 'i':
            interface = optarg;
            break;
        case 'e':
            subscriptions = split_delimited_string(optarg);
            break;
        case 'R':
            rcv_hwm = atoi(optarg);
            break;
        case 'S':
            snd_hwm = atoi(optarg);
            break;
        case 0:
            print_usage(argv);
            exit(0);
            break;
        case '?':
            if (optopt == 'c' || optopt == 'p')
                fprintf(stderr, "option -%c requires an argument.\n", optopt);
            else if (isprint (optopt))
                fprintf(stderr, "unknown option `-%c'.\n", optopt);
            else
                fprintf(stderr, "unknown option character `\\x%x'.\n", optopt);
            print_usage(argv);
            exit(1);
        default:
            fprintf(stderr, "BUG: can't process option -%c\n", optopt);
            exit(1);
        }
    }

    if (hosts == NULL)
        hosts = split_delimited_string(getenv("LOGJAM_DEVICES"));

    if (hosts)
        augment_zmq_connection_specs(&hosts, 9606);

    if (interface == NULL)
        interface = getenv("LOGJAM_INTERACE");
    if (interface)
        interface = augment_zmq_connection_spec(interface, 9610);

    if (subscriptions == NULL)
        subscriptions = split_delimited_string(getenv("LOGJAM_SUBSCRIPTIONS"));

    if (rcv_hwm == -1 && (v = getenv("LOGJAM_RCV_HWM")))
        rcv_hwm = atoi(v);

    if (snd_hwm == -1 && (v = getenv("LOGJAM_SND_HWM")))
        snd_hwm = atoi(v);
}