int _gnrc_netif_config(int argc, char **argv) { if (argc < 2) { gnrc_netif_t *netif = NULL; while ((netif = gnrc_netif_iter(netif))) { _netif_list(netif->pid); } return 0; } else if (_is_number(argv[1])) { kernel_pid_t iface = atoi(argv[1]); if (_is_iface(iface)) { if (argc < 3) { _netif_list(iface); return 0; } else if (strcmp(argv[2], "set") == 0) { if (argc < 5) { _set_usage(argv[0]); return 1; } return _netif_set(argv[0], iface, argv[3], argv[4]); } else if (strcmp(argv[2], "add") == 0) { if (argc < 4) { _add_usage(argv[0]); return 1; } return _netif_add(argv[0], (kernel_pid_t)iface, argc - 3, argv + 3); } else if (strcmp(argv[2], "del") == 0) { if (argc < 4) { _del_usage(argv[0]); return 1; } return _netif_del((kernel_pid_t)iface, argv[3]); } #ifdef MODULE_L2FILTER else if (strcmp(argv[2], "l2filter") == 0) { if (argc < 5) { _l2filter_usage(argv[2]); } else if (strcmp(argv[3], "add") == 0) { return _netif_addrm_l2filter(iface, argv[4], true); } else if (strcmp(argv[3], "del") == 0) { return _netif_addrm_l2filter(iface, argv[4], false); } else { _l2filter_usage(argv[2]); } return 1; } #endif #ifdef MODULE_NETSTATS else if (strcmp(argv[2], "stats") == 0) { uint8_t module; bool reset = false; /* check for requested module */ if ((argc == 3) || (strcmp(argv[3], "all") == 0)) { module = NETSTATS_ALL; } else if (strcmp(argv[3], "l2") == 0) { module = NETSTATS_LAYER2; } else if (strcmp(argv[3], "ipv6") == 0) { module = NETSTATS_IPV6; } else { printf("Module %s doesn't exist or does not provide statistics.\n", argv[3]); return 0; } /* check if reset flag was given */ if ((argc > 4) && (strncmp(argv[4], "reset", 5) == 0)) { reset = true; } if (module & NETSTATS_LAYER2) { _netif_stats((kernel_pid_t) iface, NETSTATS_LAYER2, reset); } if (module & NETSTATS_IPV6) { _netif_stats((kernel_pid_t) iface, NETSTATS_IPV6, reset); } return 1; } #endif else if (strcmp(argv[2], "help") == 0) { _usage(argv[0]); return 0; } else { return _netif_flag(argv[0], iface, argv[2]); } } else { puts("error: invalid interface given"); return 1; } } _usage(argv[0]); return 1; }
/* getDNSInfo of the DNS provider. */ void DNSInfo::getDNSInfo(const int argc, const char** argv) { // ATTN-SLC-16-May-02-P1 enhance to take host & user info // Decided to keep local only for first release Boolean cimFormat = false; // before we even connect to CIMOM, make sure we're // syntactically valid if (argc > 2) { _usage(); exit(1); } if (argc == 2) { // only support one option, -c for CIM formatting const char *opt = argv[1]; if (strcmp(opt,"-c") == 0) { cimFormat = true; } else { _usage(); exit(1); } } // need to first connect to the CIMOM try { // specify the timeout value for the connection (if inactive) // in milliseconds, thus setting to one minute CIMClient client; client.setTimeout(60 * 1000); client.connectLocal(); Boolean deepInheritance = true; Boolean localOnly = true; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; Uint32 numberInstances; #ifdef DEBUG cout << "DNSInfo::getDNSInfo() - doing enumerateInstances . . ." << endl; #endif Array<CIMInstance> cimNInstances = client.enumerateInstances(NAMESPACE, CLASSNAME, deepInheritance, localOnly, includeQualifiers, includeClassOrigin ); #ifdef DEBUG cout << "DNSInfo::getDNSInfo() - enumerateInstances done" << endl; #endif numberInstances = cimNInstances.size(); // while we only have one instance (the running OS), we can take the // first instance. When the OSProvider supports installed OSs as well, // will need to select the runningOS instance for (Uint32 i = 0; i < cimNInstances.size(); i++) { CIMObjectPath instanceRef = cimNInstances[i].getPath (); if ( !(instanceRef.getClassName().equal (CIMName (CLASSNAME)))) { errorExit("EnumerateInstances failed"); } // first gather the interesting properties gatherProperties(cimNInstances[i], cimFormat); // then display them displayProperties(); } // end for looping through instances } // end try catch(Exception& e) { errorExit(e.getMessage()); } }
/* * parse_command_line */ extern void parse_command_line( int argc, char* argv[] ) { char *env_val = NULL; bool override_format_env = false; int opt_char; int option_index; static struct option long_options[] = { {"accounts", required_argument, 0, 'A'}, {"all", no_argument, 0, 'a'}, {"format", required_argument, 0, 'o'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"hide", no_argument, 0, OPT_LONG_HIDE}, {"iterate", required_argument, 0, 'i'}, {"jobs", optional_argument, 0, 'j'}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"node", required_argument, 0, 'n'}, {"nodes", required_argument, 0, 'n'}, {"noheader", no_argument, 0, 'h'}, {"partitions", required_argument, 0, 'p'}, {"qos", required_argument, 0, 'q'}, {"reservation",required_argument, 0, 'R'}, {"sort", required_argument, 0, 'S'}, {"start", no_argument, 0, OPT_LONG_START}, {"steps", optional_argument, 0, 's'}, {"states", required_argument, 0, 't'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"users", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {NULL, 0, 0, 0} }; if (getenv("SQUEUE_ALL")) params.all_flag = true; if ( ( env_val = getenv("SQUEUE_SORT") ) ) params.sort = xstrdup(env_val); if ( ( env_val = getenv("SLURM_CLUSTERS") ) ) { if (!(params.clusters = slurmdb_get_info_cluster(env_val))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "SLURM_CLUSTERS. Use 'sacctmgr --list " "cluster' to see avaliable clusters.", env_val); exit(1); } working_cluster_rec = list_peek(params.clusters); } while ((opt_char = getopt_long(argc, argv, "A:ahi:j::ln:M:o:p:q:R:s::S:t:u:U:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"squeue --help\" " "for more information\n"); exit(1); case (int) 'A': case (int) 'U': /* backwards compatibility */ xfree(params.accounts); params.accounts = xstrdup(optarg); params.account_list = _build_str_list( params.accounts ); break; case (int)'a': params.all_flag = true; break; case (int)'h': params.no_header = true; break; case (int) 'i': params.iterate= atoi(optarg); if (params.iterate <= 0) { error ("--iterate=%s\n", optarg); exit(1); } break; case (int) 'j': if (optarg) { params.jobs = xstrdup(optarg); params.job_list = _build_job_list(params.jobs); } params.job_flag = true; break; case (int) 'l': params.long_list = true; override_format_env = true; break; case (int) 'M': if (params.clusters) list_destroy(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "--cluster. Use 'sacctmgr --list " "cluster' to see avaliable clusters.", optarg); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case (int) 'n': if (params.nodes) hostset_destroy(params.nodes); params.nodes = hostset_create(optarg); if (params.nodes == NULL) { error("'%s' invalid entry for --nodes", optarg); exit(1); } break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); override_format_env = true; break; case (int) 'p': xfree(params.partitions); params.partitions = xstrdup(optarg); params.part_list = _build_str_list( params.partitions ); params.all_flag = true; break; case (int) 'q': xfree(params.qoss); params.qoss = xstrdup(optarg); params.qos_list = _build_str_list( params.qoss ); break; case (int) 'R': xfree(params.reservation); params.reservation = xstrdup(optarg); break; case (int) 's': if (optarg) { params.steps = xstrdup(optarg); params.step_list = _build_step_list(params.steps); } params.step_flag = true; override_format_env = true; break; case (int) 'S': xfree(params.sort); params.sort = xstrdup(optarg); break; case (int) 't': xfree(params.states); params.states = xstrdup(optarg); params.state_list = _build_state_list( params.states ); break; case (int) 'u': xfree(params.users); params.users = xstrdup(optarg); params.user_list = _build_user_list( params.users ); break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version(); exit(0); case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_HIDE: params.all_flag = false; break; case OPT_LONG_START: params.start_flag = true; break; case OPT_LONG_USAGE: _usage(); exit(0); } } if ( override_format_env == false ) { if ( ( env_val = getenv("SQUEUE_FORMAT") ) ) params.format = xstrdup(env_val); } params.cluster_flags = slurmdb_setup_cluster_flags(); if (optind < argc) { if (params.job_flag) { params.jobs = xstrdup(argv[optind++]); params.job_list = _build_job_list(params.jobs); } else if (params.step_flag) { params.steps = xstrdup(argv[optind++]); params.step_list = _build_step_list(params.steps); } if (optind < argc) { error("Unrecognized option: %s",argv[optind]); _usage(); exit(1); } } if ( params.job_flag && params.step_flag) { if (params.job_list) { verbose("Printing job steps with job filter"); params.job_flag = false; } else { error("Incompatible options --jobs and --steps"); exit(1); } } if ( params.nodes ) { char *name1 = NULL; char *name2 = NULL; hostset_t nodenames = hostset_create(NULL); if (nodenames == NULL) fatal("malloc failure"); while ( hostset_count(params.nodes) > 0 ) { name1 = hostset_pop(params.nodes); /* localhost = use current host name */ if ( strcasecmp("localhost", name1) == 0 ) { name2 = xmalloc(128); gethostname_short(name2, 128); } else { /* translate NodeHostName to NodeName */ name2 = slurm_conf_get_nodename(name1); /* use NodeName if translation failed */ if ( name2 == NULL ) name2 = xstrdup(name1); } hostset_insert(nodenames, name2); free(name1); xfree(name2); } /* Replace params.nodename with the new one */ hostset_destroy(params.nodes); params.nodes = nodenames; } if ( ( params.accounts == NULL ) && ( env_val = getenv("SQUEUE_ACCOUNT") ) ) { params.accounts = xstrdup(env_val); params.account_list = _build_str_list( params.accounts ); } if ( ( params.partitions == NULL ) && ( env_val = getenv("SQUEUE_PARTITION") ) ) { params.partitions = xstrdup(env_val); params.part_list = _build_str_list( params.partitions ); params.all_flag = true; } if ( ( params.qoss == NULL ) && ( env_val = getenv("SQUEUE_QOS") ) ) { params.qoss = xstrdup(env_val); params.qos_list = _build_str_list( params.qoss ); } if ( ( params.states == NULL ) && ( env_val = getenv("SQUEUE_STATES") ) ) { params.states = xstrdup(env_val); params.state_list = _build_state_list( params.states ); } if ( ( params.users == NULL ) && ( env_val = getenv("SQUEUE_USERS") ) ) { params.users = xstrdup(env_val); params.user_list = _build_user_list( params.users ); } if ( params.start_flag && !params.step_flag ) { /* Set more defaults */ if (params.format == NULL) params.format = xstrdup("%.7i %.9P %.8j %.8u %.2t %.19S %.6D %R"); if (params.sort == NULL) params.sort = xstrdup("S"); if (params.states == NULL) { params.states = xstrdup("PD"); params.state_list = _build_state_list( params.states ); } } params.max_cpus = _max_cpus_per_node(); if ( params.verbose ) _print_options(); }
/* getNISInfo of the NIS provider. */ void NISInfo::getNISInfo(const int argc, const char** argv) { String hostname; String user; String passwd; // before we even connect to CIMOM, make sure we're // syntactically valid if (argc > 1) { _usage(); exit(1); } // need to first connect to the CIMOM try { // specify the timeout value for the connection (if inactive) // in milliseconds, thus setting to one minute CIMClient client; client.setTimeout(120 * 1000); client.connectLocal(); Boolean deepInheritance = true; Boolean localOnly = true; Boolean includeQualifiers = false; Boolean includeClassOrigin = false; Uint32 numberInstances; #ifdef DEBUG cout << "NISInfo::getNISInfo() - doing enumerateInstances . . ." << endl; #endif Array<CIMInstance> cimNInstances = client.enumerateInstances(NAMESPACE, CLASSNAME, deepInheritance, localOnly, includeQualifiers, includeClassOrigin ); #ifdef DEBUG cout << "NISInfo::getNISInfo() - enumerateInstances done" << endl; #endif numberInstances = cimNInstances.size(); for (Uint32 i = 0; i < cimNInstances.size(); i++) { CIMObjectPath instanceRef = cimNInstances[i].getPath (); if ( !(instanceRef.getClassName().equal (CIMName (CLASSNAME)))) { errorExit("EnumerateInstances failed"); } // first gather the interesting properties gatherProperties(cimNInstances[i]); // then display them displayProperties(); } // end for looping through instances } catch(Exception& e) { errorExit(e.getMessage()); } }
int main (int argc, char *argv[]) { int error_code = SLURM_SUCCESS, i, opt_char, input_field_count; char **input_fields; log_options_t opts = LOG_OPTS_STDERR_ONLY ; int local_exit_code = 0; char *temp = NULL; int option_index; static struct option long_options[] = { {"help", 0, 0, 'h'}, {"usage", 0, 0, 'h'}, {"immediate",0, 0, 'i'}, {"noheader",0, 0, 'n'}, {"oneliner", 0, 0, 'o'}, {"parsable", 0, 0, 'p'}, {"parsable2", 0, 0, 'P'}, {"quiet", 0, 0, 'Q'}, {"readonly", 0, 0, 'r'}, {"associations", 0, 0, 's'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {NULL, 0, 0, 0} }; command_name = argv[0]; rollback_flag = 1; exit_code = 0; exit_flag = 0; input_field_count = 0; quiet_flag = 0; readonly_flag = 0; verbosity = 0; slurm_conf_init(NULL); log_init("sacctmgr", opts, SYSLOG_FACILITY_DAEMON, NULL); while((opt_char = getopt_long(argc, argv, "hionpPQrsvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sacctmgr --help\" " "for more information\n"); exit(1); break; case (int)'h': _usage (); exit(exit_code); break; case (int)'i': rollback_flag = 0; break; case (int)'o': one_liner = 1; break; case (int)'n': print_fields_have_header = 0; break; case (int)'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case (int)'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case (int)'Q': quiet_flag = 1; break; case (int)'r': readonly_flag = 1; break; case (int)'s': with_assoc_flag = 1; break; case (int)'v': quiet_flag = -1; verbosity++; break; case (int)'V': _print_version(); exit(exit_code); break; default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (argc > MAX_INPUT_FIELDS) /* bogus input, but continue anyway */ input_words = argc; else input_words = 128; input_fields = (char **) xmalloc (sizeof (char *) * input_words); if (optind < argc) { for (i = optind; i < argc; i++) { input_fields[input_field_count++] = argv[i]; } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } /* Check to see if we are running a supported accounting plugin */ temp = slurm_get_accounting_storage_type(); if (strcasecmp(temp, "accounting_storage/slurmdbd") && strcasecmp(temp, "accounting_storage/mysql")) { fprintf (stderr, "You are not running a supported " "accounting_storage plugin\n(%s).\n" "Only 'accounting_storage/slurmdbd' " "and 'accounting_storage/mysql' are supported.\n", temp); xfree(temp); exit(1); } xfree(temp); errno = 0; db_conn = slurmdb_connection_get(); if (errno != SLURM_SUCCESS) { int tmp_errno = errno; if ((input_field_count == 2) && (!strncasecmp(argv[2], "Configuration", strlen(argv[1]))) && ((!strncasecmp(argv[1], "list", strlen(argv[0]))) || (!strncasecmp(argv[1], "show", strlen(argv[0]))))) { if (tmp_errno == ESLURM_DB_CONNECTION) { tmp_errno = 0; sacctmgr_list_config(true); } else sacctmgr_list_config(false); } errno = tmp_errno; if (errno) error("Problem talking to the database: %m"); exit(1); } my_uid = getuid(); if (input_field_count) exit_flag = 1; else error_code = _get_command (&input_field_count, input_fields); while (error_code == SLURM_SUCCESS) { error_code = _process_command (input_field_count, input_fields); if (error_code || exit_flag) break; error_code = _get_command (&input_field_count, input_fields); /* This is here so if someone made a mistake we allow * them to fix it and let the process happen since there * are checks for global exit_code we need to reset it. */ if (exit_code) { local_exit_code = exit_code; exit_code = 0; } } /* readline library writes \n when echoes the input string, it does * not when it sees the EOF, so in that case we have to print it to * align the terminal prompt. */ if (exit_flag == 2) putchar('\n'); if (local_exit_code) exit_code = local_exit_code; acct_storage_g_close_connection(&db_conn); slurm_acct_storage_fini(); if (g_qos_list) list_destroy(g_qos_list); if (g_res_list) list_destroy(g_res_list); exit(exit_code); }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char **argv) { char *env_val = NULL; int opt_char; int option_index; hostlist_t host_list; bool long_form = false; bool opt_a_set = false, opt_p_set = false; bool env_a_set = false, env_p_set = false; static struct option long_options[] = { {"all", no_argument, 0, 'a'}, {"bg", no_argument, 0, 'b'}, {"dead", no_argument, 0, 'd'}, {"exact", no_argument, 0, 'e'}, {"federation",no_argument, 0, OPT_LONG_FEDR}, {"help", no_argument, 0, OPT_LONG_HELP}, {"hide", no_argument, 0, OPT_LONG_HIDE}, {"iterate", required_argument, 0, 'i'}, {"local", no_argument, 0, OPT_LONG_LOCAL}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"noconvert", no_argument, 0, OPT_LONG_NOCONVERT}, {"noheader", no_argument, 0, 'h'}, {"Node", no_argument, 0, 'N'}, {"format", required_argument, 0, 'o'}, {"Format", required_argument, 0, 'O'}, {"partition", required_argument, 0, 'p'}, {"responding",no_argument, 0, 'r'}, {"list-reasons", no_argument, 0, 'R'}, {"summarize", no_argument, 0, 's'}, {"sort", required_argument, 0, 'S'}, {"states", required_argument, 0, 't'}, {"reservation",no_argument, 0, 'T'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {NULL, 0, 0, 0} }; params.convert_flags = CONVERT_NUM_UNIT_EXACT; if (slurmctld_conf.fed_params && strstr(slurmctld_conf.fed_params, "fed_display")) params.federation_flag = true; if (getenv("SINFO_ALL")) { env_a_set = true; params.all_flag = true; } if (getenv("SINFO_FEDERATION")) params.federation_flag = true; if (getenv("SINFO_LOCAL")) params.local = true; if ( ( env_val = getenv("SINFO_PARTITION") ) ) { env_p_set = true; params.partition = xstrdup(env_val); params.part_list = _build_part_list(env_val); params.all_flag = true; } if (env_a_set && env_p_set) { error("Conflicting options, SINFO_ALL and SINFO_PARTITION, specified. " "Please choose one or the other."); exit(1); } if ( ( env_val = getenv("SINFO_SORT") ) ) params.sort = xstrdup(env_val); if ( ( env_val = getenv("SLURM_CLUSTERS") ) ) { if (!(params.clusters = slurmdb_get_info_cluster(env_val))) { print_db_notok(env_val, 1); exit(1); } working_cluster_rec = list_peek(params.clusters); params.local = true; } while ((opt_char = getopt_long(argc, argv, "abdehi:lM:n:No:O:p:rRsS:t:TvV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sinfo --help\" for more information\n"); exit(1); break; case (int)'a': opt_a_set = true; xfree(params.partition); FREE_NULL_LIST(params.part_list); params.all_flag = true; break; case (int)'b': params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.cluster_flags & CLUSTER_FLAG_BG) params.bg_flag = true; else { error("Must be on a BG system to use --bg " "option, if using --cluster option " "put the --bg option " "after the --cluster option."); exit(1); } break; case (int)'d': params.dead_nodes = true; break; case (int)'e': params.exact_match = true; break; case (int)'h': params.no_header = true; break; case (int) 'i': params.iterate= atoi(optarg); if (params.iterate <= 0) { error ("Error: invalid entry for " "--iterate=%s", optarg); exit(1); } break; case (int) 'l': params.long_output = true; break; case (int) 'M': FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(params.clusters); params.local = true; break; case OPT_LONG_NOCONVERT: params.convert_flags |= CONVERT_NUM_UNIT_NO; break; case (int) 'n': xfree(params.nodes); params.nodes = xstrdup(optarg); /* * confirm valid nodelist entry */ host_list = hostlist_create(params.nodes); if (!host_list) { error("'%s' invalid entry for --nodes", optarg); exit(1); } if (hostlist_count(host_list) == 1) { params.node_name_single = true; xfree(params.nodes); params.nodes = hostlist_deranged_string_xmalloc(host_list); } else params.node_name_single = false; hostlist_destroy(host_list); break; case (int) 'N': params.node_flag = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'O': long_form = true; xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'p': opt_p_set = true; xfree(params.partition); FREE_NULL_LIST(params.part_list); params.partition = xstrdup(optarg); params.part_list = _build_part_list(optarg); params.all_flag = true; break; case (int) 'r': params.responding_nodes = true; break; case (int) 'R': params.list_reasons = true; break; case (int) 's': params.summarize = true; break; case (int) 'S': xfree(params.sort); params.sort = xstrdup(optarg); break; case (int) 't': xfree(params.states); params.states = xstrdup(optarg); if (!(params.state_list = _build_state_list(optarg))) { error ("valid states: %s", _node_state_list ()); exit (1); } break; case (int) 'T': params.reservation_flag = true; break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version (); exit(0); case (int) OPT_LONG_FEDR: params.federation_flag = true; break; case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); case OPT_LONG_HIDE: params.all_flag = false; break; case OPT_LONG_LOCAL: params.local = true; break; } } if (opt_a_set && opt_p_set) { error("Conflicting options, -a and -p, specified. " "Please choose one or the other."); exit(1); } params.cluster_flags = slurmdb_setup_cluster_flags(); if (params.federation_flag && !params.clusters && !params.local) { void *ptr = NULL; char *cluster_name = slurm_get_cluster_name(); if (slurm_load_federation(&ptr) || !cluster_in_federation(ptr, cluster_name)) { /* Not in federation */ params.local = true; slurm_destroy_federation_rec(ptr); } else { params.fed = (slurmdb_federation_rec_t *) ptr; } xfree(cluster_name); } if ( params.format == NULL ) { if ( params.summarize ) { params.part_field_flag = true; /* compute size later */ if (params.cluster_flags & CLUSTER_FLAG_BG) params.format = "%9P %.5a %.10l %.32F %N"; else params.format = "%9P %.5a %.10l %.16F %N"; } else if ( params.node_flag ) { params.node_field_flag = true; /* compute size later */ params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%N %.6D %.9P %.11T %.4c %.8z %.6m %.8d %.6w %.8f %20E" : "%N %.6D %.9P %6t"; } else if (params.list_reasons) { params.format = params.long_output ? "%20E %12U %19H %6t %N" : "%20E %9u %19H %N"; } else if ((env_val = getenv ("SINFO_FORMAT"))) { params.format = xstrdup(env_val); } else if (params.fed) { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %8V %.5a %.10l %.10s %.4r %.8h %.10g %.6D %.11T %N" : "%9P %8V %.5a %.10l %.6D %.6t %N"; } else { params.part_field_flag = true; /* compute size later */ params.format = params.long_output ? "%9P %.5a %.10l %.10s %.4r %.8h %.10g %.6D %.11T %N" : "%9P %.5a %.10l %.6D %.6t %N"; } } if (long_form) _parse_long_format(params.format); else _parse_format(params.format); if (params.list_reasons && (params.state_list == NULL)) { params.states = xstrdup("down,fail,drain,error"); if (!(params.state_list = _build_state_list (params.states))) fatal ("Unable to build state list for -R!"); } if (params.dead_nodes || params.nodes || params.partition || params.responding_nodes ||params.state_list) params.filtering = true; if (params.verbose) _print_options(); }
/* * parse_command_line */ extern void parse_command_line( int argc, char* argv[] ) { int opt_char; int option_index; static struct option long_options[] = { {"noheader", no_argument, 0, 'h'}, {"jobs", optional_argument, 0, 'j'}, {"long", no_argument, 0, 'l'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"norm", no_argument, 0, 'n'}, {"format", required_argument, 0, 'o'}, {"user", required_argument, 0, 'u'}, {"users", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"weights", no_argument, 0, 'w'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; /* get defaults from environment */ _opt_env(); while((opt_char = getopt_long(argc, argv, "hj::lM:no:u:vVw", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sprio --help\" " "for more information\n"); exit(1); case (int)'h': params.no_header = true; break; case (int) 'j': if (optarg) { params.jobs = xstrdup(optarg); params.job_list = _build_job_list(params.jobs); } params.job_flag = true; break; case (int) 'l': params.long_list = true; break; case (int) 'M': FREE_NULL_LIST(params.clusters); if (!(params.clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } break; case (int) 'n': params.normalized = true; break; case (int) 'o': xfree(params.format); params.format = xstrdup(optarg); break; case (int) 'u': xfree(params.users); params.users = xstrdup(optarg); params.user_list = _build_user_list(params.users); break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version (); exit(0); case (int) 'w': params.weights = true; break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } if (optind < argc) { if (params.job_flag) { params.jobs = xstrdup(argv[optind++]); params.job_list = _build_job_list(params.jobs); } if (optind < argc) { error("Unrecognized option: %s",argv[optind]); _usage(); exit(1); } } if (params.verbose) _print_options(); if (params.clusters) { if (list_count(params.clusters) > 1) { fatal("Only one cluster can be used at a time with " "sprio"); } working_cluster_rec = list_peek(params.clusters); } }
int main(int argc, char *argv[]) { int ret; sock_t fd, fd_acpt; uint32_t raddr; char buf[SIDP_PKT_MSG_MAX_LEN]; size_t len; struct sidpconn conn; if (argc != 3) _usage(argc, argv); if ((fd = example_net_stream_listen(NULL, 6767, 10)) < 0) { printf("Error #1.\n"); return 1; } for (;;) { if ((fd_acpt = example_net_stream_accept(fd, &raddr)) < 0) { printf("Error #2.\n"); return 1; } sidp_conn_init(&conn, fd_acpt, 20, 0, 0, SIDP_CONN_TYPE_NORMAL); sidp_conn_set_support(&conn, SIDP_SUPPORT_ENCAP_DEFAULT_FL); sidp_conn_set_support(&conn, SIDP_SUPPORT_COMPRESS_LZO_FL); sidp_conn_set_support(&conn, SIDP_SUPPORT_CIPHER_XSALSA20_FL); ret = sidp_seq_init_host(&conn); if (ret < 0) { printf("Error #3: %d\n", ret); sidp_conn_close(&conn); return 1; } printf("Connection from device: %d\n", conn.ddev); ret = sidp_seq_auth_host(&conn, argv[1], (unsigned char *) argv[2]); if (ret < 0) { printf("Error #3: %d\n", ret); sidp_conn_close(&conn); return 1; } ret = sidp_seq_negotiation_host(&conn); if (ret < 0) { printf("Error #4: %d\n", ret); sidp_conn_close(&conn); return 1; } /* Key was already set on the authentication sequence. * This is just an example of usage of sidp_conn_set_key(). * If you want to change the encryption key at the middle of the * data sequence, you must use this function to do it on both * sides of the connection. */ sidp_conn_set_key(&conn, (unsigned char *) argv[2]); ret = sidp_seq_data_recv(&conn, buf, &len); if (ret < 0) { printf("Error #5: %d\n", ret); sidp_conn_close(&conn); return 1; } printf("buffer: %s\n", buf); sidp_conn_close(&conn); } return 0; }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char **argv) { char *sbcast_parameters; char *end_ptr = NULL, *env_val = NULL, *sep, *tmp; int opt_char; int option_index; static struct option long_options[] = { {"compress", optional_argument, 0, 'C'}, {"fanout", required_argument, 0, 'F'}, {"force", no_argument, 0, 'f'}, {"jobid", required_argument, 0, 'j'}, {"preserve", no_argument, 0, 'p'}, {"size", required_argument, 0, 's'}, {"timeout", required_argument, 0, 't'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; if ((sbcast_parameters = slurm_get_sbcast_parameters()) && (tmp = strcasestr(sbcast_parameters, "Compression="))) { tmp += 12; sep = strchr(tmp, ','); if (sep) sep[0] = '\0'; params.compress = parse_compress_type(tmp); if (sep) sep[0] = ','; } if ((env_val = getenv("SBCAST_COMPRESS"))) params.compress = parse_compress_type(env_val); if ( ( env_val = getenv("SBCAST_FANOUT") ) ) params.fanout = atoi(env_val); if (getenv("SBCAST_FORCE")) params.force = true; params.job_id = NO_VAL; params.pack_job_offset = NO_VAL; params.step_id = NO_VAL; if (getenv("SBCAST_PRESERVE")) params.preserve = true; if ( ( env_val = getenv("SBCAST_SIZE") ) ) params.block_size = _map_size(env_val); else params.block_size = 8 * 1024 * 1024; if ( ( env_val = getenv("SBCAST_TIMEOUT") ) ) params.timeout = (atoi(env_val) * 1000); optind = 0; while ((opt_char = getopt_long(argc, argv, "CfF:j:ps:t:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sbcast --help\" for more information\n"); exit(1); break; case (int)'C': params.compress = parse_compress_type(optarg); break; case (int)'f': params.force = true; break; case (int)'F': params.fanout = atoi(optarg); break; case (int)'j': params.job_id = strtol(optarg, &end_ptr, 10); if (end_ptr[0] == '+') { params.pack_job_offset = strtol(end_ptr+1, &end_ptr, 10); } if (end_ptr[0] == '.') params.step_id = strtol(end_ptr+1, NULL, 10); break; case (int)'p': params.preserve = true; break; case (int) 's': params.block_size = _map_size(optarg); break; case (int)'t': params.timeout = (atoi(optarg) * 1000); break; case (int) 'v': params.verbose++; break; case (int) 'V': print_slurm_version(); exit(0); case (int) OPT_LONG_HELP: _help(); exit(0); case (int) OPT_LONG_USAGE: _usage(); exit(0); } } if ((argc - optind) != 2) { fprintf(stderr, "Need two file names, have %d names\n", (argc - optind)); fprintf(stderr, "Try \"sbcast --help\" for more information\n"); exit(1); } if (params.job_id == NO_VAL) { if (!(env_val = getenv("SLURM_JOB_ID"))) { error("Need a job id to run this command. " "Run from within a Slurm job or use the " "--jobid option."); exit(1); } params.job_id = strtol(env_val, &end_ptr, 10); if (end_ptr[0] == '.') params.step_id = strtol(end_ptr+1, NULL, 10); } params.src_fname = xstrdup(argv[optind]); if (argv[optind+1][0] == '/') { params.dst_fname = xstrdup(argv[optind+1]); } else if (sbcast_parameters && (tmp = strcasestr(sbcast_parameters, "DestDir="))) { tmp += 8; sep = strchr(tmp, ','); if (sep) sep[0] = '\0'; xstrfmtcat(params.dst_fname, "%s/%s", tmp, argv[optind+1]); if (sep) sep[0] = ','; } else { #ifdef HAVE_GET_CURRENT_DIR_NAME tmp = get_current_dir_name(); #else tmp = malloc(PATH_MAX); tmp = getcwd(tmp, PATH_MAX); #endif xstrfmtcat(params.dst_fname, "%s/%s", tmp, argv[optind+1]); free(tmp); } xfree(sbcast_parameters); if (params.verbose) _print_options(); }
int main (int argc, char *argv[]) { int error_code = SLURM_SUCCESS, i, opt_char, input_field_count; char **input_fields; log_options_t opts = LOG_OPTS_STDERR_ONLY ; char *temp = NULL; int option_index; static struct option long_options[] = { {"all_clusters", 0, 0, 'a'}, {"help", 0, 0, 'h'}, {"immediate",0, 0, 'i'}, {"noheader", 0, 0, 'n'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"quiet", 0, 0, 'Q'}, {"sort", 0, 0, 's'}, {"usage", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {NULL, 0, 0, 0} }; command_name = argv[0]; exit_code = 0; exit_flag = 0; input_field_count = 0; quiet_flag = 0; log_init("sreport", opts, SYSLOG_FACILITY_DAEMON, NULL); /* Check to see if we are running a supported accounting plugin */ temp = slurm_get_accounting_storage_type(); if (strcasecmp(temp, "accounting_storage/slurmdbd") && strcasecmp(temp, "accounting_storage/mysql")) { fprintf (stderr, "You are not running a supported " "accounting_storage plugin\n(%s).\n" "Only 'accounting_storage/slurmdbd' " "and 'accounting_storage/mysql' are supported.\n", temp); xfree(temp); exit(1); } xfree(temp); while((opt_char = getopt_long(argc, argv, "ahnpPQs:t:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sreport --help\" " "for more information\n"); exit(1); break; case (int)'h': _usage (); exit(exit_code); break; case (int)'a': all_clusters_flag = 1; break; case (int)'n': print_fields_have_header = 0; break; case (int)'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case (int)'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case (int)'Q': quiet_flag = 1; break; case (int)'s': _set_sort(optarg); break; case (int)'t': _set_time_format(optarg); break; case (int)'v': quiet_flag = -1; break; case (int)'V': _print_version(); exit(exit_code); break; default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (argc > MAX_INPUT_FIELDS) /* bogus input, but continue anyway */ input_words = argc; else input_words = 128; input_fields = (char **) xmalloc (sizeof (char *) * input_words); if (optind < argc) { for (i = optind; i < argc; i++) { input_fields[input_field_count++] = argv[i]; } } db_conn = slurmdb_connection_get(); if (errno) { error("Problem talking to the database: %m"); exit(1); } my_uid = getuid(); if (input_field_count) exit_flag = 1; else error_code = _get_command (&input_field_count, input_fields); while (error_code == SLURM_SUCCESS) { error_code = _process_command (input_field_count, input_fields); if (error_code || exit_flag) break; error_code = _get_command (&input_field_count, input_fields); } if (exit_flag == 2) putchar('\n'); slurmdb_connection_close(&db_conn); slurm_acct_storage_fini(); exit(exit_code); }
int main(int argc, char **argv) { int i; int j; int size; int bcnt[2]; int nwrite; char ans; char *str; char *end; double r; if(argc < 2) size = NSTRING; else size = strtol(argv[1], &end, 10); if(size < 10 || size > MAX_NSTRING || errno == ERANGE) _usage("Range Exception (10 <= x <= %d)\n", MAX_NSTRING); /* Initialization */ srand(time(NULL)); ans = 0; str = malloc(sizeof(char) * size); if(str == NULL) eoutput("Can't allocate memories"); memset(str, ANSWER_CHAR, sizeof(char) * size); nwrite = size / 2 - rand() % (size / 2); doutput(CONSOLE_OUTPUT, "nwrite: %d\n", nwrite); for (i = 0; i < size && nwrite > 0; i++) { r = (double)rand() / UINT_MAX; doutput(CONSOLE_OUTPUT, "r: %lf\n", r); if(r < 0.20) { str[i] = 'b' + rand() % 25; nwrite--; } } #ifdef DEBUG for (i = 0; i < size; i++) fprintf(stdout, "%c ", str[i]); fprintf(stdout, "\n"); #endif /* DEBUG */ /* Start solving ... */ for(i = 0; i < sizeof(char) * 8; i++) { memset(&bcnt[0], 0x00, sizeof(int) * 2); for(j = 0; j < size; j++) { bcnt[BITCOUNT(str[j], i)]++; if(j > size / 2 && (bcnt[0] > size / 2 || bcnt[1] > size / 2)) break; } ans |= ((bcnt[0] > bcnt[1])? 0 : 1) << i; } doutput(CONSOLE_OUTPUT, "answer: %c\n", ans); if(ans == ANSWER_CHAR) fprintf(stdout, "Done correctly\n"); else fprintf(stdout, "Done wrongly\n"); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int n = 0; int fail = 0; char **dbx_files = NULL; char *dbx_dir = NULL; char *out_dir = NULL; int num_dbx_files = 0; dbx_options_t options = { 0 }; int c = -1; printf("UnDBX v" DBX_VERSION " (" __DATE__ ")\n"); fflush(stdout); if (argc == 1) { #ifdef _WIN32 _gui(argv[0]); #else _usage(argv[0], EXIT_SUCCESS); #endif } options.verbosity = DBX_VERBOSITY_INFO; while (1) { static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"verbosity", required_argument, NULL, 'v'}, {"recover", no_argument, NULL, 'r'}, {"safe-mode", no_argument, NULL, 's'}, {"delete", no_argument, NULL, 'D'}, {"ignore0", no_argument, NULL, 'i'}, {"debug", no_argument, NULL, 'd'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "hVv:rsDid", long_options, NULL); if (c == -1 || c == '?' || c == ':') break; switch (c) { case 'h': _usage(argv[0], EXIT_SUCCESS); break; case 'V': exit(EXIT_SUCCESS); break; case 'v': options.verbosity = atoi(optarg); break; case 'r': options.recover = 1; break; case 's': options.safe_mode = 1; break; case 'D': options.delete_deleted = 1; break; case 'i': options.ignore0 = 1; break; case 'd': options.debug = 1; break; default: break; } } if (c == '?') _usage(argv[0], EXIT_FAILURE); if (argc - optind < 1 || argc - optind > 2) { fprintf(stderr, "error: bad command line\n"); _usage(argv[0], EXIT_FAILURE); } dbx_dir = strdup(argv[optind]); if (argc - optind == 2) out_dir = argv[optind + 1]; else out_dir = "."; dbx_files = _get_files(&dbx_dir, &num_dbx_files); for(n = 0; n < num_dbx_files; n++) { if (_undbx(dbx_dir, out_dir, dbx_files[n], &options)) fail++; } if (num_dbx_files > 0) dbx_progress_message(NULL, DBX_STATUS_OK, "Extracted %d out of %d DBX files", n - fail, n); else dbx_progress_message(NULL, DBX_STATUS_WARNING, "can't find DBX files in \"%s\"", dbx_dir); sys_glob_free(dbx_files); free(dbx_dir); return EXIT_SUCCESS; }
void Settings::processParams(int argc, char **argv) { int c; if (argc < 2) { _usage(); exit(0); } while ((c = getopt(argc, argv, "hf:H:u:c:t:r:o:")) != -1) { switch (c) { case 'f' : fileName.assign(optarg); if (fileName.empty()) { std::cerr <<"Fatal: Illegal file name"<< fileType << std::endl; exit(-1); } break; case 'H' : host.assign(optarg); break; case 'u' : urlPrefix.assign(optarg); break; case 'c' : threadNum = atoi(optarg); if (threadNum <= 0) { threadNum = DEFAULT_THREAD_NUM; } break; case 't' : fileType = atoi(optarg); if (fileType != NGINX_ACCESS_LOG && fileType != OTHER_FILE_TYPE) { std::cerr <<"Fatal: Illegal file type"<< fileType << std::endl; exit(-1); } break; case 'r' : regularExpression.assign(optarg); break; case 'o' : replacementUri.assign(optarg); break; case 'h' : _usage(); exit(0); } // end switch } // end while // parase Domain name if (urlPrefix.empty()) { std::cerr <<"Fatal: Illegal url prefix" << std::endl; exit(-1); } size_t domainStartPos = std::string::npos; size_t domainEndPos = std::string::npos; size_t colonsPos = std::string::npos; size_t prefixPos = std::string::npos; if (std::string::npos == urlPrefix.find("http://")) { urlPrefix = "http://" + urlPrefix; } domainStartPos = 7; prefixPos = urlPrefix.find("/", domainStartPos); if (std::string::npos != prefixPos) { urlPrefix = urlPrefix.substr(0, prefixPos); } colonsPos = urlPrefix.find(":", domainStartPos); // case for http://www.bullsoft.org if (std::string::npos == colonsPos) { domainEndPos = urlPrefix.length() - 1; // case for http://www.bullsoft.org:8080 } else { domainEndPos = colonsPos - 1; } domainName.assign(urlPrefix.substr(domainStartPos, domainEndPos - domainStartPos + 1)); if (domainName.empty()) { std::cerr <<"Fatal: Illegal url prefix" << std::endl; exit(-1); } // parse Port // case for :8080 if (std::string::npos != colonsPos) { size_t portStartPos = colonsPos + 1; size_t portEndPos = urlPrefix.length() - 1; portString = urlPrefix.substr(portStartPos, portEndPos - portStartPos + 1); port = atoi(portString.c_str()); if (port <= 0) { std::cerr <<"Error: Illegal Port:"<< portString << std::endl; port = 80; portString = "80"; } } // get IP adin according to domain name struct hostent *hp; unsigned long inaddr; inaddr = inet_addr(domainName.c_str()); // case for http://127.0.0.1:8080 if (inaddr != INADDR_NONE) { ip = domainName; memcpy(&ad.sin_addr, &inaddr, sizeof(inaddr)); } else { // case for http://www.bullsoft.org hp = gethostbyname(domainName.c_str()); if (hp == NULL) { std::cerr <<"Fatal: Invalid domain name:"<< domainName << std::endl; exit(-1); } memcpy(&ad.sin_addr, hp->h_addr, hp->h_length); } ad.sin_family = AF_INET; ad.sin_port = htons((unsigned short)port); // compile regular expression if (!regularExpression.empty()) { int iret = 0; iret = regcomp(®, regularExpression.c_str(), REG_EXTENDED|REG_NEWLINE); if (iret != 0) { std::cerr <<"Fatal: Invalid regular expression :"<< regularExpression << std::endl; exit(-1); } } }
/* * opt_args() : set options via commandline args and getopt_long */ static void _opt_args(int argc, char **argv) { char **rest = NULL; int i, opt_char, option_index; static struct option long_options[] = { {"account", required_argument, 0, 'A'}, {"batch", no_argument, 0, 'b'}, {"ctld", no_argument, 0, OPT_LONG_CTLD}, {"full", no_argument, 0, 'f'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"interactive", no_argument, 0, 'i'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"jobname", required_argument, 0, 'n'}, {"name", required_argument, 0, 'n'}, {"nodelist", required_argument, 0, 'w'}, {"partition", required_argument, 0, 'p'}, {"qos", required_argument, 0, 'q'}, {"quiet", no_argument, 0, 'Q'}, {"reservation", required_argument, 0, 'R'}, {"signal", required_argument, 0, 's'}, {"state", required_argument, 0, 't'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"wckey", required_argument, 0, OPT_LONG_WCKEY}, {NULL, 0, 0, 0} }; while ((opt_char = getopt_long(argc, argv, "A:bfiM:n:p:Qq:R:s:t:u:vVw:", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"scancel --help\" for more " "information\n"); exit(1); break; case (int)'A': opt.account = xstrtolower(xstrdup(optarg)); break; case (int)'b': opt.batch = true; break; case OPT_LONG_CTLD: opt.ctld = true; break; case (int)'f': opt.full = true; break; case (int)'i': opt.interactive = true; break; case (int)'M': opt.ctld = true; FREE_NULL_LIST(opt.clusters); opt.clusters = slurmdb_get_info_cluster(optarg); if (!opt.clusters) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(opt.clusters); break; case (int)'n': opt.job_name = xstrdup(optarg); break; case (int)'p': opt.partition = xstrdup(optarg); break; case (int)'Q': opt.verbose = -1; break; case (int)'q': opt.qos = xstrtolower(xstrdup(optarg)); break; case (int)'R': opt.reservation = xstrdup(optarg); break; case (int)'s': opt.signal = _xlate_signal_name(optarg); break; case (int)'t': opt.state = _xlate_state_name(optarg, false); break; case (int)'u': opt.user_name = xstrdup(optarg); break; case (int)'v': opt.verbose++; break; case (int)'V': print_slurm_version (); exit(0); case (int)'w': opt.nodelist = xstrdup(optarg); break; case OPT_LONG_WCKEY: opt.wckey = xstrdup(optarg); break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } if (optind < argc) rest = argv + optind; if (rest && (rest[0][0] >= '0') && (rest[0][0] <= '9')) { opt.job_list = _xlate_job_step_ids(rest); } else if (rest) { for (i = optind; i < argc; i++) { if (opt.job_name) xstrcat(opt.job_name, ","); xstrcat(opt.job_name, argv[i]); } } if (!_opt_verify()) exit(1); }
/* * _process_command - process the user's command * IN argc - count of arguments * IN argv - the arguments * RET 0 or errno (only for errors fatal to sreport) */ static int _process_command (int argc, char **argv) { int command_len = 0; if (argc < 1) { exit_code = 1; if (quiet_flag == -1) fprintf(stderr, "no input"); return 0; } command_len = strlen(argv[0]); if ((xstrncasecmp(argv[0], "cluster", MAX(command_len, 2)) == 0)) { if (argc < 2) { exit_code = 1; if (quiet_flag != 1) fprintf(stderr, "too few arguments for keyword:%s\n", argv[0]); } else _cluster_rep((argc - 1), &argv[1]); } else if (xstrncasecmp(argv[0], "help", MAX(command_len, 2)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } _usage (); } else if ((xstrncasecmp(argv[0], "job", MAX(command_len, 1)) == 0)) { if (argc < 2) { exit_code = 1; if (quiet_flag != 1) fprintf(stderr, "too few arguments for keyword:%s\n", argv[0]); } else _job_rep((argc - 1), &argv[1]); } else if (xstrncasecmp(argv[0], "quiet", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } quiet_flag = 1; } else if ((xstrncasecmp(argv[0], "exit", MAX(command_len, 1)) == 0) || (xstrncasecmp(argv[0], "\\q", MAX(command_len, 2)) == 0) || (xstrncasecmp(argv[0], "quit", MAX(command_len, 4)) == 0)) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } exit_flag = 1; } else if (xstrncasecmp(argv[0], "local", MAX(command_len, 3)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } local_flag = true; } else if (xstrncasecmp(argv[0], "nonparsable", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } print_fields_parsable_print = 0; } else if (xstrncasecmp(argv[0], "parsable", MAX(command_len, 8)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; } else if (xstrncasecmp(argv[0], "parsable2", MAX(command_len, 9)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; } else if ((xstrncasecmp(argv[0], "reservation", MAX(command_len, 2)) == 0) || (xstrncasecmp(argv[0], "resv", MAX(command_len, 2)) == 0)) { if (argc < 2) { exit_code = 1; if (quiet_flag != 1) fprintf(stderr, "too few arguments for keyword:%s\n", argv[0]); } else _resv_rep((argc - 1), &argv[1]); } else if (xstrncasecmp(argv[0], "sort", MAX(command_len, 1)) == 0) { if (argc < 2) { exit_code = 1; fprintf (stderr, "too few arguments for keyword:%s\n", argv[0]); } else _set_sort(argv[1]); } else if (xstrncasecmp(argv[0], "time", MAX(command_len, 1)) == 0) { if (argc < 2) { exit_code = 1; fprintf (stderr, "too few arguments for keyword:%s\n", argv[0]); } else _set_time_format(argv[1]); } else if (xstrncasecmp(argv[0], "verbose", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for %s keyword\n", argv[0]); } quiet_flag = -1; } else if (xstrncasecmp(argv[0], "version", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for %s keyword\n", argv[0]); } _print_version(); } else if ((xstrncasecmp(argv[0], "user", MAX(command_len, 1)) == 0)) { if (argc < 2) { exit_code = 1; if (quiet_flag != 1) fprintf(stderr, "too few arguments for keyword:%s\n", argv[0]); } else _user_rep((argc - 1), &argv[1]); } else { exit_code = 1; fprintf (stderr, "invalid keyword: %s\n", argv[0]); } return 0; }
/* * parse_command_line, fill in params data structure with data */ extern void parse_command_line(int argc, char *argv[]) { int opt_char; int option_index; int tmp = 0; static struct option long_options[] = { {"commandline", no_argument, 0, 'c'}, {"command", required_argument, 0, 'C'}, {"display", required_argument, 0, 'D'}, {"noheader", no_argument, 0, 'h'}, {"iterate", required_argument, 0, 'i'}, {"ionodes", required_argument, 0, 'I'}, {"cluster", required_argument, 0, 'M'}, {"clusters",required_argument, 0, 'M'}, {"nodes", required_argument, 0, 'n'}, {"quiet", no_argument, 0, 'Q'}, {"resolve", required_argument, 0, 'R'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"help", no_argument, 0, OPT_LONG_HELP}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"show_hidden", no_argument, 0, 'H'}, {NULL, 0, 0, 0} }; memset(¶ms, 0, sizeof(params)); while ((opt_char = getopt_long(argc, argv, "cC:D:hi:I:Hn:M:QR:vV", long_options, &option_index)) != -1) { switch (opt_char) { case '?': fprintf(stderr, "Try \"smap --help\" for more information\n"); exit(1); break; case 'c': params.commandline = TRUE; break; case 'C': params.command = xstrdup(optarg); break; case 'D': if (!strcmp(optarg, "j")) tmp = JOBS; else if (!strcmp(optarg, "s")) tmp = SLURMPART; else if (!strcmp(optarg, "b")) tmp = BGPART; else if (!strcmp(optarg, "c")) tmp = COMMANDS; else if (!strcmp(optarg, "r")) tmp = RESERVATIONS; params.display = tmp; break; case 'h': params.no_header = true; break; case 'H': params.all_flag = true; break; case 'i': params.iterate = atoi(optarg); if (params.iterate <= 0) { error("Error: --iterate=%s", optarg); exit(1); } break; case 'I': /* * confirm valid ionodelist entry (The 128 is * a large number here to avoid having to do a * lot more querying to figure out the correct * pset size. This number should be large enough. */ params.io_bit = bit_alloc(128); if(bit_unfmt(params.io_bit, optarg) == -1) { error("'%s' invalid entry for --ionodes", optarg); exit(1); } break; case 'M': if(params.clusters) list_destroy(params.clusters); if(!(params.clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' can't be reached now, " "or it is an invalid entry for " "--cluster. Use 'sacctmgr --list " "cluster' to see available clusters.", optarg); exit(1); } working_cluster_rec = list_peek(params.clusters); break; case 'n': /* * confirm valid nodelist entry */ params.hl = hostlist_create(optarg); if (!params.hl) { error("'%s' invalid entry for --nodes", optarg); exit(1); } break; case 'Q': quiet_flag = 1; break; case 'R': params.commandline = TRUE; params.resolve = xstrdup(optarg); break; case 'v': params.verbose++; break; case 'V': print_slurm_version(); exit(0); case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } params.cluster_dims = slurmdb_setup_cluster_dims(); if (params.cluster_dims > 4) fatal("smap is unable to support more than four dimensions"); params.cluster_base = hostlist_get_base(params.cluster_dims); params.cluster_flags = slurmdb_setup_cluster_flags(); }
int main (int argc, char **argv) { int error_code = SLURM_SUCCESS, i, opt_char, input_field_count; char **input_fields; log_options_t opts = LOG_OPTS_STDERR_ONLY ; char *temp = NULL; int option_index; uint16_t persist_conn_flags = 0; static struct option long_options[] = { {"all_clusters", 0, 0, 'a'}, {"cluster", 1, 0, 'M'}, {"federation", no_argument, 0, OPT_LONG_FEDR}, {"help", 0, 0, 'h'}, {"immediate",0, 0, 'i'}, {"local", no_argument, 0, OPT_LONG_LOCAL}, {"noheader", 0, 0, 'n'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"quiet", 0, 0, 'Q'}, {"sort", 0, 0, 's'}, {"tres", 1, 0, 'T'}, {"usage", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {NULL, 0, 0, 0} }; command_name = argv[0]; exit_code = 0; exit_flag = 0; federation_flag = false; input_field_count = 0; local_flag = false; quiet_flag = 0; slurm_conf_init(NULL); log_init("sreport", opts, SYSLOG_FACILITY_DAEMON, NULL); /* Check to see if we are running a supported accounting plugin */ temp = slurm_get_accounting_storage_type(); if (xstrcasecmp(temp, "accounting_storage/slurmdbd") && xstrcasecmp(temp, "accounting_storage/mysql")) { fprintf (stderr, "You are not running a supported " "accounting_storage plugin\n(%s).\n" "Only 'accounting_storage/slurmdbd' " "and 'accounting_storage/mysql' are supported.\n", temp); xfree(temp); exit(1); } xfree(temp); if (slurmctld_conf.fed_params && strstr(slurmctld_conf.fed_params, "fed_display")) federation_flag = true; if (getenv("SREPORT_CLUSTER")) { cluster_flag = xstrdup(optarg); local_flag = true; } if (getenv("SREPORT_FEDERATION")) federation_flag = true; if (getenv("SREPORT_LOCAL")) local_flag = true; temp = getenv("SREPORT_TRES"); if (temp) tres_str = xstrdup(temp); while ((opt_char = getopt_long(argc, argv, "aM:hnpPQs:t:T:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sreport --help\" " "for more information\n"); exit(1); break; case (int)'h': _usage (); exit(exit_code); break; case (int)'a': all_clusters_flag = 1; break; case OPT_LONG_FEDR: federation_flag = true; break; case OPT_LONG_LOCAL: local_flag = true; break; case (int) 'M': cluster_flag = xstrdup(optarg); federation_flag = true; break; case (int)'n': print_fields_have_header = 0; break; case (int)'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case (int)'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case (int)'Q': quiet_flag = 1; break; case (int)'s': _set_sort(optarg); break; case (int)'t': _set_time_format(optarg); break; case (int)'T': xfree(tres_str); tres_str = xstrdup(optarg); break; case (int)'v': quiet_flag = -1; break; case (int)'V': _print_version(); exit(exit_code); break; default: fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(1); } } i = 0; if (all_clusters_flag) i++; if (cluster_flag) i++; if (local_flag) i++; if (i > 1) { fprintf(stderr, "Only one cluster option can be used (--all_clusters OR --cluster OR --local)\n"), exit(1); } if (argc > MAX_INPUT_FIELDS) /* bogus input, but continue anyway */ input_words = argc; else input_words = 128; input_fields = (char **) xmalloc (sizeof (char *) * input_words); if (optind < argc) { for (i = optind; i < argc; i++) { input_fields[input_field_count++] = argv[i]; } } if (federation_flag && !all_clusters_flag && !cluster_flag && !local_flag) cluster_flag = _build_cluster_string(); db_conn = slurmdb_connection_get2(&persist_conn_flags); if (errno) { fatal("Problem connecting to the database: %m"); exit(1); } if (persist_conn_flags & PERSIST_FLAG_P_USER_CASE) user_case_norm = false; _build_tres_list(); if (input_field_count) exit_flag = 1; else error_code = _get_command (&input_field_count, input_fields); while (error_code == SLURM_SUCCESS) { error_code = _process_command (input_field_count, input_fields); if (error_code || exit_flag) break; error_code = _get_command (&input_field_count, input_fields); } if (exit_flag == 2) putchar('\n'); /* Free the cluster grabbed from the -M option */ xfree(cluster_flag); slurmdb_connection_close(&db_conn); slurm_acct_storage_fini(); exit(exit_code); }
int main (int argc, char *argv[]) { int opt_char; log_options_t opts = LOG_OPTS_STDERR_ONLY; shares_request_msg_t req_msg; char *temp = NULL; int option_index; bool all_users = 0; static struct option long_options[] = { {"accounts", 1, 0, 'A'}, {"all", 0, 0, 'a'}, {"helpformat",0,0, 'e'}, {"long", 0, 0, 'l'}, {"partition",0, 0, 'm'}, {"cluster", 1, 0, 'M'}, {"clusters", 1, 0, 'M'}, {"noheader", 0, 0, 'n'}, {"format", 1, 0, 'o'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"users", 1, 0, 'u'}, {"Users", 0, 0, 'U'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"help", 0, 0, OPT_LONG_HELP}, {"usage", 0, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; exit_code = 0; long_flag = 0; quiet_flag = 0; verbosity = 0; memset(&req_msg, 0, sizeof(shares_request_msg_t)); slurm_conf_init(NULL); log_init("sshare", opts, SYSLOG_FACILITY_DAEMON, NULL); while((opt_char = getopt_long(argc, argv, "aA:ehlM:no:pPqUu:t:vVm", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sshare --help\" " "for more information\n"); exit(1); break; case 'a': all_users = 1; break; case 'A': if (!req_msg.acct_list) req_msg.acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(req_msg.acct_list, optarg); break; case 'e': _help_format_msg(); exit(0); break; case 'h': print_fields_have_header = 0; break; exit(exit_code); break; case 'l': long_flag = 1; break; case 'M': FREE_NULL_LIST(clusters); if (!(clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(clusters); break; case 'm': options |= PRINT_PARTITIONS; break; case 'n': print_fields_have_header = 0; break; case 'o': xstrfmtcat(opt_field_list, "%s,", optarg); break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'u': if (!strcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); _addto_name_char_list(req_msg.user_list, optarg, 0); break; case 'U': options |= PRINT_USERS_ONLY; break; case 'v': quiet_flag = -1; verbosity++; break; case 'V': _print_version(); exit(exit_code); break; case OPT_LONG_HELP: case OPT_LONG_USAGE: _usage(); exit(0); default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } if (all_users) { if (req_msg.user_list && list_count(req_msg.user_list)) { FREE_NULL_LIST(req_msg.user_list); } if (verbosity) fprintf(stderr, "Users requested:\n\t: all\n"); } else if (verbosity && req_msg.user_list && list_count(req_msg.user_list)) { fprintf(stderr, "Users requested:\n"); ListIterator itr = list_iterator_create(req_msg.user_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else if (!req_msg.user_list || !list_count(req_msg.user_list)) { struct passwd *pwd = getpwuid(getuid()); if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); temp = xstrdup(pwd->pw_name); list_append(req_msg.user_list, temp); if (verbosity) { fprintf(stderr, "Users requested:\n"); fprintf(stderr, "\t: %s\n", temp); } } if (req_msg.acct_list && list_count(req_msg.acct_list)) { if (verbosity) { fprintf(stderr, "Accounts requested:\n"); ListIterator itr = list_iterator_create(req_msg.acct_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } } else { if (req_msg.acct_list && list_count(req_msg.acct_list)) { FREE_NULL_LIST(req_msg.acct_list); } if (verbosity) fprintf(stderr, "Accounts requested:\n\t: all\n"); } if (clusters) exit_code = _multi_cluster(&req_msg); else exit_code = _single_cluster(&req_msg); exit(exit_code); }
int main (int argc, char** argv) { // This client connection is used solely to create and delete subscriptions. CIMClient workClient; try { workClient.connectLocal(); String processIdFile = TRAP_DIR; processIdFile.append("/procIdFile"); String logFile = TRAP_DIR; logFile.append("/trapLogFile"); if (argc <= 1 || argc > 4) { cerr << "Invalid argument count: " << argc << endl; _usage(); return 1; } else if (strcmp(argv[1], "setup") == 0) { if (argc < 3) { cerr << "Missing query language" << endl; _usage(); return -1; } if ((strcmp(argv[2], "WQL") != 0) && (strcmp(argv[2], "DMTF:CQL") != 0)) { cerr << "Invalid query language: '" << argv[2] << "'" << endl; _usage(); return -1; } _setup(workClient, argv[2]); cout << "+++++ setup completed successfully" << endl; return 0; } else if (String::equalNoCase(argv[1], "run")) { if (argc < 3) { cerr << "Invalid indicationSendCount." << endl; _usage (); return -1; } Uint32 indicationSendCount = atoi(argv[2]); Uint32 runClientThreadCount = 1; if (argc == 4) { runClientThreadCount = atoi(argv[3]); } int rc = _beginTest(workClient, indicationSendCount, runClientThreadCount, processIdFile, logFile); return rc; } else if (String::equalNoCase(argv[1], "cleanup")) { if (argc > 2) { cerr << "Invalid argument count." << endl; _usage (); return -1; } _cleanup (workClient); cout << "+++++ cleanup completed successfully" << endl; return 0; } else if (String::equalNoCase(argv[1], "removelog")) { if (argc > 2) { cerr << "Invalid argument count." << endl; _usage (); return -1; } _removeTrapLogFile(logFile); cout << "+++++ removelog completed successfully" << endl; return 0; } else { cerr << "Invalid option: " << argv[1] << endl; _usage (); return -1; } } catch (Exception & e) { cerr << "Error: " << e.getMessage() << endl; } return -1; }
int main (int argc, char *argv[]) { int error_code = SLURM_SUCCESS, opt_char; log_options_t opts = LOG_OPTS_STDERR_ONLY; shares_request_msg_t req_msg; shares_response_msg_t *resp_msg = NULL; char *temp = NULL; int option_index; bool all_users = 0; static struct option long_options[] = { {"accounts", 1, 0, 'A'}, {"all", 0, 0, 'a'}, {"long", 0, 0, 'l'}, {"cluster", 1, 0, 'M'}, {"clusters", 1, 0, 'M'}, {"noheader", 0, 0, 'h'}, {"parsable", 0, 0, 'p'}, {"parsable2",0, 0, 'P'}, {"users", 1, 0, 'u'}, {"verbose", 0, 0, 'v'}, {"version", 0, 0, 'V'}, {"help", 0, 0, OPT_LONG_HELP}, {"usage", 0, 0, OPT_LONG_USAGE}, {NULL, 0, 0, 0} }; exit_code = 0; long_flag = 0; quiet_flag = 0; verbosity = 0; memset(&req_msg, 0, sizeof(shares_request_msg_t)); log_init("sshare", opts, SYSLOG_FACILITY_DAEMON, NULL); while((opt_char = getopt_long(argc, argv, "aA:hlM:npPqu:t:vV", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"sshare --help\" " "for more information\n"); exit(1); break; case 'a': all_users = 1; break; case 'A': if (!req_msg.acct_list) req_msg.acct_list = list_create(slurm_destroy_char); slurm_addto_char_list(req_msg.acct_list, optarg); break; case 'h': print_fields_have_header = 0; break; exit(exit_code); break; case 'l': long_flag = 1; break; case 'M': if (clusters) list_destroy(clusters); if (!(clusters = slurmdb_get_info_cluster(optarg))) { print_db_notok(optarg, 0); exit(1); } working_cluster_rec = list_peek(clusters); break; case 'n': print_fields_have_header = 0; break; case 'p': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_ENDING; break; case 'P': print_fields_parsable_print = PRINT_FIELDS_PARSABLE_NO_ENDING; break; case 'u': if (!strcmp(optarg, "-1")) { all_users = 1; break; } all_users = 0; if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); _addto_name_char_list(req_msg.user_list, optarg, 0); break; case 'v': quiet_flag = -1; verbosity++; break; case 'V': _print_version(); exit(exit_code); break; case OPT_LONG_HELP: case OPT_LONG_USAGE: _usage(); exit(0); default: exit_code = 1; fprintf(stderr, "getopt error, returned %c\n", opt_char); exit(exit_code); } } if (verbosity) { opts.stderr_level += verbosity; opts.prefix_level = 1; log_alter(opts, 0, NULL); } if (all_users) { if (req_msg.user_list && list_count(req_msg.user_list)) { list_destroy(req_msg.user_list); req_msg.user_list = NULL; } if (verbosity) fprintf(stderr, "Users requested:\n\t: all\n"); } else if (verbosity && req_msg.user_list && list_count(req_msg.user_list)) { fprintf(stderr, "Users requested:\n"); ListIterator itr = list_iterator_create(req_msg.user_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else if (!req_msg.user_list || !list_count(req_msg.user_list)) { struct passwd *pwd = getpwuid(getuid()); if (!req_msg.user_list) req_msg.user_list = list_create(slurm_destroy_char); temp = xstrdup(pwd->pw_name); list_append(req_msg.user_list, temp); if (verbosity) { fprintf(stderr, "Users requested:\n"); fprintf(stderr, "\t: %s\n", temp); } } if (req_msg.acct_list && list_count(req_msg.acct_list)) { fprintf(stderr, "Accounts requested:\n"); ListIterator itr = list_iterator_create(req_msg.acct_list); while((temp = list_next(itr))) fprintf(stderr, "\t: %s\n", temp); list_iterator_destroy(itr); } else { if (req_msg.acct_list && list_count(req_msg.acct_list)) { list_destroy(req_msg.acct_list); req_msg.acct_list = NULL; } if (verbosity) fprintf(stderr, "Accounts requested:\n\t: all\n"); } error_code = _get_info(&req_msg, &resp_msg); if (req_msg.acct_list) list_destroy(req_msg.acct_list); if (req_msg.user_list) list_destroy(req_msg.user_list); if (error_code) { slurm_perror("Couldn't get shares from controller"); exit(error_code); } /* do stuff with it */ process(resp_msg); slurm_free_shares_response_msg(resp_msg); exit(exit_code); }
int main(int argc, char *argv[]) { CLPI_CL *cl; int opt; int opt_clip_info = 0, opt_seq_info = 0, opt_prog_info = 0; int opt_cpi_info = 0, opt_extent_start = 0; int ii; do { opt = getopt(argc, argv, OPTS); switch (opt) { case -1: break; case 'v': verbose = 1; break; case 's': opt_seq_info = 1; break; case 'i': opt_cpi_info = 1; break; case 'c': opt_clip_info = 1; break; case 'p': opt_prog_info = 1; break; case 'e': opt_extent_start = 1; break; default: _usage(argv[0]); break; } } while (opt != -1); if (optind >= argc) { _usage(argv[0]); } for (ii = optind; ii < argc; ii++) { cl = bd_read_clpi(argv[ii]); if (cl == NULL) { fprintf(stderr, "Parsing %s failed\n", argv[ii]); continue; } if (opt_clip_info) { // Show clip info _show_clip_info(cl, 1); } if (opt_seq_info) { // Show sequence info _show_seq_info(&cl->sequence, 1); } if (opt_prog_info) { // Show program info _show_prog_info(&cl->program, 1); } if (opt_cpi_info) { // Show cpi _show_cpi_info(&cl->cpi, 1); } if (opt_prog_info) { if (cl->program_ss.num_prog) { printf("\n"); indent_printf(1, "Extension: Program Info SS"); _show_prog_info(&cl->program_ss, 1); } } if (opt_cpi_info) { if (cl->program_ss.num_prog) { printf("\n"); indent_printf(1, "Extension: CPI SS"); _show_cpi_info(&cl->cpi_ss, 1); } } if (opt_extent_start) { // Show extent start point if (cl->extent_start.num_point > 0) { _show_extent_start(&cl->extent_start, 1); } } bd_free_clpi(cl); } return 0; }
int main(int argc, char **argv) { tree_t *tree = NULL; treenode_t *node = NULL; person_t *person = NULL; if (_parse_cmd(argc, argv)) { _usage(); return -1; } if (_init()) return -1; tree = tree_alloc(NULL, person_find, person_print, person_free, 0x1234); person = malloc(sizeof(person_t)); if (!person) goto out_free; strncpy(person->name, "fz", NAMELEN - 1); person->age = 33; tree_add_end(tree, NULL, person); node = tree_find(tree, person); if (node) { printf("find (%s:%d) in tree\n", person->name, person->age); person = malloc(sizeof(person_t)); if (!person) goto out_free; strncpy(person->name, "forrest", NAMELEN -1); person->age = 11; tree_add_first(tree, node, person); person = malloc(sizeof(person_t)); if (!person) goto out_free; strncpy(person->name, "bug", NAMELEN -1); person->age = 13; tree_add_end(tree, node, person); } tree_print(tree); person = malloc(sizeof(person_t)); if (!person) goto out_free; strncpy(person->name, "fz", NAMELEN -1); person->age = 33; node = tree_find(tree, person); if (node) { printf("find (%s:%d) in tree\n", person->name, person->age); } tree_del(tree, person); free(person); tree_print(tree); out_free: tree_free(tree); _release(); return 0; }
int main(int argc, char **argv) { char errbuf[PCAP_ERRBUF_SIZE]; pcap_t *p = NULL; char *fn = NULL, *out = "out.pcap", *filt = "ip"; int c = 0; int f_wait = 0; while((c = getopt(argc, argv, "no:sW")) != -1) { switch(c) { case 'n': No_Write = 1; break; case 'o': out = optarg; break; case 's': Full_Snap_Only = 0; break; case 'W': f_wait = 1; break; case 'h': default: _usage(); exit(1); } } argc -= optind; argv += optind; if(argc < 1) { _usage(); exit(1); } fn = argv[0]; if(argc > 1) filt = copy_argv(&argv[1]); if((p = pcap_open_offline(fn, errbuf))) { if(No_Write || (D = pcap_dump_open(p, out))) { pfilter(p, "%s", filt); pcap_loop(p, -1, _arrival, (u_char*)p); } else { fmt_eprint("can't open output \"%s\"", out); exit(1); } } else { fmt_eprint("can't open file: %s\n", errbuf); exit(1); } if(D) { pcap_dump_close(D); } fmt_print("%a packets read, %a written (%.1f%%), or %.1f%% of %La total bytes\n", Read, Written, ((double)Written/(double)Read)*100, ((double)WrittenBytes/(double)ReadBytes)*100, ReadBytes); while(f_wait) /* debug */ ; exit(0); }
/* * opt_args() : set options via commandline args and getopt_long */ static void _opt_args(int argc, char **argv) { int opt_char; int option_index; static struct option long_options[] = { {"account", required_argument, 0, 'A'}, {"batch", no_argument, 0, 'b'}, {"ctld", no_argument, 0, OPT_LONG_CTLD}, {"help", no_argument, 0, OPT_LONG_HELP}, {"interactive", no_argument, 0, 'i'}, {"cluster", required_argument, 0, 'M'}, {"clusters", required_argument, 0, 'M'}, {"name", required_argument, 0, 'n'}, {"nodelist", required_argument, 0, 'w'}, {"partition", required_argument, 0, 'p'}, {"qos", required_argument, 0, 'q'}, {"quiet", no_argument, 0, 'Q'}, {"reservation", required_argument, 0, 'R'}, {"signal", required_argument, 0, 's'}, {"state", required_argument, 0, 't'}, {"usage", no_argument, 0, OPT_LONG_USAGE}, {"user", required_argument, 0, 'u'}, {"verbose", no_argument, 0, 'v'}, {"version", no_argument, 0, 'V'}, {"wckey", required_argument, 0, OPT_LONG_WCKEY}, {NULL, 0, 0, 0} }; while((opt_char = getopt_long(argc, argv, "A:biM:n:p:Qq:R:s:t:u:vVw:", long_options, &option_index)) != -1) { switch (opt_char) { case (int)'?': fprintf(stderr, "Try \"scancel --help\" for more " "information\n"); exit(1); break; case (int)'A': opt.account = xstrtolower(xstrdup(optarg)); break; case (int)'b': opt.batch = true; break; case OPT_LONG_CTLD: opt.ctld = true; break; case (int)'i': opt.interactive = true; break; case (int)'M': opt.ctld = true; if(opt.clusters) list_destroy(opt.clusters); if(!(opt.clusters = slurmdb_get_info_cluster(optarg))) { error("'%s' invalid entry for --cluster", optarg); exit(1); } working_cluster_rec = list_peek(opt.clusters); break; case (int)'n': opt.job_name = xstrdup(optarg); break; case (int)'p': opt.partition = xstrdup(optarg); break; case (int)'Q': opt.verbose = -1; break; case (int)'q': opt.qos = xstrtolower(xstrdup(optarg)); break; case (int)'R': opt.reservation = xstrdup(optarg); break; case (int)'s': opt.signal = _xlate_signal_name(optarg); break; case (int)'t': opt.state = _xlate_state_name(optarg, false); break; case (int)'u': opt.user_name = xstrdup(optarg); break; case (int)'v': opt.verbose++; break; case (int)'V': print_slurm_version (); exit(0); case (int)'w': opt.nodelist = xstrdup(optarg); break; case OPT_LONG_WCKEY: opt.wckey = xstrdup(optarg); break; case OPT_LONG_HELP: _help(); exit(0); case OPT_LONG_USAGE: _usage(); exit(0); } } if (optind < argc) { char **rest = argv + optind; _xlate_job_step_ids(rest); } if (!_opt_verify()) exit(1); }
int main(int argc, char *argv[]) { MPLS_PL *pl; int opt; int ii, pl_ii; MPLS_PL *pl_list[1000]; struct stat st; char *path = NULL; DIR *dir = NULL; do { opt = getopt(argc, argv, OPTS); switch (opt) { case -1: break; case 'v': verbose = 1; break; case 'l': clip_list = 1; break; case 'i': playlist_info = 1; break; case 'c': chapter_marks = 1; break; case 'p': sub_paths = 1; break; case 'd': dups = 1; break; case 'r': repeats = atoi(optarg); break; case 'f': repeats = 2; dups = 1; seconds = 900; break; case 's': seconds = atoi(optarg); break; default: _usage(argv[0]); break; } } while (opt != -1); if (optind >= argc) { _usage(argv[0]); } for (pl_ii = 0, ii = optind; pl_ii < 1000 && ii < argc; ii++) { if (stat(argv[ii], &st)) { continue; } dir = NULL; if (S_ISDIR(st.st_mode)) { char *main_title = NULL; printf("Directory: %s:\n", argv[ii]); path = str_printf("%s/BDMV/PLAYLIST", argv[ii]); if (path == NULL) { fprintf(stderr, "Failed to find playlist path: %s\n", argv[ii]); continue; } dir = opendir(path); if (dir == NULL) { fprintf(stderr, "Failed to open dir: %s\n", path); free(path); continue; } main_title = nav_find_main_title(argv[ii]); if (main_title != NULL) { printf("Main Title: %s\n", main_title); free(main_title); } else { fprintf(stderr, "Main title search failed\n"); } } if (dir != NULL) { char **dirlist = calloc(10001, sizeof(char*)); struct dirent *ent; int jj = 0; for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) { if (ent->d_name != NULL) { dirlist[jj] = (char*)malloc(strlen(ent->d_name) + 1); strcpy(dirlist[jj], ent->d_name); jj++; } } qsort(dirlist, jj, sizeof(char*), _qsort_str_cmp); for (jj = 0; dirlist[jj] != NULL; jj++) { char *name = NULL; name = str_printf("%s/%s", path, dirlist[jj]); free(dirlist[jj]); if (stat(name, &st)) { free(name); continue; } if (!S_ISREG(st.st_mode)) { free(name); continue; } pl = _process_file(name, pl_list, pl_ii); free(name); if (pl != NULL) { pl_list[pl_ii++] = pl; } } while (ent != NULL); free(dirlist); free(path); } else { pl = _process_file(argv[ii], pl_list, pl_ii); if (pl != NULL) { pl_list[pl_ii++] = pl; } } } // Cleanup for (ii = 0; ii < pl_ii; ii++) { mpls_free(pl_list[ii]); } return 0; }
int main(int argc, char **argv) { int optch, return_value = 0; char *input = NULL, *output = NULL, *inc_paths = NULL; char *font_paths = NULL, *img_paths = NULL; cg_back_t do_back = BACK_NO; cg_paper_t do_paper = A4; yvalue_t do_width, do_height, do_margin_width, do_margin_height; ybool_t set_back = YFALSE, set_paper = YFALSE, set_pdf = YFALSE; ybool_t set_width = YFALSE, set_height = YFALSE, set_margin = YFALSE; ybool_t set_margin_width = YFALSE, set_margin_height = YFALSE; ybool_t do_reverse = YFALSE, set_reverse = YFALSE; ybool_t set_landscape = YFALSE, set_quiet = YFALSE; cg_pdf_version_t pdf_version = PDF_14; char *author = NULL, *title = NULL, *log_file = NULL;; cg_t *carta; /* parse the command line */ while ((optch = getopt(argc, argv, "p:w:h:l:m:x:y:b:v:r:i:o:d:e:t:L:q")) != -1) switch (optch) { case 'p': /* paper type */ set_paper = YTRUE; do_paper = cg_get_paper(optarg); do_width = cg_get_paper_width(do_paper); do_height = cg_get_paper_height(do_paper); break ; case 'w': /* paper width */ set_width = YTRUE; do_width = yvalue_read(optarg, YUNIT_MM); break ; case 'h': /* paper height */ set_height = YTRUE; do_height = yvalue_read(optarg, YUNIT_MM); break ; case 'l': /* landscape mode */ if (!strcasecmp(optarg, "yes") || !strcasecmp(optarg, "true")) set_landscape = YTRUE; break ; case 'm': /* margin size */ set_margin = YTRUE; do_margin_width = yvalue_read(optarg, YUNIT_MM); do_margin_height = do_margin_width; break ; case 'x': /* margin width */ set_margin_width = YTRUE; do_margin_width = yvalue_read(optarg, YUNIT_MM); break ; case 'y': /* margin height */ set_margin_height = YTRUE; do_margin_height = yvalue_read(optarg, YUNIT_MM); break ; case 'b': /* cards' back configuration */ set_back = YTRUE; if (!strcasecmp(optarg, "width")) do_back = BACK_WIDTH; else if (!strcasecmp(optarg, "height")) do_back = BACK_HEIGHT; else if (!strcasecmp(optarg, "no")) do_back = BACK_NO; else set_back = YFALSE; break ; case 'v': /* PDF version */ set_pdf = YTRUE; if (!strcmp(optarg, "1.3")) pdf_version = PDF_13; else if (!strcmp(optarg, "1.4")) pdf_version = PDF_14; else if (!strcmp(optarg, "1.5")) pdf_version = PDF_15; else set_pdf = YFALSE; break ; case 'r': /* inverse page order */ if (!strcasecmp(optarg, "yes") || !strcasecmp(optarg, "true")) { set_reverse = YTRUE; do_reverse = YTRUE; } else if (!strcasecmp(optarg, "no") || !strcasecmp(optarg, "false")) { set_reverse = YTRUE; do_reverse = YFALSE; } break ; case 'd': /* include path directories */ inc_paths = strdup(optarg); break ; case 'f': /* font path directories */ font_paths = strdup(optarg); break ; case 'g': /* image path directories */ img_paths = strdup(optarg); break ; case 'i': /* input file */ input = strdup(optarg); break ; case 'o': /* output file */ output = strdup(optarg); break ; case 'e': /* author */ author = strdup(optarg); break ; case 't': /* title */ title = strdup(optarg); break ; case 'L': /* log file */ log_file = strdup(optarg); break ; case 'q': /* quiet mode */ set_quiet = YTRUE; break ; default: _usage(); exit(1); } if (!input || !output) { _usage(); exit(1); } /* logging init */ if (set_quiet && log_file) YLOG_INIT_FILE(log_file); else if (set_quiet && !log_file) YLOG_INIT_SYSLOG(); else if (!set_quiet && log_file) YLOG_INIT_STDERR_FILE(log_file); else YLOG_INIT_STDERR(); /* read input file */ if (!(carta = cg_init(input, inc_paths, font_paths, img_paths))) { YLOG_ADD(YLOG_ERR, "Unable to read input file '%s'", input); exit(1); } /* update with command line options */ if (set_back) carta->do_back = do_back; if (set_paper || set_width || set_height || set_landscape || set_margin || set_margin_width || set_margin_height) { cg_deck_t *deck; int i; for (i = 0; i < yv_len(carta->decks); ++i) { deck = carta->decks[i]; if (set_paper || set_width) deck->paper_width = do_width; if (set_paper || set_height) deck->paper_height = do_height; if (set_landscape) { yvalue_t tmp_val = deck->paper_width; deck->paper_width = deck->paper_height; deck->paper_height = tmp_val; } if (set_margin || set_margin_width) deck->paper_margin_w = do_margin_width; if (set_margin || set_margin_height) deck->paper_margin_h = do_margin_height; } } if (set_pdf) carta->pdf_version = pdf_version; if (set_reverse) carta->reverse = do_reverse; if (author) { free0(carta->author); carta->author = author; } if (title) { free0(carta->title); carta->title = title; } /* compute cols and rows */ if (cg_compute_cols_rows(carta) == YENOERR) { /* create the PDF file */ if (cg_create_document(output, carta) != YENOERR) return_value = 2; } else return_value = 3; /* free memory */ yv_del(&carta->xml_doms, free_dom, NULL); yv_del(&carta->decks, free_deck, NULL); yv_del(&carta->fonts, free_font, NULL); yv_del(&carta->images, free_image, NULL); yv_del(&carta->masks, free_image, NULL); yv_del(&carta->templates, NULL, NULL); yv_del(&carta->variables, NULL, NULL); yv_del(&carta->inc_paths, free_path, NULL); yv_del(&carta->img_paths, free_path, NULL); yv_del(&carta->text_defines, free_text_define, NULL); if (carta->expr) { yv_del(&carta->expr->vars, free_var, NULL); yv_del(&carta->expr->funcs, free_func, NULL); free0(carta->expr); } free0(carta->author); free0(carta->title); free0(carta->subject); free0(carta->keywords); free0(carta->copyright); free0(carta->version); free0(carta->language); free0(carta->note); free0(carta->master_password); free0(carta->user_password); free0(carta); return (return_value); }
int main(int argc, char **argv) { const char *voice_code, *text, *output_file_name, *mode; int sample_rate_ret, backwards; struct FRAGMENT_INFO fragment; float quit_after; struct FRAGMENT_INFO *fragments; char **texts; int i, n; size_t synthesized_ret; if (argc < 5) { _usage(argv[0]); return DRIVER_FAILURE; } voice_code = argv[1]; text = argv[2]; output_file_name = argv[3]; mode = argv[4]; if (strcmp(mode, "multi") == 0) { if (argc < 7) { _usage(argv[0]); return DRIVER_FAILURE; } quit_after = (float)atof(argv[5]); backwards = atoi(argv[6]); // split text into fragments n = 0; texts = _str_split((char *)text, '|', &n); // create fragments fragments = (struct FRAGMENT_INFO *)calloc(sizeof(fragment), n); for (i = 0; i < n; ++i) { fragments[i].voice_code = voice_code; fragments[i].text = texts[i]; } // synthesize if(_synthesize_multiple( output_file_name, &fragments, n, quit_after, backwards, &sample_rate_ret, &synthesized_ret ) != CEW_SUCCESS) { printf("Error while calling _synthesize_single()\n"); return DRIVER_FAILURE; } printf("Sample rate: %d\n", sample_rate_ret); printf("Synthesized: %lu\n", synthesized_ret); for (i = 0; i < synthesized_ret; ++i) { printf("%d %.3f %.3f\n", i, fragments[i].begin, fragments[i].end); } // deallocate for (i = 0; i < n; ++i) { free((void *)fragments[i].text); } free((void *)fragments); free((void *)texts); fragments = NULL; texts = NULL; } else { fragment.voice_code = voice_code; fragment.text = text; if (_synthesize_single(output_file_name, &sample_rate_ret, &fragment) != CEW_SUCCESS) { printf("Error while calling _synthesize_single()\n"); return DRIVER_FAILURE; } printf("Sample rate: %d\n", sample_rate_ret); printf("Begin: %.3f\n", fragment.begin); printf("End: %.3f\n", fragment.end); } return DRIVER_SUCCESS; }
static void _usage_invalid_opt(int opt, char *const *argv) { fprintf(stderr, "Unrecognized option: -%c\n", (char) opt); _usage(argv); }
/* * _process_command - process the user's command * IN argc - count of arguments * IN argv - the arguments * RET 0 or errno (only for errors fatal to sacctmgr) */ static int _process_command (int argc, char *argv[]) { int command_len = 0; if (argc < 1) { exit_code = 1; if (quiet_flag == -1) fprintf(stderr, "no input"); return 0; } command_len = strlen(argv[0]); if (strncasecmp (argv[0], "associations", MAX(command_len, 3)) == 0) { with_assoc_flag = 1; } else if (strncasecmp (argv[0], "dump", MAX(command_len, 3)) == 0) { sacctmgr_dump_cluster((argc - 1), &argv[1]); } else if (strncasecmp (argv[0], "help", MAX(command_len, 2)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } _usage (); } else if (strncasecmp (argv[0], "load", MAX(command_len, 2)) == 0) { load_sacctmgr_cfg_file((argc - 1), &argv[1]); } else if (strncasecmp (argv[0], "oneliner", MAX(command_len, 1)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } one_liner = 1; } else if (strncasecmp (argv[0], "quiet", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } quiet_flag = 1; } else if ((strncasecmp (argv[0], "exit", MAX(command_len, 4)) == 0) || (strncasecmp (argv[0], "\\q", MAX(command_len, 2)) == 0) || (strncasecmp (argv[0], "quit", MAX(command_len, 4)) == 0)) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for keyword:%s\n", argv[0]); } exit_flag = 1; } else if ((strncasecmp (argv[0], "add", MAX(command_len, 3)) == 0) || (strncasecmp (argv[0], "create", MAX(command_len, 3)) == 0)) { _add_it((argc - 1), &argv[1]); } else if ((strncasecmp (argv[0], "archive", MAX(command_len, 3)) == 0)) { _archive_it((argc - 1), &argv[1]); } else if ((strncasecmp (argv[0], "show", MAX(command_len, 3)) == 0) || (strncasecmp (argv[0], "list", MAX(command_len, 3)) == 0)) { _show_it((argc - 1), &argv[1]); } else if (!strncasecmp (argv[0], "modify", MAX(command_len, 1)) || !strncasecmp (argv[0], "update", MAX(command_len, 1))) { _modify_it((argc - 1), &argv[1]); } else if ((strncasecmp (argv[0], "delete", MAX(command_len, 3)) == 0) || (strncasecmp (argv[0], "remove", MAX(command_len, 3)) == 0)) { _delete_it((argc - 1), &argv[1]); } else if (strncasecmp (argv[0], "verbose", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for %s keyword\n", argv[0]); } quiet_flag = -1; } else if (strncasecmp (argv[0], "readonly", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for %s keyword\n", argv[0]); } readonly_flag = 1; } else if (strncasecmp (argv[0], "reconfigure", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for %s keyword\n", argv[0]); } slurmdb_reconfig(db_conn); } else if (strncasecmp (argv[0], "rollup", MAX(command_len, 2)) == 0) { time_t my_start = 0; time_t my_end = 0; uint16_t archive_data = 0; if (argc > 4) { exit_code = 1; fprintf (stderr, "too many arguments for %s keyword\n", argv[0]); } if (argc > 1) my_start = parse_time(argv[1], 1); if (argc > 2) my_end = parse_time(argv[2], 1); if (argc > 3) archive_data = atoi(argv[3]); if (acct_storage_g_roll_usage(db_conn, my_start, my_end, archive_data) == SLURM_SUCCESS) { if (commit_check("Would you like to commit rollup?")) { acct_storage_g_commit(db_conn, 1); } else { printf(" Rollup Discarded\n"); acct_storage_g_commit(db_conn, 0); } } } else if (strncasecmp (argv[0], "version", MAX(command_len, 4)) == 0) { if (argc > 1) { exit_code = 1; fprintf (stderr, "too many arguments for %s keyword\n", argv[0]); } _print_version(); } else { exit_code = 1; fprintf (stderr, "invalid keyword: %s\n", argv[0]); } return 0; }
int main (int argc, char **argv) { char *endpoint = NULL; void *context, *socket; zmq_pollitem_t pollitems[] = { { NULL, 0, ZMQ_POLLIN, 0 } }; if (argc <= 1) { _usage(argv[0]); return -1; } endpoint = argv[1]; context = zmq_ctx_new(); if (!context) { _ERR("ZeroMQ context: %s\n", zmq_strerror(errno)); return -1; } socket = zmq_socket(context, ZMQ_PULL); if (!socket) { _ERR("ZeroMQ socket: %s\n", zmq_strerror(errno)); zmq_ctx_destroy(context); return -1; } if (zmq_connect(socket, endpoint) == -1) { _ERR("ZeroMQ connect: %s: %s\n", endpoint, zmq_strerror(errno)); zmq_close(socket); zmq_ctx_destroy(context); return -1; } pollitems[0].socket = socket; _signals(); while (!_interrupted) { if (zmq_poll(pollitems, 1, -1) == -1) { break; } if (pollitems[0].revents & ZMQ_POLLIN) { int more; size_t moresz = sizeof(more); while (!_interrupted) { zmq_msg_t zmsg; if (zmq_msg_init(&zmsg) != 0) { break; } if (zmq_recvmsg(socket, &zmsg, 0) == -1) { _ERR("ZeroMQ receive: %s\n", zmq_strerror(errno)); zmq_msg_close(&zmsg); break; } if (zmq_getsockopt(socket, ZMQ_RCVMORE, &more, &moresz) == -1) { _ERR("ZeroMQ option receive: %s\n", zmq_strerror(errno)); more = 0; } fprintf(stdout, "%.*s\n", (int)zmq_msg_size(&zmsg), (char *)zmq_msg_data(&zmsg)); zmq_msg_close(&zmsg); if (!more) { break; } } } } zmq_close(socket); zmq_ctx_destroy(context); return 0; }