static int do_show(int argc, char **argv) { DIR *dir; struct dirent *d; long flags, owner = -1, group = -1; dir = opendir("/sys/class/net"); if (!dir) { perror("opendir"); return -1; } while ((d = readdir(dir))) { if (d->d_name[0] == '.' && (d->d_name[1] == 0 || d->d_name[1] == '.')) continue; if (read_prop(d->d_name, "tun_flags", &flags)) continue; read_prop(d->d_name, "owner", &owner); read_prop(d->d_name, "group", &group); printf("%s:", d->d_name); print_flags(flags); if (owner != -1) printf(" user %ld", owner); if (group != -1) printf(" group %ld", group); printf("\n"); } closedir(dir); return 0; }
/* * read_props reads either the full set of properties for instance 'instance' * (including defaults - pulling them in from inetd where necessary) if * 'instance' is non-null, else just the defaults from inetd. The properties * are returned in an allocated inetd_prop_t array, which must be freed * using free_instance_props(). If an error occurs NULL is returned and 'err' * is set to indicate the cause, else a pointer to the read properties is * returned. */ static inetd_prop_t * read_props(scf_handle_t *h, const char *instance, size_t *num_elements, scf_error_t *err) { inetd_prop_t *ret = NULL; int i; boolean_t defaults_only = (instance == NULL); if ((ret = malloc(sizeof (inetd_properties))) == NULL) { *err = SCF_ERROR_NO_MEMORY; return (NULL); } (void) memcpy(ret, &inetd_properties, sizeof (inetd_properties)); if (defaults_only) instance = INETD_INSTANCE_FMRI; for (i = 0; ret[i].ip_name != NULL; i++) { if (defaults_only && !ret[i].ip_default) continue; switch (*err = read_prop(h, &ret[i], i, instance, defaults_only ? PG_NAME_SERVICE_DEFAULTS : ret[i].ip_pg)) { case 0: break; case SCF_ERROR_INVALID_ARGUMENT: goto failure_cleanup; case SCF_ERROR_NOT_FOUND: /* * In non-default-only mode where we're reading a * default property, since the property wasn't * found in the instance, try and read inetd's default * value. */ if (!ret[i].ip_default || defaults_only) continue; switch (*err = read_prop(h, &ret[i], i, INETD_INSTANCE_FMRI, PG_NAME_SERVICE_DEFAULTS)) { case 0: ret[i].from_inetd = B_TRUE; continue; case SCF_ERROR_NOT_FOUND: continue; default: goto failure_cleanup; } default: goto failure_cleanup; } } *num_elements = i; return (ret); failure_cleanup: free_instance_props(ret); return (NULL); }
static void set_prop(gmx_atomprop_t aps, int eprop) { gmx_atomprop *ap2 = (gmx_atomprop*) aps; const char *fns[epropNR] = { "atommass.dat", "vdwradii.dat", "dgsolv.dat", "electroneg.dat", "elements.dat" }; double fac[epropNR] = { 1.0, 1.0, 418.4, 1.0, 1.0 }; double def[epropNR] = { 12.011, 0.14, 0.0, 2.2, -1 }; aprop_t *ap; ap = &ap2->prop[eprop]; if (!ap->bSet) { ap->db = gmx_strdup(fns[eprop]); ap->def = def[eprop]; read_prop(aps, eprop, fac[eprop]); if (debug) { fprintf(debug, "Entries in %s: %d\n", ap->db, ap->nprop); } if ( ( (!aps->bWarned) && (eprop == epropMass) ) || (eprop == epropVDW)) { printf("\n" "WARNING: Masses and atomic (Van der Waals) radii will be guessed\n" " based on residue and atom names, since they could not be\n" " definitively assigned from the information in your input\n" " files. These guessed numbers might deviate from the mass\n" " and radius of the atom type. Please check the output\n" " files if necessary.\n\n"); aps->bWarned = TRUE; } } }
static void set_prop(gmx_atomprop_t aps,int eprop) { gmx_atomprop *ap2 = (gmx_atomprop*) aps; const char *fns[epropNR] = { "atommass.dat", "vdwradii.dat", "dgsolv.dat", "electroneg.dat", "elements.dat" }; double fac[epropNR] = { 1.0, 1.0, 418.4, 1.0, 1.0 }; double def[epropNR] = { 12.011, 0.14, 0.0, 2.2, -1 }; aprop_t *ap; ap = &ap2->prop[eprop]; if (!ap->bSet) { ap->db = strdup(fns[eprop]); ap->def = def[eprop]; read_prop(aps,eprop,fac[eprop]); if (debug) fprintf(debug,"Entries in %s: %d\n",ap->db,ap->nprop); if ( ( (!aps->bWarned) && (eprop == epropMass) ) || (eprop == epropVDW)) { printf("\n"); printf("WARNING: masses and atomic (Van der Waals) radii will be determined\n"); printf(" based on residue and atom names. These numbers can deviate\n"); printf(" from the correct mass and radius of the atom type.\n"); printf("\n"); aps->bWarned = TRUE; } } }
/* * Try and read each of the method properties for the method 'method' of * instance 'inst', and return a table containing all method properties. If an * error occurs, NULL is returned, with 'err' set to indicate the cause. * Otherwise, a pointer to an inetd_prop_t table is returned containing all * the method properties, and each of the properties is flagged according to * whether it was present or not, and if it was present its value is set in * the property's entry in the table. */ static inetd_prop_t * read_method_props(const char *inst, instance_method_t method, scf_error_t *err) { inetd_prop_t *ret; int i; debug_msg("Entering read_method_props"); if ((ret = calloc(1, sizeof (method_props))) == NULL) { *err = SCF_ERROR_NO_MEMORY; return (NULL); } (void) memcpy(ret, method_props, sizeof (method_props)); for (i = 0; ret[i].ip_name != NULL; i++) { *err = read_prop(rep_handle, &ret[i], i, inst, methods[method].name); if ((*err != 0) && (*err != SCF_ERROR_NOT_FOUND)) { destroy_method_props(ret); return (NULL); } } return (ret); }
string ConfigElem::read_string( const char *propname, const char *dflt ) const { string temp; if (read_prop( propname, &temp)) return temp; else return dflt; }
int mnl_utl_load_property(MNL_CONFIG_T* prConfig) { int idx; int cnt = sizeof(mnl_prop_path)/sizeof(mnl_prop_path[0]); int res = 0; for (idx = 0; idx < cnt; idx++) { if (!read_prop(prConfig, mnl_prop_path[idx])) break; } //Add for reading property set by YGPS char result[6] = {0}; if(property_get(MNL_CONFIG_STATUS, result, NULL)){ prConfig->dbg2file = result[2] - '0'; MNL_MSG("dbg2file: %d\n", prConfig->dbg2file); prConfig->debug_nmea = result[3] - '0'; MNL_MSG("debug_nmea:%d \n", prConfig->debug_nmea); prConfig->BEE_enabled = result[4] - '0'; MNL_MSG("BEE_enabled: %d", prConfig->BEE_enabled); //prConfig->test_mode = result[5] - '0'; //MNL_MSG("test_mode: %d", prConfig->test_mode); }else{ MNL_ERR("Config is not set yet, ignore"); } MNL_MSG("========================================\n"); if (idx < cnt) /*successfully read property from file*/ { MNL_MSG("[setting] reading from %s\n", mnl_prop_path[idx]); res = 0; } else { MNL_MSG("[setting] load default value\n"); res = -1; } MNL_MSG("dev_dsp/dev_gps : %s %s\n", prConfig->dev_dsp, prConfig->dev_gps); MNL_MSG("init_speed/link_speed: %d %d\n", prConfig->init_speed, prConfig->link_speed); MNL_MSG("pmtk_conn/socket_port/dev_dbg : %d %d %s\n", prConfig->pmtk_conn, prConfig->socket_port, prConfig->dev_dbg); MNL_MSG("debug_nmea/debug_mnl: %d 0x%04X\n", prConfig->debug_nmea, prConfig->debug_mnl); MNL_MSG("nmea2file/dbg2file: %d/%d\n", prConfig->nmea2file, prConfig->dbg2file); MNL_MSG("time-out: %d %d %d %d %d %d\n", prConfig->timeout_init, prConfig->timeout_monitor, prConfig->timeout_wakeup, prConfig->timeout_ttff, prConfig->timeout_sleep, prConfig->timeout_pwroff); MNL_MSG("EPO_Enabled: %d\n", prConfig->EPO_enabled); MNL_MSG("BEE_Enabled: %d\n", prConfig->BEE_enabled); MNL_MSG("SUPL_Enabled: %d\n", prConfig->SUPL_enabled); MNL_MSG("SUPLSI_Enabled: %d\n", prConfig->SUPLSI_enabled); MNL_MSG("EPO_priority: %d\n", prConfig->EPO_priority); MNL_MSG("BEE_priority: %d\n", prConfig->BEE_priority); MNL_MSG("SUPL_priority: %d\n", prConfig->SUPL_priority); MNL_MSG("AVAILIABLE_AGE: %d", prConfig->AVAILIABLE_AGE); MNL_MSG("RTC_DRIFT: %d", prConfig->RTC_DRIFT); MNL_MSG("TIME_INTERVAL: %d", prConfig->TIME_INTERVAL); MNL_MSG("========================================\n"); return res; }
string ConfigElem::read_string( const char *propname ) const { string temp; if (read_prop( propname, &temp)) { return temp; } else { prop_not_found( propname ); return ""; // this is not reached, prop_not_found throws } }
int elf_ppc64_load(int argc, char **argv, const char *buf, off_t len, struct kexec_info *info) { struct mem_ehdr ehdr; char *cmdline, *modified_cmdline = NULL; const char *devicetreeblob; uint64_t max_addr, hole_addr; char *seg_buf = NULL; off_t seg_size = 0; struct mem_phdr *phdr; size_t size; #ifdef NEED_RESERVE_DTB uint64_t *rsvmap_ptr; struct bootblock *bb_ptr; #endif int result, opt; uint64_t my_kernel, my_dt_offset; uint64_t my_opal_base = 0, my_opal_entry = 0; unsigned int my_panic_kernel; uint64_t my_stack, my_backup_start; uint64_t toc_addr; uint32_t my_run_at_load; unsigned int slave_code[256/sizeof (unsigned int)], master_entry; /* See options.h -- add any more there, too. */ static const struct option options[] = { KEXEC_ARCH_OPTIONS { "command-line", 1, NULL, OPT_APPEND }, { "append", 1, NULL, OPT_APPEND }, { "ramdisk", 1, NULL, OPT_RAMDISK }, { "initrd", 1, NULL, OPT_RAMDISK }, { "devicetreeblob", 1, NULL, OPT_DEVICETREEBLOB }, { "dtb", 1, NULL, OPT_DEVICETREEBLOB }, { "args-linux", 0, NULL, OPT_ARGS_IGNORE }, { 0, 0, NULL, 0 }, }; static const char short_options[] = KEXEC_OPT_STR ""; if (info->file_mode) return elf_ppc64_load_file(argc, argv, info); /* Parse command line arguments */ initrd_base = 0; initrd_size = 0; cmdline = 0; ramdisk = 0; devicetreeblob = 0; max_addr = 0xFFFFFFFFFFFFFFFFULL; hole_addr = 0; while ((opt = getopt_long(argc, argv, short_options, options, 0)) != -1) { switch (opt) { default: /* Ignore core options */ if (opt < OPT_ARCH_MAX) break; case OPT_APPEND: cmdline = optarg; break; case OPT_RAMDISK: ramdisk = optarg; break; case OPT_DEVICETREEBLOB: devicetreeblob = optarg; break; case OPT_ARGS_IGNORE: break; } } if (!cmdline) fprintf(stdout, "Warning: append= option is not passed. Using the first kernel root partition\n"); if (ramdisk && reuse_initrd) die("Can't specify --ramdisk or --initrd with --reuseinitrd\n"); /* Need to append some command line parameters internally in case of * taking crash dumps. */ if (info->kexec_flags & KEXEC_ON_CRASH) { modified_cmdline = xmalloc(COMMAND_LINE_SIZE); memset((void *)modified_cmdline, 0, COMMAND_LINE_SIZE); if (cmdline) { strncpy(modified_cmdline, cmdline, COMMAND_LINE_SIZE); modified_cmdline[COMMAND_LINE_SIZE - 1] = '\0'; } } /* Parse the Elf file */ result = build_elf_exec_info(buf, len, &ehdr, 0); if (result < 0) { free_elf_info(&ehdr); return result; } /* Load the Elf data. Physical load addresses in elf64 header do not * show up correctly. Use user supplied address for now to patch the * elf header */ phdr = &ehdr.e_phdr[0]; size = phdr->p_filesz; if (size > phdr->p_memsz) size = phdr->p_memsz; my_kernel = hole_addr = locate_hole(info, size, 0, 0, max_addr, 1); ehdr.e_phdr[0].p_paddr = hole_addr; result = elf_exec_load(&ehdr, info); if (result < 0) { free_elf_info(&ehdr); return result; } /* If panic kernel is being loaded, additional segments need * to be created. */ if (info->kexec_flags & KEXEC_ON_CRASH) { result = load_crashdump_segments(info, modified_cmdline, max_addr, 0); if (result < 0) return -1; /* Use new command line. */ cmdline = modified_cmdline; } /* Add v2wrap to the current image */ elf_rel_build_load(info, &info->rhdr, purgatory, purgatory_size, 0, max_addr, 1, 0); /* Add a ram-disk to the current image * Note: Add the ramdisk after elf_rel_build_load */ if (ramdisk) { if (devicetreeblob) { fprintf(stderr, "Can't use ramdisk with device tree blob input\n"); return -1; } seg_buf = slurp_file(ramdisk, &seg_size); hole_addr = add_buffer(info, seg_buf, seg_size, seg_size, 0, 0, max_addr, 1); initrd_base = hole_addr; initrd_size = seg_size; } /* ramdisk */ if (devicetreeblob) { /* Grab device tree from buffer */ seg_buf = slurp_file(devicetreeblob, &seg_size); } else { /* create from fs2dt */ create_flatten_tree(&seg_buf, &seg_size, cmdline); } result = fixup_dt(&seg_buf, &seg_size); if (result < 0) return result; my_dt_offset = add_buffer(info, seg_buf, seg_size, seg_size, 0, 0, max_addr, -1); #ifdef NEED_RESERVE_DTB /* patch reserve map address for flattened device-tree * find last entry (both 0) in the reserve mem list. Assume DT * entry is before this one */ bb_ptr = (struct bootblock *)(seg_buf); rsvmap_ptr = (uint64_t *)(seg_buf + be32_to_cpu(bb_ptr->off_mem_rsvmap)); while (*rsvmap_ptr || *(rsvmap_ptr+1)) rsvmap_ptr += 2; rsvmap_ptr -= 2; *rsvmap_ptr = cpu_to_be64(my_dt_offset); rsvmap_ptr++; *rsvmap_ptr = cpu_to_be64((uint64_t)be32_to_cpu(bb_ptr->totalsize)); #endif if (read_prop("/proc/device-tree/ibm,opal/opal-base-address", &my_opal_base, sizeof(my_opal_base)) == 0) { my_opal_base = be64_to_cpu(my_opal_base); elf_rel_set_symbol(&info->rhdr, "opal_base", &my_opal_base, sizeof(my_opal_base)); } if (read_prop("/proc/device-tree/ibm,opal/opal-entry-address", &my_opal_entry, sizeof(my_opal_entry)) == 0) { my_opal_entry = be64_to_cpu(my_opal_entry); elf_rel_set_symbol(&info->rhdr, "opal_entry", &my_opal_entry, sizeof(my_opal_entry)); } /* Set kernel */ elf_rel_set_symbol(&info->rhdr, "kernel", &my_kernel, sizeof(my_kernel)); /* Set dt_offset */ elf_rel_set_symbol(&info->rhdr, "dt_offset", &my_dt_offset, sizeof(my_dt_offset)); /* get slave code from new kernel, put in purgatory */ elf_rel_get_symbol(&info->rhdr, "purgatory_start", slave_code, sizeof(slave_code)); master_entry = slave_code[0]; memcpy(slave_code, phdr->p_data, sizeof(slave_code)); slave_code[0] = master_entry; elf_rel_set_symbol(&info->rhdr, "purgatory_start", slave_code, sizeof(slave_code)); if (info->kexec_flags & KEXEC_ON_CRASH) { my_panic_kernel = 1; /* Set panic flag */ elf_rel_set_symbol(&info->rhdr, "panic_kernel", &my_panic_kernel, sizeof(my_panic_kernel)); /* Set backup address */ my_backup_start = info->backup_start; elf_rel_set_symbol(&info->rhdr, "backup_start", &my_backup_start, sizeof(my_backup_start)); /* Tell relocatable kernel to run at load address * via word before slave code in purgatory */ elf_rel_get_symbol(&info->rhdr, "run_at_load", &my_run_at_load, sizeof(my_run_at_load)); if (my_run_at_load == KERNEL_RUN_AT_ZERO_MAGIC) my_run_at_load = 1; /* else it should be a fixed offset image */ elf_rel_set_symbol(&info->rhdr, "run_at_load", &my_run_at_load, sizeof(my_run_at_load)); } /* Set stack address */ my_stack = locate_hole(info, 16*1024, 0, 0, max_addr, 1); my_stack += 16*1024; elf_rel_set_symbol(&info->rhdr, "stack", &my_stack, sizeof(my_stack)); /* Set toc */ toc_addr = my_r2(&info->rhdr); elf_rel_set_symbol(&info->rhdr, "my_toc", &toc_addr, sizeof(toc_addr)); /* Set debug */ elf_rel_set_symbol(&info->rhdr, "debug", &my_debug, sizeof(my_debug)); my_kernel = 0; my_dt_offset = 0; my_panic_kernel = 0; my_backup_start = 0; my_stack = 0; toc_addr = 0; my_run_at_load = 0; my_debug = 0; my_opal_base = 0; my_opal_entry = 0; elf_rel_get_symbol(&info->rhdr, "opal_base", &my_opal_base, sizeof(my_opal_base)); elf_rel_get_symbol(&info->rhdr, "opal_entry", &my_opal_entry, sizeof(my_opal_entry)); elf_rel_get_symbol(&info->rhdr, "kernel", &my_kernel, sizeof(my_kernel)); elf_rel_get_symbol(&info->rhdr, "dt_offset", &my_dt_offset, sizeof(my_dt_offset)); elf_rel_get_symbol(&info->rhdr, "run_at_load", &my_run_at_load, sizeof(my_run_at_load)); elf_rel_get_symbol(&info->rhdr, "panic_kernel", &my_panic_kernel, sizeof(my_panic_kernel)); elf_rel_get_symbol(&info->rhdr, "backup_start", &my_backup_start, sizeof(my_backup_start)); elf_rel_get_symbol(&info->rhdr, "stack", &my_stack, sizeof(my_stack)); elf_rel_get_symbol(&info->rhdr, "my_toc", &toc_addr, sizeof(toc_addr)); elf_rel_get_symbol(&info->rhdr, "debug", &my_debug, sizeof(my_debug)); dbgprintf("info->entry is %p\n", info->entry); dbgprintf("kernel is %llx\n", (unsigned long long)my_kernel); dbgprintf("dt_offset is %llx\n", (unsigned long long)my_dt_offset); dbgprintf("run_at_load flag is %x\n", my_run_at_load); dbgprintf("panic_kernel is %x\n", my_panic_kernel); dbgprintf("backup_start is %llx\n", (unsigned long long)my_backup_start); dbgprintf("stack is %llx\n", (unsigned long long)my_stack); dbgprintf("toc_addr is %llx\n", (unsigned long long)toc_addr); dbgprintf("purgatory size is %zu\n", purgatory_size); dbgprintf("debug is %d\n", my_debug); dbgprintf("opal_base is %llx\n", (unsigned long long) my_opal_base); dbgprintf("opal_entry is %llx\n", (unsigned long long) my_opal_entry); return 0; }
/** Open a CSV file and parse it as **/ int csv_reader::open(const char *file){ char line[1024]; char filename[128]; int has_cols = 0; int linenum = 0; int i = 0; OBJECT *obj = OBJECTHDR(this); weather *wtr = 0; if(file == 0){ gl_error("csv_reader has no input file name!"); /* TROUBLESHOOT No input file was specified for the csv_reader object. Double-check the input model and re-run GridLAB-D. */ return 0; } strncpy(filename, file, 127); infile = fopen(filename, "r"); if(infile == 0){ gl_error("csv_reader could not open \'%s\' for input!", file); /* TROUBLESHOOT The specified input file could not be opened for reading. Verify that no other applications are using that file, double-check the input model, and re-run GridLAB-D. */ return 0; } if(columns_str[0] != 0){ if(0 == read_header(columns_str)){ gl_error("csv_reader::open ~ column header read failure from explicit headers"); return 0; } else { has_cols = 1; } } while(fgets(line, 1024, infile) > 0){ ++linenum; // consume leading whitespace? // comments following valid lines? size_t _len = strlen(line); if(line[0] == '#'){ // comment continue; } else if(strlen(line) < 1){ continue; // blank line } else if(line[0] == '$'){ // property if(0 == read_prop(line+1)){ gl_error("csv_reader::open ~ property read failure on line %i", linenum); return 0; } else { continue; } } else if(has_cols == 0){ if(0 == read_header(line)){ gl_error("csv_reader::open ~ column header read failure on line %i", linenum); return 0; } else { has_cols = 1; } } else { if(0 == read_line(line)){ gl_error("csv_reader::open ~ data line read failure on line %i", linenum); return 0; } else { ++sample_ct; } } } /* move list into double pointer */ samples = (weather**)malloc(sizeof(weather *) * (size_t) sample_ct); for(i = 0, wtr = weather_root; i < sample_ct && wtr != NULL; ++i, wtr=wtr->next){ samples[i] = wtr; } sample_ct = i; // if wtr was the limiting factor, truncate the count // index = -1; // forces to start on zero-eth index // post-process // calculate object lat/long obj->latitude = lat_deg + (lat_deg > 0 ? lat_min : -lat_min) / 60; obj->longitude = long_deg + (long_deg > 0 ? long_min : -long_min / 60); return 1; }