static error_t parse_opt(int k, char *optarg, struct argp_state *state) { struct arguments *args = state->input; switch (k) { case 'a': args->adapter = strtoul(optarg, NULL, 0); break; case 'f': args->frontend = strtoul(optarg, NULL, 0); break; case 'd': args->demux = strtoul(optarg, NULL, 0); break; case 'l': args->lnb_name = optarg; break; case 'S': args->sat_number = strtoul(optarg, NULL, 0); break; case 'U': args->freq_bpf = strtoul(optarg, NULL, 0); break; case 'W': args->diseqc_wait = strtoul(optarg, NULL, 0); break; case 'N': args->get_nit++; break; case 'G': args->get_detected++; break; case 'F': args->dont_add_new_freqs++; break; case 'p': args->other_nit++; break; case 'v': verbose++; break; case 'T': args->timeout_multiply = strtoul(optarg, NULL, 0); break; case 'I': args->input_format = parse_format(optarg); break; case 'O': args->output_format = parse_format(optarg); break; case 'o': args->output = optarg; break; case '3': args->force_dvbv3 = 1; break; default: return ARGP_ERR_UNKNOWN; }; return 0; }
void logger::init(actor_system_config& cfg) { CAF_IGNORE_UNUSED(cfg); #if CAF_LOG_LEVEL >= 0 namespace lg = defaults::logger; component_filter = get_or(cfg, "logger.component-filter", lg::component_filter); // Parse the configured log level. auto verbosity = get_or(cfg, "logger.verbosity", lg::verbosity); switch (static_cast<uint64_t>(verbosity)) { case atom_uint("quiet"): case atom_uint("QUIET"): level_ = CAF_LOG_LEVEL_QUIET; break; case atom_uint("error"): case atom_uint("ERROR"): level_ = CAF_LOG_LEVEL_ERROR; break; case atom_uint("warning"): case atom_uint("WARNING"): level_ = CAF_LOG_LEVEL_WARNING; break; case atom_uint("info"): case atom_uint("INFO"): level_ = CAF_LOG_LEVEL_INFO; break; case atom_uint("debug"): case atom_uint("DEBUG"): level_ = CAF_LOG_LEVEL_DEBUG; break; case atom_uint("trace"): case atom_uint("TRACE"): level_ = CAF_LOG_LEVEL_TRACE; break; default: { // nop } } // Parse the format string. file_format_ = parse_format(get_or(cfg, "logger.file-format", lg::file_format)); console_format_ = parse_format(get_or(cfg,"logger.console-format", lg::console_format)); // Set flags. if (get_or(cfg, "logger.inline-output", false)) set(inline_output_flag); auto con_atm = get_or(cfg, "logger.console", lg::console); if (con_atm == atom("UNCOLORED")) set(uncolored_console_flag); else if (con_atm == atom("COLORED")) set(colored_console_flag); #endif }
args_t::args_t( int argc, const char * argv[] ) : output( stdout ), input1( stdin ), input2( NULL ), distance( DEFAULT_DISTANCE ), min_distance( DEFAULT_MIN_DISTANCE ), ambig( DEFAULT_AMBIG ), format ( DEFAULT_FORMAT ), overlap ( DEFAULT_OVERLAP ), do_bootstrap( false ), do_bootstrap_two_files ( false ), do_count( false ), quiet( false ), do_fst( false ), report_self ( false ), counts_in_name ( DEFAULT_COUNTS_IN_NAME ), include_prob( DEFAULT_INCLUDE_PROB ), ambigs_to_resolve(NULL), resolve_fraction(DEFAULT_FRACTION) { // skip arg[0], it's just the program name for (int i = 1; i < argc; ++i ) { const char * arg = argv[i]; if ( arg[0] == '-' && arg[1] == '-' ) { if ( !strcmp( &arg[2], "help" ) ) help(); else if ( !strcmp( &arg[2], "version" ) ) version(); else ERROR( "unknown argument: %s", arg ); } else if ( arg[0] == '-' ) { if ( !strcmp( &arg[1], "h" ) ) help(); else if ( arg[1] == 'v' ) version(); else if ( arg[1] == 'o' ) parse_output( next_arg (i, argc, argv) ); else if ( arg[1] == 't' ) parse_distance ( next_arg (i, argc, argv) ); else if ( arg[1] == 'w' ) parse_min_distance ( next_arg (i, argc, argv) ); else if ( arg[1] == 'l') parse_overlap( next_arg (i, argc, argv) ); else if ( arg[1] == 'f') parse_format( next_arg (i, argc, argv) ); else if ( arg[1] == 'a') parse_ambig( next_arg (i, argc, argv) ); else if ( arg[1] == 's') parse_second_in( next_arg (i, argc, argv) ); else if ( arg[1] == 'd') parse_counts_in_name( next_arg (i, argc, argv) ); else if ( arg[1] == 'u') parse_include_prob( next_arg (i, argc, argv) ); else if ( arg[1] == 'b') parse_bootstrap(); else if ( arg[1] == 'r') parse_bootstrap_two_files (); else if ( arg[1] == 'c') parse_count(); else if ( arg[1] == 'q') parse_quiet(); else if ( arg[1] == 'm') parse_fst(); else if ( arg[1] == '0') parse_report_self(); else if ( arg[1] == 'g') parse_fraction( next_arg (i, argc, argv) ); else ERROR( "unknown argument: %s", arg ); } else if (i == argc-1) { parse_input (arg); } else { ERROR( "unknown argument: %s", arg ); } } }
static boolean_t keysource_prop_parser(char *prop_value, key_format_t *format, key_locator_t *locator, char **uri) { int len; int prop_len; char *s = prop_value; *format = KEY_FORMAT_NONE; *locator = KEY_LOCATOR_NONE; if (!prop_value) return (B_FALSE); prop_len = strlen(prop_value); if (prop_len > ZFS_MAXPROPLEN) return (B_FALSE); for (len = 0; len < prop_len; len++) if (s[len] == ',') break; /* If we are at the end of the key property, there is a problem */ if (len == prop_len) return (B_FALSE); if (!parse_format(format, s, len)) return (B_FALSE); s = s + len + 1; len = prop_len - len - 1; return (parse_locator(locator, s, len, uri)); }
static int do_printf (const char *format, va_list ap, int (*func)(int c, void *data), void *data) { char c; int n, f; int width, precision; n = 0; while ((c = *format++) != '\0') { if (c == '%') { f = parse_format (&format, &width, &precision); if (f & LENGTH_INTMAX) f |= LENGTH_LONGLONG; else if (f & LENGTH_SIZE) f |= LENGTH_LONG; else if (f & LENGTH_PTRDIFF) f |= LENGTH_LONG; if (f == END_STRING) { break; } else if (f & CONVERSION_NONE) { PUTCHAR ('%'); } else if (f & CONVERSION_INT) { long long intval; unsigned long long uintval; if (f & LENGTH_CHAR) intval = (long long)va_arg (ap, int); else if (f & LENGTH_SHORT) intval = (long long)va_arg (ap, int); else if (f & LENGTH_LONGLONG)
/** * Create File using type and encoding from filename or given * format specification. * * @param filename Filename including suffix. The type and encoding * of the file will be taken from the suffix. * An empty filename or "-" means stdin or stdout. * @param format File format as string. See the description of the * parse_format() function for details. */ explicit File(const std::string& filename = "", const std::string& format = "") : Options(), m_filename(filename), m_buffer(nullptr), m_buffer_size(0), m_format_string(format) { // stdin/stdout if (filename == "" || filename == "-") { m_filename = ""; default_settings_for_stdinout(); } // filename is actually a URL std::string protocol = m_filename.substr(0, m_filename.find_first_of(':')); if (protocol == "http" || protocol == "https") { default_settings_for_url(); } detect_format_from_suffix(m_filename); if (format != "") { parse_format(format); } }
inline int snprintf_s_sl(char *dest, rsize_t dmax, const char *format, char *s, long a) { char pformatList[MAX_FORMAT_ELEMENTS]; unsigned int index = 0; // Determine the number of format options in the format string unsigned int nfo = parse_format(format, &pformatList[0], MAX_FORMAT_ELEMENTS); // Check that there are not too many format options if ( nfo != 2 ) { dest[0] = '\0'; return SNPRFNEGATE(ESBADFMT); } // Check first format is of string type if ( CHK_FORMAT(FMT_STRING, pformatList[index]) == 0) { dest[0] = '\0'; return SNPRFNEGATE(ESFMTTYP); } index++; // Check that the format is for an integer type if ( CHK_FORMAT(FMT_LONG, pformatList[index]) == 0) { dest[0] = '\0'; return SNPRFNEGATE(ESFMTTYP); } index++; return snprintf(dest, dmax, format, s, a); }
// Like sprintf, except size of the buffer is passed in so that it won't get overrun. int16_t ssprintf(char *print_buffer, int16_t buffer_size, const char *format, va_list ap) { PARSEOPTION_TYPE options; char format_char; uint16_t out_size = 0; do { format_char = pgm_read_byte(format++); if (format_char == '%') { uint16_t size; init_option_data(&options); parse_format(&format, &options); size = expand_data(&ap, &options, print_buffer, buffer_size - out_size); print_buffer += size; out_size += size; } else { // just a normal character, move it in the buffer. *print_buffer++ = format_char; out_size++; } } while ((format_char != '\0') && (out_size < buffer_size)); // return how many characters we put into the buffer. return out_size; }
static error_t parse_opt(int k, char *optarg, struct argp_state *state) { struct arguments *args = state->input; switch (k) { case 'I': args->input_format = parse_format(optarg); break; case 'O': args->output_format = parse_format(optarg); break; case 's': args->delsys = parse_delsys(optarg); break; default: return ARGP_ERR_UNKNOWN; }; return 0; }
/* _print_job_step - print the specified job step's information */ static int _print_job_steps( bool clear_old ) { int error_code; static job_step_info_response_msg_t * old_step_ptr = NULL; static job_step_info_response_msg_t * new_step_ptr; uint16_t show_flags = 0; if (params.all_flag) show_flags |= SHOW_ALL; if (old_step_ptr) { if (clear_old) old_step_ptr->last_update = 0; /* Use a last_update time of 0 so that we can get an updated * run_time for jobs rather than just its start_time */ error_code = slurm_get_job_steps((time_t) 0, NO_VAL, NO_VAL, &new_step_ptr, show_flags); if (error_code == SLURM_SUCCESS) slurm_free_job_step_info_response_msg( old_step_ptr ); else if (slurm_get_errno () == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_step_ptr = old_step_ptr; } } else { error_code = slurm_get_job_steps((time_t) 0, NO_VAL, NO_VAL, &new_step_ptr, show_flags); } if (error_code) { slurm_perror ("slurm_get_job_steps error"); return SLURM_ERROR; } old_step_ptr = new_step_ptr; if (params.verbose) { printf ("last_update_time=%ld records=%u\n", (long) new_step_ptr->last_update, new_step_ptr->job_step_count); } if (!params.format && !params.format_long) params.format = "%.15i %.8j %.9P %.8u %.9M %N"; if (!params.format_list) { if (params.format) parse_format(params.format); else if (params.format_long) parse_long_format(params.format_long); } print_steps_array( new_step_ptr->job_steps, new_step_ptr->job_step_count, params.format_list ); return SLURM_SUCCESS; }
/* * We have to call this to set up the format of the columns. There is a * separate format for each addrbook, so we need to call this for each * addrbook. We call it when the pab's are built. It also depends on * whether or not as.checkboxes is set, so if we go into a Select mode * from the address book maintenance screen we need to re-call this. Since * we can't go back out of ListMode we don't have that problem. Restore_state * has to call it because of the as.checkboxes possibly being different in * the two states. */ void addrbook_new_disp_form(PerAddrBook *pab, char **list, int addrbook_num, int (*prefix_f)(PerAddrBook *, int *)) { char *last_one; int column = 0; dprint((9, "- init_disp_form(%s) -\n", (pab && pab->abnick) ? pab->abnick : "?")); memset((void *)pab->disp_form, 0, NFIELDS*sizeof(COL_S)); pab->disp_form[1].wtype = WeCalculate; /* so we don't get false AllAuto */ if(prefix_f) as.do_bold = (*prefix_f)(pab, &column); /* if custom format is specified */ if(list && list[0] && list[0][0]){ /* find the one for addrbook_num */ for(last_one = *list; *list != NULL && addrbook_num; addrbook_num--,list++) last_one = *list; /* If not enough to go around, last one repeats */ if(*list == NULL) parse_format(last_one, &(pab->disp_form[column])); else parse_format(*list, &(pab->disp_form[column])); } else{ /* default */ /* If 2nd wtype is AllAuto, the widths are calculated old way */ pab->disp_form[1].wtype = AllAuto; pab->disp_form[column++].type = Nickname; pab->disp_form[column++].type = Fullname; pab->disp_form[column++].type = Addr; /* Fill in rest */ while(column < NFIELDS) pab->disp_form[column++].type = Notused; } }
int ft_printf(const char *format, ...) { va_list args; int ret; va_start(args, format); if (*format == '\0') return (0); ret = parse_format(format, &args); va_end(args); return (ret); }
void parse_options(int argc, char *argv[]) { int c; // parameters for getopt_long() function static const char short_options[] = "AHSh:dif:v"; static const struct option long_options[] = { {"help", no_argument, NULL, 1 }, {"all", no_argument, NULL, 'A'}, {"hash", required_argument, NULL, 'h'}, {"format", required_argument, NULL, 'f'}, {"version", no_argument, NULL, 'v'}, { NULL, 0, NULL, 0 } }; // setting all fields to false memset(&config, false, sizeof(config)); config.all = true; while ((c = getopt_long(argc, argv, short_options, long_options, &ind))) { if (c < 0) break; switch (c) { case 1: // --help option usage(); exit(EXIT_SUCCESS); case 'A': config.all = true; break; case 'v': printf("%s %s\n%s\n", PROGRAM, TOOLKIT, COPY); exit(EXIT_SUCCESS); case 'h': config.all = false; parse_hash_algorithm(optarg); break; case 'f': parse_format(optarg); break; default: fprintf(stderr, "%s: try '--help' for more information\n", PROGRAM); exit(EXIT_FAILURE); } } }
/** * Create File using buffer pointer and size and type and encoding * from given format specification. * * @param buffer Pointer to buffer with data. * @param size Size of buffer. * @param format File format as string. See the description of the * parse_format() function for details. */ explicit File(const char* buffer, size_t size, const std::string& format = "") : Options(), m_filename(), m_buffer(buffer), m_buffer_size(size), m_format_string(format) { default_settings_for_stdinout(); if (format != "") { parse_format(format); } }
static bool parse_command_line( int argc, char *argv[] ) { int n; for (n = 1; n < argc; n++) { const char *arg = argv[n]; if (strcmp (arg, "-h") == 0 || strcmp (arg, "--help") == 0) { print_usage (argv[0]); return false; } if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) { fprintf (stderr, "dfbg version %s\n", DIRECTFB_VERSION); return false; } if (strcmp (arg, "-m") == 0 || strcmp (arg, "--mode") == 0) { if (++n == argc) { print_usage (argv[0]); return false; } if (!parse_mode( argv[n] )) return false; continue; } if (strcmp (arg, "-f") == 0 || strcmp (arg, "--format") == 0) { if (++n == argc) { print_usage (argv[0]); return false; } if (!parse_format( argv[n] )) return false; continue; } print_usage (argv[0]); return false; } return true; }
/* This routine is slow, but does the work and it's the simplest to write down. All this will get integrated into the linker anyway, so there's no point in doing optimizations */ void collect_sets(const char *file, setnode **setlist_ptr) { char secname[201]; FILE *pipe = my_popen(OBJDUMP_NAME " -h ", file); /* This fscanf() simply splits the whole stream into separate words */ while (fscanf(pipe, " %200s ", secname) > 0) { parse_format(secname); parse_secname(secname, setlist_ptr); } pclose(pipe); }
CAMLprim value caml_nativeint_format(value fmt, value arg) { char format_string[FORMAT_BUFFER_SIZE]; char default_format_buffer[FORMAT_BUFFER_SIZE]; char * buffer; char conv; value res; buffer = parse_format(fmt, ARCH_INTNAT_PRINTF_FORMAT, format_string, default_format_buffer, &conv); sprintf(buffer, format_string, Nativeint_val(arg)); res = caml_copy_string(buffer); if (buffer != default_format_buffer) caml_stat_free(buffer); return res; }
int ft_getprintf(char **ret, const char *format, va_list args) { t_printf_part *beginning[1]; va_list args2; int i; if (parse_format(format, beginning) <= 0) return (-1); va_copy(args2, args); if (build_specifiers(beginning, &args2) <= 0) return (-1); i = concat_parts(beginning, ret); ptf_free_list(beginning); return (i); }
static DFBBoolean parse_command_line( int argc, char *argv[] ) { int n; for (n = 1; n < argc; n++) { const char *arg = argv[n]; if (strcmp (arg, "-h") == 0 || strcmp (arg, "--help") == 0) { print_usage (argv[0]); return DFB_FALSE; } if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0) { fprintf (stderr, "mkdgiff version %s\n", DIRECTFB_VERSION); return DFB_FALSE; } if (strcmp (arg, "-f") == 0 || strcmp (arg, "--format") == 0) { if (++n == argc) { print_usage (argv[0]); return DFB_FALSE; } if (!parse_format( argv[n], &m_format )) return DFB_FALSE; continue; } if (filename || access( arg, R_OK )) { print_usage (argv[0]); return DFB_FALSE; } filename = arg; } if (!filename) { print_usage (argv[0]); return DFB_FALSE; } return DFB_TRUE; }
void parse_options(int argc, char *argv[]) { int c; /* Parameters for getopt_long() function */ static const char short_options[] = "d:f:v"; static const struct option long_options[] = { {"database", required_argument, NULL, 'd'}, {"format", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 1 }, {"version", no_argument, NULL, 'v'}, { NULL, 0, NULL, 0 } }; while ((c = getopt_long(argc, argv, short_options, long_options, &ind))) { if (c < 0) break; switch (c) { case 1: // --help option usage(); exit(EXIT_SUCCESS); case 'd': config.dbfile = optarg; break; case 'f': parse_format(optarg); break; case 'v': printf("%s %s\n%s\n", PROGRAM, TOOLKIT, COPY); exit(EXIT_SUCCESS); default: fprintf(stderr, "%s: try '--help' for more information\n", PROGRAM); exit(EXIT_FAILURE); } } }
static void parse_options(int argc, char *argv[]) { int c; /* Parameters for getopt_long() function */ static const char short_options[] = "f:v"; static const struct option long_options[] = { {"format", required_argument, NULL, 'f'}, {"help", no_argument, NULL, 1 }, {"verbose", no_argument, NULL, 'v'}, { NULL, 0, NULL, 0 } }; memset(&config, 0, sizeof(config)); while ((c = getopt_long(argc, argv, short_options, long_options, &ind))) { if (c < 0) break; switch (c) { case 1: // --help option usage(); exit(EXIT_SUCCESS); case 'f': parse_format(optarg); break; case 'v': config.verbose = true; break; default: fprintf(stderr, "%s: try '--help' for more information\n", PROGRAM); exit(EXIT_FAILURE); } } }
inline int snprintf_s_i(char *dest, rsize_t dmax, const char *format, int a) { char pformatList[MAX_FORMAT_ELEMENTS]; unsigned int index = 0; // Determine the number of format options in the format string unsigned int nfo = parse_format(format, &pformatList[0], MAX_FORMAT_ELEMENTS); // Check that there are not too many format options if ( nfo != 1 ) { dest[0] = '\0'; return SNPRFNEGATE(ESBADFMT); } // Check that the format is for an integer type if ( check_integer_format(pformatList[index]) == 0) { dest[0] = '\0'; return SNPRFNEGATE(ESFMTTYP); } index++; return snprintf(dest, dmax, format, a); }
CAMLprim value caml_format_int(value fmt, value arg) { char format_string[FORMAT_BUFFER_SIZE]; char default_format_buffer[FORMAT_BUFFER_SIZE]; char * buffer; char conv; value res; buffer = parse_format(fmt, ARCH_INTNAT_PRINTF_FORMAT, format_string, default_format_buffer, &conv); switch (conv) { case 'u': case 'x': case 'X': case 'o': sprintf(buffer, format_string, Unsigned_long_val(arg)); break; default: sprintf(buffer, format_string, Long_val(arg)); break; } res = caml_copy_string(buffer); if (buffer != default_format_buffer) caml_stat_free(buffer); return res; }
/** Parse the argv for command line parameters. */ void parse_options( int argc, char* argv[] ) { char *cmd; arg_tok( argv+1, 0 ); while (cmd = arg_tok(0,":=")) { cmd += strspn( cmd, "-/" ); if (str_in( cmd, "l", "ls", "list", 0 )) action = List; else if (str_in( cmd, "r", "rd", "read", 0 )) action = Read; else if (str_in( cmd, "h", "help", 0 )) action = Help; else if (str_in( cmd, "d", "dev", "device", 0 )) parse_device_id( arg_tok(0,"") ); else if (str_in( cmd, "c", "ch", "chan", "channel", 0 )) parse_channel_list( arg_tok(0,"") ); else if (str_in( cmd, "f", "fmt", "format", 0 )) parse_format( arg_tok(0,"") ); else errorf( "#### Unknown command: %s", cmd ); } }
static ParsedFormat * parsed_format_new (const char *output_format) { static GHashTable *output_format_to_parsed_format = NULL; ParsedFormat *rv; if (output_format == NULL) output_format = GSK_LOG_DEFAULT_OUTPUT_FORMAT; if (output_format_to_parsed_format == NULL) output_format_to_parsed_format = g_hash_table_new (g_str_hash, g_str_equal); rv = g_hash_table_lookup (output_format_to_parsed_format, output_format); if (rv) { ++(rv->ref_count); return rv; } else { rv = parse_format (output_format); if (rv == NULL) return NULL; g_hash_table_insert (output_format_to_parsed_format, rv->output_format, rv); } return rv; }
main(int argc, char *argv[]) #endif { char options[128] = "aAc:CdD::efF:g:hHI:L:m:M:no:O:Ptu:vx:X-:"; netsnmp_session *sess_list = NULL, *ss = NULL; netsnmp_transport *transport = NULL; int arg, i = 0; int uid = 0, gid = 0; int exit_code = 1; char *cp, *listen_ports = NULL; #if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(NETSNMP_SNMPTRAPD_DISABLE_AGENTX) int agentx_subagent = 1; #endif netsnmp_trapd_handler *traph; #ifndef WIN32 int prepared_sockets = 0; #endif #ifndef NETSNMP_NO_SYSTEMD /* check if systemd has sockets for us and don't close them */ prepared_sockets = netsnmp_sd_listen_fds(0); #endif #ifndef WIN32 /* * close all non-standard file descriptors we may have * inherited from the shell. */ if (!prepared_sockets) netsnmp_close_fds(2); #endif #ifdef SIGTERM signal(SIGTERM, term_handler); #endif #ifdef SIGHUP signal(SIGHUP, SIG_IGN); /* do not terminate on early SIGHUP */ #endif #ifdef SIGINT signal(SIGINT, term_handler); #endif #ifdef SIGPIPE signal(SIGPIPE, SIG_IGN); /* 'Inline' failure of wayward readers */ #endif /* * register our configuration handlers now so -H properly displays them */ snmptrapd_register_configs( ); #ifdef NETSNMP_USE_MYSQL snmptrapd_register_sql_configs( ); #endif #ifdef NETSNMP_SECMOD_USM init_usm_conf( "snmptrapd" ); #endif /* NETSNMP_SECMOD_USM */ register_config_handler("snmptrapd", "snmpTrapdAddr", parse_trapd_address, free_trapd_address, "string"); register_config_handler("snmptrapd", "doNotLogTraps", parse_config_doNotLogTraps, NULL, "(1|yes|true|0|no|false)"); #if HAVE_GETPID register_config_handler("snmptrapd", "pidFile", parse_config_pidFile, NULL, "string"); #endif #ifdef HAVE_UNISTD_H register_config_handler("snmptrapd", "agentuser", parse_config_agentuser, NULL, "userid"); register_config_handler("snmptrapd", "agentgroup", parse_config_agentgroup, NULL, "groupid"); #endif register_config_handler("snmptrapd", "doNotFork", parse_config_doNotFork, NULL, "(1|yes|true|0|no|false)"); register_config_handler("snmptrapd", "ignoreAuthFailure", parse_config_ignoreAuthFailure, NULL, "(1|yes|true|0|no|false)"); register_config_handler("snmptrapd", "outputOption", parse_config_outputOption, NULL, "string"); /* * Add some options if they are available. */ #if HAVE_GETPID strcat(options, "p:"); #endif #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG #ifdef WIN32 snmp_log_syslogname(app_name_long); #else snmp_log_syslogname(app_name); #endif #endif /* NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG */ /* * Now process options normally. */ while ((arg = getopt(argc, argv, options)) != EOF) { switch (arg) { case '-': if (strcasecmp(optarg, "help") == 0 || strcasecmp(optarg, "version") == 0) { version(); exit_code = 0; goto out; } handle_long_opt(optarg); break; case 'a': dropauth = 1; break; case 'A': netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPEND_LOGFILES, 1); break; case 'c': if (optarg != NULL) { netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_OPTIONALCONFIG, optarg); } else { usage(); goto out; } break; case 'C': netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_READ_CONFIGS, 1); break; case 'd': netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DUMP_PACKET, 1); break; case 'D': debug_register_tokens(optarg); snmp_set_do_debugging(1); break; case 'f': dofork = 0; break; case 'F': if (optarg != NULL) { if (( strncmp( optarg, "print", 5 ) == 0 ) || ( strncmp( optarg, "syslog", 6 ) == 0 ) || ( strncmp( optarg, "execute", 7 ) == 0 )) { /* New style: "type=format" */ trap1_fmt_str_remember = strdup(optarg); cp = strchr( trap1_fmt_str_remember, '=' ); if (cp) *cp = ' '; } else { /* Old style: implicitly "print=format" */ trap1_fmt_str_remember = malloc(strlen(optarg) + 7); sprintf( trap1_fmt_str_remember, "print %s", optarg ); } } else { usage(); goto out; } break; #if HAVE_UNISTD_H case 'g': if (optarg != NULL) { netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_GROUPID, gid = atoi(optarg)); } else { usage(); goto out; } break; #endif case 'h': usage(); exit_code = 0; goto out; case 'H': init_agent("snmptrapd"); #ifdef USING_NOTIFICATION_LOG_MIB_NOTIFICATION_LOG_MODULE init_notification_log(); #endif #ifdef NETSNMP_EMBEDDED_PERL init_perl(); #endif init_snmp("snmptrapd"); fprintf(stderr, "Configuration directives understood:\n"); read_config_print_usage(" "); exit_code = 0; goto out; case 'I': if (optarg != NULL) { add_to_init_list(optarg); } else { usage(); } break; case 'S': fprintf(stderr, "Warning: -S option has been withdrawn; use -Ls <facility> instead\n"); goto out; case 'm': if (optarg != NULL) { setenv("MIBS", optarg, 1); } else { usage(); goto out; } break; case 'M': if (optarg != NULL) { setenv("MIBDIRS", optarg, 1); } else { usage(); goto out; } break; case 'n': netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_APP_NUMERIC_IP, 1); break; case 'o': fprintf(stderr, "Warning: -o option has been withdrawn; use -Lf <file> instead\n"); goto out; case 'O': cp = snmp_out_toggle_options(optarg); if (cp != NULL) { fprintf(stderr, "Unknown output option passed to -O: %c\n", *cp); usage(); goto out; } break; case 'L': if (snmp_log_options( optarg, argc, argv ) < 0 ) { usage(); goto out; } break; #if HAVE_GETPID case 'p': if (optarg != NULL) { parse_config_pidFile(NULL, optarg); } else { usage(); goto out; } break; #endif case 'P': fprintf(stderr, "Warning: -P option has been withdrawn; use -f -Le instead\n"); goto out; case 's': fprintf(stderr, "Warning: -s option has been withdrawn; use -Lsd instead\n"); goto out; case 't': SyslogTrap++; break; #if HAVE_UNISTD_H case 'u': if (optarg != NULL) { char *ecp; uid = strtoul(optarg, &ecp, 10); #if HAVE_GETPWNAM && HAVE_PWD_H if (*ecp) { struct passwd *info; info = getpwnam(optarg); uid = info ? info->pw_uid : -1; endpwent(); } #endif if (uid < 0) { fprintf(stderr, "Bad user id: %s\n", optarg); goto out; } netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_USERID, uid); } else { usage(); goto out; } break; #endif case 'v': version(); exit(0); break; #if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(NETSNMP_SNMPTRAPD_DISABLE_AGENTX) case 'x': if (optarg != NULL) { netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, optarg); } else { usage(); goto out; } break; case 'X': agentx_subagent = 0; break; #endif default: fprintf(stderr, "invalid option: -%c\n", arg); usage(); goto out; break; } } if (optind < argc) { /* * There are optional transport addresses on the command line. */ for (i = optind; i < argc; i++) { char *astring; if (listen_ports != NULL) { astring = malloc(strlen(listen_ports) + 2 + strlen(argv[i])); if (astring == NULL) { fprintf(stderr, "malloc failure processing argv[%d]\n", i); goto out; } sprintf(astring, "%s,%s", listen_ports, argv[i]); free(listen_ports); listen_ports = astring; } else { listen_ports = strdup(argv[i]); if (listen_ports == NULL) { fprintf(stderr, "malloc failure processing argv[%d]\n", i); goto out; } } } } SOCK_STARTUP; /* * I'm being lazy here, and not checking the * return value from these registration calls. * Don't try this at home, children! */ if (0 == snmp_get_do_logging()) { #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER, syslog_handler); traph->authtypes = TRAP_AUTH_LOG; snmp_enable_syslog(); #else /* NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG */ #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_STDIO traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER, print_handler); traph->authtypes = TRAP_AUTH_LOG; snmp_enable_stderr(); #endif /* NETSNMP_FEATURE_REMOVE_LOGGING_STDIO */ #endif /* NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG */ } else { traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_PRE_HANDLER, print_handler); traph->authtypes = TRAP_AUTH_LOG; } #if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(NETSNMP_SNMPTRAPD_DISABLE_AGENTX) /* * we're an agentx subagent? */ if (agentx_subagent) { /* * make us a agentx client. */ netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1); } #endif /* * don't fail if we can't do agentx (ie, socket not there, or not root) */ netsnmp_ds_toggle_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS); /* * ignore any warning messages. */ netsnmp_ds_toggle_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_CONNECTION_WARNINGS); /* * initialize the agent library */ init_agent("snmptrapd"); #if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(NETSNMP_SNMPTRAPD_DISABLE_AGENTX) #ifdef NETSNMP_FEATURE_CHECKING netsnmp_feature_require(register_snmpEngine_scalars_context) #endif /* NETSNMP_FEATURE_CHECKING */ /* * initialize local modules */ if (agentx_subagent) { #ifdef USING_SNMPV3_SNMPENGINE_MODULE extern void register_snmpEngine_scalars_context(const char *); #endif subagent_init(); #ifdef USING_NOTIFICATION_LOG_MIB_NOTIFICATION_LOG_MODULE /* register the notification log table */ if (should_init("notificationLogMib")) { netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_NOTIF_LOG_CTX, "snmptrapd"); traph = netsnmp_add_global_traphandler(NETSNMPTRAPD_POST_HANDLER, notification_handler); traph->authtypes = TRAP_AUTH_LOG; init_notification_log(); } #endif #ifdef USING_SNMPV3_SNMPENGINE_MODULE /* * register scalars from SNMP-FRAMEWORK-MIB::snmpEngineID group; * allows engineID probes via the master agent under the * snmptrapd context */ register_snmpEngine_scalars_context("snmptrapd"); #endif } #endif /* USING_AGENTX_SUBAGENT_MODULE && !NETSNMP_SNMPTRAPD_DISABLE_AGENTX */ /* register our authorization handler */ init_netsnmp_trapd_auth(); #if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(NETSNMP_SNMPTRAPD_DISABLE_AGENTX) if (agentx_subagent) { #ifdef USING_AGENT_NSVACMACCESSTABLE_MODULE extern void init_register_nsVacm_context(const char *); #endif #ifdef USING_SNMPV3_USMUSER_MODULE #ifdef NETSNMP_FEATURE_CHECKING netsnmp_feature_require(init_register_usmUser_context) #endif /* NETSNMP_FEATURE_CHECKING */ extern void init_register_usmUser_context(const char *); /* register ourselves as having a USM user database */ init_register_usmUser_context("snmptrapd"); #endif #ifdef USING_AGENT_NSVACMACCESSTABLE_MODULE /* register net-snmp vacm extensions */ init_register_nsVacm_context("snmptrapd"); #endif #ifdef USING_TLSTM_MIB_SNMPTLSTMCERTTOTSNTABLE_MODULE init_snmpTlstmCertToTSNTable_context("snmptrapd"); #endif } #endif #ifdef NETSNMP_EMBEDDED_PERL init_perl(); { /* set the default path to load */ char init_file[SNMP_MAXBUF]; snprintf(init_file, sizeof(init_file) - 1, "%s/%s", SNMPSHAREPATH, "snmp_perl_trapd.pl"); netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_PERL_INIT_FILE, init_file); } #endif /* * Initialize the world. */ init_snmp("snmptrapd"); #ifdef SIGHUP signal(SIGHUP, hup_handler); #endif if (trap1_fmt_str_remember) { parse_format( NULL, trap1_fmt_str_remember ); } if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_QUIT_IMMEDIATELY)) { /* * just starting up to process specific configuration and then * shutting down immediately. */ netsnmp_running = 0; } /* * if no logging options on command line or in conf files, use syslog */ if (0 == snmp_get_do_logging()) { #ifndef NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG #ifdef WIN32 snmp_enable_syslog_ident(app_name_long, Facility); #else snmp_enable_syslog_ident(app_name, Facility); #endif #endif /* NETSNMP_FEATURE_REMOVE_LOGGING_SYSLOG */ } if (listen_ports) cp = listen_ports; else cp = default_port; while (cp != NULL) { char *sep = strchr(cp, ','); if (sep != NULL) { *sep = 0; } transport = netsnmp_transport_open_server("snmptrap", cp); if (transport == NULL) { snmp_log(LOG_ERR, "couldn't open %s -- errno %d (\"%s\")\n", cp, errno, strerror(errno)); snmptrapd_close_sessions(sess_list); goto sock_cleanup; } else { ss = snmptrapd_add_session(transport); if (ss == NULL) { /* * Shouldn't happen? We have already opened the transport * successfully so what could have gone wrong? */ snmptrapd_close_sessions(sess_list); snmp_log(LOG_ERR, "couldn't open snmp - %s", strerror(errno)); goto sock_cleanup; } else { ss->next = sess_list; sess_list = ss; } } /* * Process next listen address, if there is one. */ if (sep != NULL) { *sep = ','; cp = sep + 1; } else { cp = NULL; } } SNMP_FREE(listen_ports); /* done with them */ #ifdef NETSNMP_USE_MYSQL if( netsnmp_mysql_init() ) { fprintf(stderr, "MySQL initialization failed\n"); goto sock_cleanup; } #endif #ifndef WIN32 /* * fork the process to the background if we are not printing to stderr */ if (dofork && netsnmp_running) { int fd; #if HAVE_FORKALL switch (forkall()) { #else switch (fork()) { #endif case -1: fprintf(stderr, "bad fork - %s\n", strerror(errno)); goto sock_cleanup; case 0: /* * become process group leader */ if (setsid() == -1) { fprintf(stderr, "bad setsid - %s\n", strerror(errno)); goto sock_cleanup; } /* * if we are forked, we don't want to print out to stdout or stderr */ fd = open("/dev/null", O_RDWR); if (fd >= 0) { dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); close(fd); } break; default: _exit(0); } } #endif /* WIN32 */ #if HAVE_GETPID if (pid_file != NULL) { if ((PID = fopen(pid_file, "w")) == NULL) { snmp_log_perror("fopen"); goto sock_cleanup; } fprintf(PID, "%d\n", (int) getpid()); fclose(PID); free_config_pidFile(); } #endif snmp_log(LOG_INFO, "NET-SNMP version %s\n", netsnmp_get_version()); /* * ignore early sighup during startup */ reconfig = 0; #if HAVE_UNISTD_H #ifdef HAVE_SETGID if ((gid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_GROUPID)) > 0) { DEBUGMSGTL(("snmptrapd/main", "Changing gid to %d.\n", gid)); if (setgid(gid) == -1 #ifdef HAVE_SETGROUPS || setgroups(1, (gid_t *)&gid) == -1 #endif ) { snmp_log_perror("setgid failed"); if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) { goto sock_cleanup; } } } #endif #ifdef HAVE_SETUID if ((uid = netsnmp_ds_get_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_USERID)) != 0) { DEBUGMSGTL(("snmptrapd/main", "Changing uid to %d.\n", uid)); if (setuid(uid) == -1) { snmp_log_perror("setuid failed"); if (!netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_NO_ROOT_ACCESS)) { goto sock_cleanup; } } } #endif #endif /* * Let systemd know we're up. */ #ifndef NETSNMP_NO_SYSTEMD netsnmp_sd_notify(1, "READY=1\n"); if (prepared_sockets) /* * Clear the environment variable, we already processed all the sockets * by now. */ netsnmp_sd_listen_fds(1); #endif #ifdef WIN32SERVICE trapd_status = SNMPTRAPD_RUNNING; #endif snmptrapd_main_loop(); if (snmp_get_do_logging()) { struct tm *tm; time_t timer; time(&timer); tm = localtime(&timer); snmp_log(LOG_INFO, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d NET-SNMP version %s Stopped.\n", tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, netsnmp_get_version()); } snmp_log(LOG_INFO, "Stopping snmptrapd\n"); #ifdef NETSNMP_EMBEDDED_PERL shutdown_perl(); #endif snmptrapd_close_sessions(sess_list); snmp_shutdown("snmptrapd"); #ifdef WIN32SERVICE trapd_status = SNMPTRAPD_STOPPED; #endif snmp_disable_log(); exit_code = 0; sock_cleanup: SOCK_CLEANUP; out: return exit_code; } /* * Read the configuration files. Implemented as a signal handler so that * receipt of SIGHUP will cause configuration to be re-read when the * trap daemon is running detatched from the console. * */ void trapd_update_config(void) { free_config(); #ifdef USING_MIBII_VACM_CONF_MODULE vacm_standard_views(0,0,NULL,NULL); #endif read_configs(); }
static void snmptrapd_main_loop(void) { int count, numfds, block; fd_set readfds,writefds,exceptfds; struct timeval timeout, *tvp; while (netsnmp_running) { if (reconfig) { /* * If we are logging to a file, receipt of SIGHUP also * indicates that the log file should be closed and * re-opened. This is useful for users that want to * rotate logs in a more predictable manner. */ netsnmp_logging_restart(); snmp_log(LOG_INFO, "NET-SNMP version %s restarted\n", netsnmp_get_version()); trapd_update_config(); if (trap1_fmt_str_remember) { parse_format( NULL, trap1_fmt_str_remember ); } reconfig = 0; } numfds = 0; FD_ZERO(&readfds); FD_ZERO(&writefds); FD_ZERO(&exceptfds); block = 0; tvp = &timeout; timerclear(tvp); tvp->tv_sec = 5; snmp_select_info(&numfds, &readfds, tvp, &block); if (block == 1) tvp = NULL; /* block without timeout */ #ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER netsnmp_external_event_info(&numfds, &readfds, &writefds, &exceptfds); #endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */ count = select(numfds, &readfds, &writefds, &exceptfds, tvp); if (count > 0) { #ifndef NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER netsnmp_dispatch_external_events(&count, &readfds, &writefds, &exceptfds); #endif /* NETSNMP_FEATURE_REMOVE_FD_EVENT_MANAGER */ /* If there are any more events after external events, then * try SNMP events. */ if (count > 0) { snmp_read(&readfds); } } else { switch (count) { case 0: snmp_timeout(); break; case -1: if (errno == EINTR) continue; snmp_log_perror("select"); netsnmp_running = 0; break; default: fprintf(stderr, "select returned %d\n", count); netsnmp_running = 0; } } run_alarms(); } }
int main (int argc, char *argv[]) { char *prio_type = NULL; int error_code = SLURM_SUCCESS; priority_factors_request_msg_t req_msg; priority_factors_response_msg_t *resp_msg = NULL; log_options_t opts = LOG_OPTS_STDERR_ONLY ; slurm_conf_init(NULL); log_init(xbasename(argv[0]), opts, SYSLOG_FACILITY_USER, NULL); parse_command_line( argc, argv ); if (params.verbose) { opts.stderr_level += params.verbose; log_alter(opts, SYSLOG_FACILITY_USER, NULL); } if (working_cluster_rec) { slurm_ctl_conf_info_msg_t *slurm_ctl_conf_ptr; error_code = slurm_load_ctl_conf((time_t) NULL, &slurm_ctl_conf_ptr); if (error_code) { slurm_perror ("slurm_load_ctl_conf error"); exit(error_code); } weight_age = slurm_ctl_conf_ptr->priority_weight_age; weight_fs = slurm_ctl_conf_ptr->priority_weight_fs; weight_js = slurm_ctl_conf_ptr->priority_weight_js; weight_part = slurm_ctl_conf_ptr->priority_weight_part; weight_qos = slurm_ctl_conf_ptr->priority_weight_qos; weight_tres = slurm_ctl_conf_ptr->priority_weight_tres; prio_type = xstrdup(slurm_ctl_conf_ptr->priority_type); slurm_free_ctl_conf(slurm_ctl_conf_ptr); } else { weight_age = slurm_get_priority_weight_age(); weight_fs = slurm_get_priority_weight_fairshare(); weight_js = slurm_get_priority_weight_job_size(); weight_part = slurm_get_priority_weight_partition(); weight_qos = slurm_get_priority_weight_qos(); weight_tres = slurm_get_priority_weight_tres(); prio_type = slurm_get_priority_type(); } /* Check to see if we are running a supported accounting plugin */ if (xstrcasecmp(prio_type, "priority/basic") == 0) { fprintf (stderr, "You are not running a supported " "priority plugin\n(%s).\n" "Only 'priority/multifactor' is supported.\n", prio_type); exit(1); } xfree(prio_type); memset(&req_msg, 0, sizeof(priority_factors_request_msg_t)); if (params.jobs) req_msg.job_id_list = params.job_list; else req_msg.job_id_list = NULL; if (params.users) req_msg.uid_list = params.user_list; else req_msg.uid_list = NULL; error_code = _get_info(&req_msg, &resp_msg); if (error_code) { slurm_perror("Couldn't get priority factors from controller"); exit(error_code); } if (params.format == NULL) { if (params.normalized) { if (params.long_list) params.format = "%.15i %.8u %10y %10a %10f " "%10j %10p %10q %20t"; else{ params.format = xstrdup("%.15i"); if (params.users) xstrcat(params.format, " %.8u"); xstrcat(params.format, " %10y"); if (weight_age) xstrcat(params.format, " %10a"); if (weight_fs) xstrcat(params.format, " %10f"); if (weight_js) xstrcat(params.format, " %10j"); if (weight_part) xstrcat(params.format, " %10p"); if (weight_qos) xstrcat(params.format, " %10q"); if (weight_tres) xstrcat(params.format, " %20t"); } } else { if (params.long_list) params.format = "%.15i %.8u %.10Y %.10A %.10F " "%.10J %.10P %.10Q %.6N %.20T"; else{ params.format = xstrdup("%.15i"); if (params.users) xstrcat(params.format, " %.8u"); xstrcat(params.format, " %.10Y"); if (weight_age) xstrcat(params.format, " %.10A"); if (weight_fs) xstrcat(params.format, " %.10F"); if (weight_js) xstrcat(params.format, " %.10J"); if (weight_part) xstrcat(params.format, " %.10P"); if (weight_qos) xstrcat(params.format, " %.10Q"); if (weight_tres) xstrcat(params.format, " %.20T"); } } } /* create the format list from the format */ parse_format(params.format); if (params.jobs && (!resp_msg || !resp_msg->priority_factors_list || !list_count(resp_msg->priority_factors_list))) { printf("Unable to find jobs matching user/id(s) specified\n"); } else if (resp_msg) { print_jobs_array(resp_msg->priority_factors_list, params.format_list); } #if 0 /* Free storage here if we want to verify that logic. * Since we exit next, this is not important */ FREE_NULL_LIST(params.format_list); slurm_free_priority_factors_response_msg(resp_msg); #endif exit (error_code); }
/* _print_job - print the specified job's information */ static int _print_job ( bool clear_old ) { static job_info_msg_t * old_job_ptr = NULL, * new_job_ptr; int error_code; uint16_t show_flags = 0; uint32_t job_id = 0; if (params.all_flag || (params.job_list && list_count(params.job_list))) show_flags |= SHOW_ALL; /* We require detail data when CPUs are requested */ if (params.format && strstr(params.format, "C")) show_flags |= SHOW_DETAIL; if (params.job_list && (list_count(params.job_list) == 1)) { ListIterator iterator; uint32_t *job_id_ptr; iterator = list_iterator_create(params.job_list); job_id_ptr = list_next(iterator); job_id = *job_id_ptr; list_iterator_destroy(iterator); } if (old_job_ptr) { if (clear_old) old_job_ptr->last_update = 0; if (job_id) { error_code = slurm_load_job( &new_job_ptr, job_id, show_flags); } else { error_code = slurm_load_jobs( old_job_ptr->last_update, &new_job_ptr, show_flags); } if (error_code == SLURM_SUCCESS) slurm_free_job_info_msg( old_job_ptr ); else if (slurm_get_errno () == SLURM_NO_CHANGE_IN_DATA) { error_code = SLURM_SUCCESS; new_job_ptr = old_job_ptr; } } else if (job_id) { error_code = slurm_load_job(&new_job_ptr, job_id, show_flags); } else { error_code = slurm_load_jobs((time_t) NULL, &new_job_ptr, show_flags); } if (error_code) { slurm_perror ("slurm_load_jobs error"); return SLURM_ERROR; } old_job_ptr = new_job_ptr; if (job_id) old_job_ptr->last_update = (time_t) 0; if (params.verbose) { printf ("last_update_time=%ld\n", (long) new_job_ptr->last_update); } if (params.format == NULL) { if (params.long_list) params.format = "%.7i %.9P %.8j %.8u %.8T %.10M %.9l " "%.6D %R"; else params.format = "%.7i %.9P %.8j %.8u %.2t %.10M %.6D %R"; } if (params.format_list == NULL) parse_format(params.format); print_jobs_array( new_job_ptr->job_array, new_job_ptr->record_count , params.format_list ) ; return SLURM_SUCCESS; }
// Consume already buffered data. Returns true if audio transmitted. bool AudioPlaySdWav::consume(uint32_t size) { uint32_t len; uint8_t lsb, msb; const uint8_t *p; p = buffer + buffer_offset; start: if (size == 0) return false; #if 0 Serial.print("AudioPlaySdWav consume, "); Serial.print("size = "); Serial.print(size); Serial.print(", buffer_offset = "); Serial.print(buffer_offset); Serial.print(", data_length = "); Serial.print(data_length); Serial.print(", space = "); Serial.print((AUDIO_BLOCK_SAMPLES - block_offset) * 2); Serial.print(", state = "); Serial.println(state); #endif switch (state) { // parse wav file header, is this really a .wav file? case STATE_PARSE1: len = data_length; if (size < len) len = size; memcpy((uint8_t *)header + header_offset, p, len); header_offset += len; buffer_offset += len; buffer_length -= len; data_length -= len; if (data_length > 0) return false; // parse the header... if (header[0] == 0x46464952 && header[2] == 0x45564157 && header[3] == 0x20746D66 && header[4] >= 16) { if (header[4] > sizeof(header)) { // if such .wav files exist, increasing the // size of header[] should accomodate them... //Serial.println("WAVEFORMATEXTENSIBLE too long"); break; } //Serial.println("header ok"); p += len; size -= len; data_length = header[4]; header_offset = 0; state = STATE_PARSE2; goto start; } //Serial.println("unknown WAV header"); break; // check & extract key audio parameters case STATE_PARSE2: len = data_length; if (size < len) len = size; memcpy((uint8_t *)header + header_offset, p, len); header_offset += len; buffer_offset += len; buffer_length -= len; data_length -= len; if (data_length > 0) return false; if (parse_format()) { //Serial.println("audio format ok"); p += len; size -= len; data_length = 8; header_offset = 0; state = STATE_PARSE3; goto start; } //Serial.println("unknown audio format"); break; // find the data chunk case STATE_PARSE3: // 10 len = data_length; if (size < len) len = size; memcpy((uint8_t *)header + header_offset, p, len); header_offset += len; buffer_offset += len; buffer_length -= len; data_length -= len; if (data_length > 0) return false; //Serial.print("chunk id = "); //Serial.print(header[0], HEX); //Serial.print(", length = "); //Serial.println(header[1]); p += len; size -= len; data_length = header[1]; if (header[0] == 0x61746164) { //Serial.print("wav: found data chunk, len="); //Serial.println(data_length); // TODO: verify offset in file is an even number // as required by WAV format. abort if odd. Code // below will depend upon this and fail if not even. leftover_bytes = 0; state = state_play; if (state & 1) { // if we're going to start stereo // better allocate another output block block_right = allocate(); if (!block_right) return false; } total_length = data_length; } else { state = STATE_PARSE4; } goto start; // ignore any extra unknown chunks (title & artist info) case STATE_PARSE4: // 11 if (size < data_length) { data_length -= size; buffer_offset += size; buffer_length -= size; return false; } p += data_length; size -= data_length; buffer_offset += data_length; buffer_length -= data_length; data_length = 8; header_offset = 0; state = STATE_PARSE3; //Serial.println("consumed unknown chunk"); goto start; // playing mono at native sample rate case STATE_DIRECT_8BIT_MONO: return false; // playing stereo at native sample rate case STATE_DIRECT_8BIT_STEREO: return false; // playing mono at native sample rate case STATE_DIRECT_16BIT_MONO: if (size > data_length) size = data_length; data_length -= size; while (1) { lsb = *p++; msb = *p++; size -= 2; block_left->data[block_offset++] = (msb << 8) | lsb; if (block_offset >= AUDIO_BLOCK_SAMPLES) { transmit(block_left, 0); transmit(block_left, 1); release(block_left); block_left = NULL; data_length += size; buffer_offset = p - buffer; if (block_right) release(block_right); if (data_length == 0) state = STATE_STOP; return true; } if (size == 0) { if (data_length == 0) break; return false; } } //Serial.println("end of file reached"); // end of file reached if (block_offset > 0) { // TODO: fill remainder of last block with zero and transmit } state = STATE_STOP; return false; // playing stereo at native sample rate case STATE_DIRECT_16BIT_STEREO: if (size > data_length) size = data_length; data_length -= size; if (leftover_bytes) { block_left->data[block_offset] = header[0]; goto right16; } while (1) { lsb = *p++; msb = *p++; size -= 2; if (size == 0) { if (data_length == 0) break; header[0] = (msb << 8) | lsb; leftover_bytes = 2; return false; } block_left->data[block_offset] = (msb << 8) | lsb; right16: lsb = *p++; msb = *p++; size -= 2; block_right->data[block_offset++] = (msb << 8) | lsb; if (block_offset >= AUDIO_BLOCK_SAMPLES) { transmit(block_left, 0); release(block_left); block_left = NULL; transmit(block_right, 1); release(block_right); block_right = NULL; data_length += size; buffer_offset = p - buffer; if (data_length == 0) state = STATE_STOP; return true; } if (size == 0) { if (data_length == 0) break; leftover_bytes = 0; return false; } } // end of file reached if (block_offset > 0) { // TODO: fill remainder of last block with zero and transmit } state = STATE_STOP; return false; // playing mono, converting sample rate case STATE_CONVERT_8BIT_MONO : return false; // playing stereo, converting sample rate case STATE_CONVERT_8BIT_STEREO: return false; // playing mono, converting sample rate case STATE_CONVERT_16BIT_MONO: return false; // playing stereo, converting sample rate case STATE_CONVERT_16BIT_STEREO: return false; // ignore any extra data after playing // or anything following any error case STATE_STOP: return false; // this is not supposed to happen! //default: //Serial.println("AudioPlaySdWav, unknown state"); } state_play = STATE_STOP; state = STATE_STOP; return false; }