void read_config(ConfigMatch *matches) { char *dcfg[] = { /* world settings */ "screenwidth = 640", /* px */ "screenheight = 480", "netheight = 150", "adtg = 1000", /* Acceleration Due To Gravity */ /* player */ "playerradius = 80", "playerspeed = 500", /* px/s */ "jumpvel = 400", "skywalk = false", /* ball */ "ballradius = 10", "elasticity = .8", /* Elasticity of collisions, 1=fully elastic, 0=lame */ /* display */ "font = crap/ter-132b.pcf.gz", "fontsize = 32", "colorfg = 0x80 0x80 0x80", "colorbg = 0xd0 0xd0 0xd0", /* misc */ "physhz = 200", /* updates/s */ "quitkey = 113", "dudes = 2", "porimg = crap/slime.png", /* 200x100px, with the point 100,90 being the base point */ "" }; bool verbose = false; if( verbose ) puts("\nLoading Default Config:"); char **l; for( l=dcfg; strcmp(*l,""); l++ ) { parse_config_line(matches, *l, verbose); } verbose = true; char configpath[] = "./config"; if( verbose ) printf("\nLoading Config File '%s':\n", configpath); FILE *config = fopen(configpath, "r"); if( config ) { char line[BUFSIZ]; while( fgets(line, sizeof(line), config) ) { parse_config_line(matches, line, verbose); } fclose(config); if( verbose ) puts("end of config\n"); } else if( verbose ) puts(":< config file not found ;-;\n"); }
static int do_list(u_info *user_info) { FILE *fp; u_info tmp_u_info ; char line[MAX_LINE]; if (user_info->fconf == NULL) { fprintf(stderr, "missing file to list accounts\n"); return -1; } if ((fp = fopen(user_info->fconf, "r")) == NULL) { perror("error to open the configuration file ... "); return -1; } while (fgets(line, (int) sizeof line - 1U, fp) != NULL) { strip_lf(line); if (*line == 0 || *line == '#') { continue; } if (parse_config_line(line, &tmp_u_info) != 0) { fprintf(stderr, "Warning: invalid line [%s]\n", line); continue; } if (isatty(1)) { printf("%-19s %-39s \n", tmp_u_info.login, tmp_u_info.home); } else { printf("%s\t%s\n", tmp_u_info.login, tmp_u_info.home); } } fclose(fp); return 0; }
/* * parse a config file * return a list of rules */ rule *parse_config_file(char *filename) { FILE *file; char line[LINE_LENGTH+1]; rule *start_rule = NULL, *rule1 = NULL, *rule2 = NULL; file = fopen(filename,"r"); if (!file) { LM_INFO("file not found: %s\n", filename); return NULL; } while (fgets(line, LINE_LENGTH, file)) { rule2 = parse_config_line(line); if (rule2) { if (rule1) { /* it is not the first rule */ rule1->next = rule2; } else { /* it is the first rule */ start_rule = rule2; } rule1 = rule2; } } fclose(file); return start_rule; /* returns the linked list */ }
/* * Parse the configuration file with the given file pointer into the * configuration object. * * Return 0 on success or else a negative value. */ static int parse_config_file(FILE *fp, struct configuration *config) { int ret = -1; /* Usually, this value is 8192 on most Unix systems. */ char line[BUFSIZ]; assert(fp); assert(config); while (fgets(line, sizeof(line), fp) != NULL) { /* * Remove the \n at the end of the buffer and replace it by a NULL * bytes so we handle the line without this useless char. */ if (strlen(line) > 0) { line[strlen(line) - 1] = '\0'; } ret = parse_config_line(line, config); if (ret < 0) { goto error; } } error: return ret; }
int read_config(char *confname) { int fd, len, remain, ret; char *filename = confname; char *data, *line, *newline; if (!filename) filename = DEFAULT_CONFIG_FILE; fd = open(filename, O_RDONLY); if (fd == -1) { if (!confname) { fprintf(stderr, "Warning: Could not open %s. %s. Default settings will be used.\n", filename, strerror(errno)); return TRUE; /* nonexistent default config need not be an error */ } fprintf(stderr, "Error: Could not open %s. %s\n", filename, strerror(errno)); return FALSE; /* non-existent custom config file is always an error */ } /* read the entire file into memory carefully */ len = lseek(fd, 0, SEEK_END); lseek(fd, 0, SEEK_SET); data = malloc(len + 1); remain = len; while (remain) { ret = read(fd, data, remain); if (ret <= 0) { /* some error */ free(data); close(fd); return FALSE; } remain -= ret; } close (fd); data[len] = '\0'; /* break up the file data into lines using the '\n' char. */ line = data; while ( (newline = strchr(line, '\n')) ) { *newline++ = '\0'; if (!parse_config_line(line)) { free(data); return FALSE; } line = newline; } /* check for trailing junk */ line = trim(line); if (strlen(line)) fprintf(stderr, "Warning: trailing junk (\"%s\") after last config line ignored.\n", line); free(data); return TRUE; }
/** non-realtime function to read config, * called from state-restore or worker-thread */ static void parse_config_file (MidiMap* self, const char* fn) { assert (self->state == NULL); FILE *f; if (!fn) { lv2_log_error (&self->logger, "MidiMap.lv2: invalid config file handle\n"); } if (!(f = fopen (fn, "r"))) { lv2_log_error (&self->logger, "MidiMap.lv2: cannot open config file '%s'\n", fn); return; } lv2_log_note (&self->logger, "MidiMap.lv2: parsing config file '%s'\n", fn); self->state = calloc (1, sizeof (RuleSet)); char line[MAX_CFG_LINE_LEN]; unsigned int lineno = 0; unsigned int cfg_version = 0; while (fgets (line, MAX_CFG_LINE_LEN - 1, f) != NULL ) { ++lineno; if (strlen (line) == MAX_CFG_LINE_LEN - 1) { lv2_log_error (&self->logger, "MidiMap.lv2: Too long config line %d\n", lineno); continue; } // strip trailing whitespace while (strlen (line) > 0 && (line[strlen (line) - 1] == '\n' || line[strlen (line) - 1] == '\r' || line[strlen (line) - 1] == ' ' || line[strlen (line) - 1] == '\t')) { line[strlen (line) - 1] = '\0'; } // ignore comments and empty lines if (strlen (line) == 0 || line[0] == '#') { continue; } parse_config_line (self, line, &cfg_version, lineno); } fclose (f); if (cfg_version > 0) { /* remember config file - for state */ free (self->cfg_file_path); self->cfg_file_path = strdup (fn); #ifndef NDEBUG char* dump = serialize_ruleset (self->state); printf ("----\n%s\n----\n", dump); free (dump); #endif } else { lv2_log_error (&self->logger, "MidiMap.lv2: error parsing config file\n"); free (self->state); self->state = NULL; } }
void load_config(const char *filename) { FILE *fp; int ch, i; char line[1024]; fp = fopen(filename, "r"); if (! fp) return; memset(line, 0, sizeof(line)); i = 0; ch = fgetc(fp); while (1) { switch (ch) { case '#': while (ch != '\n' && ch != -1) ch = fgetc(fp); break; case -1: parse_config_line(line); fclose(fp); return; case '\r': ch = fgetc(fp); break; case '\n': parse_config_line(line); memset(line, 0, sizeof(line)); i = 0; ch = fgetc(fp); break; default: if (i < sizeof(line) - 1) line[i++] = ch; ch = fgetc(fp); break; } } }
static void process_line(char *line) { struct entry *entry; char *key = NULL, *value = NULL; entry = add_entry(); strlcpy(entry->line, line, sizeof(entry->line)); parse_config_line(line, &key, &value); if (!key || !value) return; strlcpy(entry->key, key, sizeof(entry->key)); strlcpy(entry->value, value, sizeof(entry->value)); }
/* * load_config_file: loads from `file' all the options that are written in it * and stores them in the environment. See parse_config_line() above. * If `file' cannot be opened -1 is returned, but if it is read and * parse_config_line() detects a corrupted line, fatal() is directly called. * On success 0 is returned. */ int load_config_file(char *file) { FILE *fd; char buf[PATH_MAX+1], *p, *str; size_t slen; int i=0, e=0; if(!(fd=fopen(file, "r"))) { fatal("Cannot load the configuration file from %s: %s\n" " Maybe you want to use the -c option ?", file, strerror(errno)); return -1; } while(!feof(fd) && i < CONF_MAX_LINES) { setzero(buf, PATH_MAX+1); fgets(buf, PATH_MAX, fd); e++; if(feof(fd)) break; str=buf; while(isspace(*str)) str++; if(*str=='#' || !*str) { /* Strip off any comment or null lines */ continue; } else { /* Remove the last part of the string where a side * comment starts, #a comment like this. */ if((p=strrchr(str, '#'))) *p='\0'; /* Don't include the newline and spaces of the end of * the string */ slen=strlen(str); for(p=&str[slen-1]; isspace(*p); p--) *p='\0'; parse_config_line(file, e, str); i++; } } fclose(fd); return 0; }
/* Parse a configuration file and put the results in the configuration tree starting at *base. */ bool read_config_file(avl_tree_t *config_tree, const char *fname) { FILE *fp; char buffer[MAX_STRING_SIZE]; char *line; int lineno = 0; bool ignore = false; config_t *cfg; bool result = false; fp = fopen(fname, "r"); if(!fp) { logger(LOG_ERR, "Cannot open config file %s: %s", fname, strerror(errno)); return false; } for(;;) { line = readline(fp, buffer, sizeof buffer); if(!line) { if(feof(fp)) result = true; break; } lineno++; if(!*line || *line == '#') continue; if(ignore) { if(!strncmp(line, "-----END", 8)) ignore = false; continue; } if(!strncmp(line, "-----BEGIN", 10)) { ignore = true; continue; } cfg = parse_config_line(line, fname, lineno); if (!cfg) break; config_add(config_tree, cfg); } fclose(fp); return result; }
// This is a very simple config file parser that extracts // commandline arguments from the specified file. static int load_config(const char *filename, char **argv, int max_args) { FILE *fp = fopen(filename, "r"); if (!fp) return 0; int argc = 0; char line[128]; while (fgets(line, sizeof(line), fp) && argc < max_args) { int new_args = parse_config_line(line, argv, max_args - argc); argc += new_args; argv += new_args; } fclose(fp); return argc; }
static void do_mixer_settings(FILE *file) { struct mixer *mixer; char buf[256], *name, *value; mixer = mixer_open(0); if(!mixer) { log_info("cannot open mixer"); return; } log_info("processing mixer settings from %s", alsa_config_file); while(fgets(buf, sizeof(buf),file)) { if(parse_config_line(buf, &name, &value)) { log_info("%s -> %s", name, value); tinymix_set_value(mixer, name, value); } } mixer_close(mixer); log_info("mixer settings processed"); }
static void do_mixer_settings(FILE *file) { char buf[256], cmd[256], *name, *value; int i, pp[2], pid; char *argv[] = {ALSA_MIX_CMD, "-s", "-q", 0}; log_info("processing mixer settings from %s", alsa_config_file); pipe(pp); signal(SIGPIPE, SIG_IGN); signal(SIGCHLD, SIG_IGN); pid = fork(); if(pid < 0) { log_err("fork failed"); return; } if(pid == 0) { dup2(pp[0],0); close(pp[1]); close(pp[0]); execv(ALSA_MIX_CMD, argv); return; /* mustn't be reached */ } close(pp[0]); while(fgets(buf, sizeof(buf),file)) { if(parse_config_line(buf, &name, &value)) { log_info("%s -> %s", name, value); sprintf(cmd, "cset name=\"%s\" \"%s\"\n", name, value); i = strlen(cmd); if(write(pp[1], cmd, i) != i) { log_err("write error\n"); break; } } } close(pp[1]); waitpid(pid,0,0); signal(SIGPIPE, SIG_DFL); signal(SIGCHLD, SIG_DFL); log_info("mixer settings processed"); }
static void process_line(char *line) { char *option, *value; if (!parse_config_line(line, &option, &value)) return; if (!strcmp(option, "TINT2_BUTTON_ALIGNED_X1")) setenv("TINT2_BUTTON_ALIGNED_X1", value, 1); else if (!strcmp(option, "TINT2_BUTTON_ALIGNED_X2")) setenv("TINT2_BUTTON_ALIGNED_X2", value, 1); else if (!strcmp(option, "TINT2_BUTTON_ALIGNED_Y1")) setenv("TINT2_BUTTON_ALIGNED_Y1", value, 1); else if (!strcmp(option, "TINT2_BUTTON_ALIGNED_Y2")) setenv("TINT2_BUTTON_ALIGNED_Y2", value, 1); else if (!strcmp(option, "TINT2_BUTTON_PANEL_X1")) setenv("TINT2_BUTTON_PANEL_X1", value, 1); else if (!strcmp(option, "TINT2_BUTTON_PANEL_X2")) setenv("TINT2_BUTTON_PANEL_X2", value, 1); else if (!strcmp(option, "TINT2_BUTTON_PANEL_Y1")) setenv("TINT2_BUTTON_PANEL_Y1", value, 1); else if (!strcmp(option, "TINT2_BUTTON_PANEL_Y2")) setenv("TINT2_BUTTON_PANEL_Y2", value, 1); }
/* * parse a config file * return a list of rules */ rule *parse_config_file(char *filename, int *err) { FILE *file; char line[LINE_LENGTH+1]; rule *start_rule = NULL, *rule1 = NULL, *rule2 = NULL; *err = 0; file = fopen(filename,"r"); if (!file) { if (safe_file_load) { LOG(L_ERR, "ERROR: File not found: %s\n", filename); *err = 1; } else { LOG(L_WARN, "WARNING: File not found: %s\n", filename); } return NULL; } while (fgets(line, LINE_LENGTH, file)) { rule2 = parse_config_line(line, err); if (*err) goto error; if (rule2) { if (rule1) { /* it is not the first rule */ rule1->next = rule2; } else { /* it is the first rule */ start_rule = rule2; } rule1 = rule2; } } error: fclose(file); return start_rule; /* returns the linked list */ }
bool Config::parse_config(const String& config) { for(size_t i=0; i<config.length(); ++i) { char ch = config[i]; if(isspace(ch)) { continue; } String current_line; while('\r' != ch && '\n' != ch) { current_line += ch; if(++i >= config.length()) { break; } ch = config[i]; } current_line.trim(); if(!parse_config_line(current_line)) { return false; } } return true; }
void read_config(lstate *state) { int lineno = 1; FILE *fp; char *buf = my_malloc(256); if(!(fp = fopen(state->config_file, "r"))) { GrError("Couldn't open config file \"%s\"\n", state->config_file); exit(2); } state->litems = NULL; state->numlitems = 0; state->ssitems = NULL; state->randomss = 0; state->numssitems = 0; state->stitems = NULL; state->rotatess = 0; while(fgets(buf, 256, fp)) { parse_config_line(state, buf, lineno); lineno++; } fclose(fp); free(buf); if(state->randomss) choose_random_screensaver(state); else state->curssitem = state->ssitems; if(!state->numlitems) { GrError("No valid launcher items in config file\n"); exit(5); } }
static bool parse_options(int argc, char **argv) { config_t *cfg; int r; int option_index = 0; int lineno = 0; cmdline_conf = list_alloc((list_action_t)free_config); while((r = getopt_long(argc, argv, "c:DLd::k::n:o:K::RU:", long_options, &option_index)) != EOF) { switch (r) { case 0: /* long option */ break; case 'c': /* config file */ confbase = xstrdup(optarg); break; case 'D': /* no detach */ do_detach = false; break; case 'L': /* no detach */ #ifndef HAVE_MLOCKALL logger(LOG_ERR, "%s not supported on this platform", "mlockall()"); return false; #else do_mlock = true; break; #endif case 'd': /* inc debug level */ if(optarg) debug_level = atoi(optarg); else debug_level++; break; case 'k': /* kill old tincds */ #ifndef HAVE_MINGW if(optarg) { if(!strcasecmp(optarg, "HUP")) kill_tincd = SIGHUP; else if(!strcasecmp(optarg, "TERM")) kill_tincd = SIGTERM; else if(!strcasecmp(optarg, "KILL")) kill_tincd = SIGKILL; else if(!strcasecmp(optarg, "USR1")) kill_tincd = SIGUSR1; else if(!strcasecmp(optarg, "USR2")) kill_tincd = SIGUSR2; else if(!strcasecmp(optarg, "WINCH")) kill_tincd = SIGWINCH; else if(!strcasecmp(optarg, "INT")) kill_tincd = SIGINT; else if(!strcasecmp(optarg, "ALRM")) kill_tincd = SIGALRM; else { kill_tincd = atoi(optarg); if(!kill_tincd) { fprintf(stderr, "Invalid argument `%s'; SIGNAL must be a number or one of HUP, TERM, KILL, USR1, USR2, WINCH, INT or ALRM.\n", optarg); usage(true); return false; } } } else kill_tincd = SIGTERM; #else kill_tincd = 1; #endif break; case 'n': /* net name given */ /* netname "." is special: a "top-level name" */ netname = strcmp(optarg, ".") != 0 ? xstrdup(optarg) : NULL; break; case 'o': /* option */ cfg = parse_config_line(optarg, NULL, ++lineno); if (!cfg) return false; list_insert_tail(cmdline_conf, cfg); break; case 'K': /* generate public/private keypair */ if(optarg) { generate_keys = atoi(optarg); if(generate_keys < 512) { fprintf(stderr, "Invalid argument `%s'; BITS must be a number equal to or greater than 512.\n", optarg); usage(true); return false; } generate_keys &= ~7; /* Round it to bytes */ } else generate_keys = 2048; break; case 'R': /* chroot to NETNAME dir */ do_chroot = true; break; case 'U': /* setuid to USER */ switchuser = optarg; break; case 1: /* show help */ show_help = true; break; case 2: /* show version */ show_version = true; break; case 3: /* bypass security */ bypass_security = true; break; case 4: /* write log entries to a file */ use_logfile = true; if(optarg) logfilename = xstrdup(optarg); break; case 5: /* write PID to a file */ pidfilename = xstrdup(optarg); break; case '?': usage(true); return false; default: break; } } return true; }
/** * @brief * pbs_loadconf - Populate the pbs_conf structure * * @par * Load the pbs_conf structure. The variables can be filled in * from either the environment or the pbs.conf file. The * environment gets priority over the file. If any of the * primary variables are not filled in, the function fails. * Primary vars: pbs_home_path, pbs_exec_path, pbs_server_name * * @note * Clients can now be multithreaded. So dont call pbs_loadconf with * reload = TRUE. Currently, the code flow ensures that the configuration * is loaded only once (never used with reload true). Thus in the rest of * the code a direct read of the pbs_conf.variables is fine. There is no * race of access of pbs_conf vars against the loading of pbs_conf vars. * However, if pbs_loadconf is called with reload = TRUE, this assumption * will be void. In that case, access to every pbs_conf.variable has to be * synchronized against the reload of those variables. * * @param[in] reload Whether to attempt a reload * * @return int * @retval 1 Success * @retval 0 Failure */ int pbs_loadconf(int reload) { FILE *fp; char buf[256]; char *conf_name; /* the name of the conf parameter */ char *conf_value; /* the value from the conf file or env*/ char *gvalue; /* used with getenv() */ unsigned int uvalue; /* used with sscanf() */ #ifndef WIN32 struct servent *servent; /* for use with getservent */ char **servalias; /* service alias list */ unsigned int *pui; /* for use with identify_service_entry */ #endif /* initialize the thread context data, if not already initialized */ if (pbs_client_thread_init_thread_context() != 0) return 0; /* this section of the code modified the procecss-wide * tcp array. Since multiple threads can get into this * simultaneously, we need to serialize it */ if (pbs_client_thread_lock_conf() != 0) return 0; if (pbs_conf.loaded && !reload) { (void)pbs_client_thread_unlock_conf(); return 1; } else if (pbs_conf.load_failed && !reload) { (void)pbs_client_thread_unlock_conf(); return 0; } /* * If there are service port definitions available, use them * as the defaults. They may be overridden later by the config * file or environment variables. If not available, retain * whatever we were using before. */ #ifdef WIN32 /* Windows does not have the getservent() call. */ pbs_conf.batch_service_port = get_svrport( PBS_BATCH_SERVICE_NAME, "tcp", pbs_conf.batch_service_port); pbs_conf.batch_service_port_dis = get_svrport( PBS_BATCH_SERVICE_NAME_DIS, "tcp", pbs_conf.batch_service_port_dis); pbs_conf.mom_service_port = get_svrport( PBS_MOM_SERVICE_NAME, "tcp", pbs_conf.mom_service_port); pbs_conf.manager_service_port = get_svrport( PBS_MANAGER_SERVICE_NAME, "tcp", pbs_conf.manager_service_port); pbs_conf.scheduler_service_port = get_svrport( PBS_SCHEDULER_SERVICE_NAME, "tcp", pbs_conf.scheduler_service_port); pbs_conf.pbs_data_service_port = get_svrport( PBS_DATA_SERVICE_NAME, "tcp", pbs_conf.pbs_data_service_port); #else /* Non-Windows uses getservent() for better performance. */ while ((servent = getservent()) != NULL) { if (strcmp(servent->s_proto, "tcp") != 0) continue; /* First, check the official service name. */ pui = identify_service_entry(servent->s_name); if (pui != NULL) { *pui = (unsigned int)ntohs(servent->s_port); continue; } /* Next, check any aliases that may be defined. */ for (servalias = servent->s_aliases; (servalias != NULL) && (*servalias != NULL); servalias++) { pui = identify_service_entry(*servalias); if (pui != NULL) { *pui = (unsigned int)ntohs(servent->s_port); break; } } } endservent(); #endif /* * Once we determine the location of the pbs.conf file, it never changes. * The fact that it is saved to the pbs_conf global structure means that * we can always see its location when debugging. */ if (pbs_conf.pbs_conf_file == NULL) pbs_conf.pbs_conf_file = pbs_get_conf_file(); /* * Parse through the configuration file and set variables based * on the contents of the file. */ if ((fp = fopen(pbs_conf.pbs_conf_file, "r")) != NULL) { while (parse_config_line(fp, &conf_name, &conf_value) != NULL) { if ((conf_name == NULL) || (*conf_name == '\0')) continue; if (!strcmp(conf_name, PBS_CONF_START_SERVER)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.start_server = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_START_MOM)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.start_mom = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_START_SCHED)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.start_sched = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_START_COMM)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.start_comm = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_LOCALLOG)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.locallog = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_SYSLOG)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.syslogfac = ((uvalue <= (23<<3)) ? uvalue : 0); } else if (!strcmp(conf_name, PBS_CONF_SYSLOGSEVR)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.syslogsvr = ((uvalue <= 7) ? uvalue : 0); } else if (!strcmp(conf_name, PBS_CONF_BATCH_SERVICE_PORT)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.batch_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port); } else if (!strcmp(conf_name, PBS_CONF_BATCH_SERVICE_PORT_DIS)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.batch_service_port_dis = ((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port_dis); } else if (!strcmp(conf_name, PBS_CONF_MOM_SERVICE_PORT)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.mom_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.mom_service_port); } else if (!strcmp(conf_name, PBS_CONF_MANAGER_SERVICE_PORT)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.manager_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.manager_service_port); } else if (!strcmp(conf_name, PBS_CONF_SCHEDULER_SERVICE_PORT)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.scheduler_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.scheduler_service_port); } else if (!strcmp(conf_name, PBS_CONF_DATA_SERVICE_PORT)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.pbs_data_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.pbs_data_service_port); } else if (!strcmp(conf_name, PBS_CONF_DATA_SERVICE_HOST)) { free(pbs_conf.pbs_data_service_host); pbs_conf.pbs_data_service_host = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_USE_TCP)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.pbs_use_tcp = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_USE_COMPRESSION)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.pbs_use_compression = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_USE_MCAST)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.pbs_use_mcast = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_FORCE_FT_COMM)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.pbs_use_ft = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_LEAF_NAME)) { if (pbs_conf.pbs_leaf_name) free(pbs_conf.pbs_leaf_name); pbs_conf.pbs_leaf_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_LEAF_ROUTERS)) { if (pbs_conf.pbs_leaf_routers) free(pbs_conf.pbs_leaf_routers); pbs_conf.pbs_leaf_routers = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_COMM_NAME)) { if (pbs_conf.pbs_comm_name) free(pbs_conf.pbs_comm_name); pbs_conf.pbs_comm_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_COMM_ROUTERS)) { if (pbs_conf.pbs_comm_routers) free(pbs_conf.pbs_comm_routers); pbs_conf.pbs_comm_routers = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_COMM_THREADS)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.pbs_comm_threads = uvalue; } else if (!strcmp(conf_name, PBS_CONF_COMM_LOG_EVENTS)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.pbs_comm_log_events = uvalue; } else if (!strcmp(conf_name, PBS_CONF_HOME)) { free(pbs_conf.pbs_home_path); pbs_conf.pbs_home_path = shorten_and_cleanup_path(conf_value); } else if (!strcmp(conf_name, PBS_CONF_EXEC)) { free(pbs_conf.pbs_exec_path); pbs_conf.pbs_exec_path = shorten_and_cleanup_path(conf_value); } /* Check for PBS_DEFAULT for backward compatibility */ else if (!strcmp(conf_name, PBS_CONF_DEFAULT_NAME)) { free(pbs_conf.pbs_server_name); pbs_conf.pbs_server_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_SERVER_NAME)) { free(pbs_conf.pbs_server_name); pbs_conf.pbs_server_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_RCP)) { free(pbs_conf.rcp_path); pbs_conf.rcp_path = shorten_and_cleanup_path(conf_value); } else if (!strcmp(conf_name, PBS_CONF_SCP)) { free(pbs_conf.scp_path); pbs_conf.scp_path = shorten_and_cleanup_path(conf_value); } else if (!strcmp(conf_name, PBS_CONF_K5DCELOGIN)) { free(pbs_conf.k5dcelogin_path); pbs_conf.k5dcelogin_path = shorten_and_cleanup_path(conf_value); } /* rcp_path can be inferred from pbs_conf.pbs_exec_path - see below */ /* pbs_demux_path is inferred from pbs_conf.pbs_exec_path - see below */ else if (!strcmp(conf_name, PBS_CONF_ENVIRONMENT)) { free(pbs_conf.pbs_environment); pbs_conf.pbs_environment = shorten_and_cleanup_path(conf_value); } else if (!strcmp(conf_name, PBS_CONF_PRIMARY)) { free(pbs_conf.pbs_primary); pbs_conf.pbs_primary = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_SECONDARY)) { free(pbs_conf.pbs_secondary); pbs_conf.pbs_secondary = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_MOM_HOME)) { free(pbs_conf.pbs_mom_home); pbs_conf.pbs_mom_home = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_CORE_LIMIT)) { free(pbs_conf.pbs_core_limit); pbs_conf.pbs_core_limit = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_LICENSE_STRING)) { free(pbs_conf.pbs_license_file_location); pbs_conf.pbs_license_file_location = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_SERVER_HOST_NAME)) { free(pbs_conf.pbs_server_host_name); pbs_conf.pbs_server_host_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_PUBLIC_HOST_NAME)) { free(pbs_conf.pbs_public_host_name); pbs_conf.pbs_public_host_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_MAIL_HOST_NAME)) { free(pbs_conf.pbs_mail_host_name); pbs_conf.pbs_mail_host_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_SMTP_SERVER_NAME)) { free(pbs_conf.pbs_smtp_server_name); pbs_conf.pbs_smtp_server_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_OUTPUT_HOST_NAME)) { free(pbs_conf.pbs_output_host_name); pbs_conf.pbs_output_host_name = strdup(conf_value); } else if (!strcmp(conf_name, PBS_CONF_SCHEDULER_MODIFY_EVENT)) { if (sscanf(conf_value, "%u", &uvalue) == 1) pbs_conf.sched_modify_event = ((uvalue > 0) ? 1 : 0); } else if (!strcmp(conf_name, PBS_CONF_MOM_NODE_NAME)) { free(pbs_conf.pbs_mom_node_name); pbs_conf.pbs_mom_node_name = strdup(conf_value); } #ifdef WIN32 else if (!strcmp(conf_name, PBS_CONF_REMOTE_VIEWER)) { free(pbs_conf.pbs_conf_remote_viewer); pbs_conf.pbs_conf_remote_viewer = strdup(conf_value); } #endif #ifndef WIN32 else if (!strcmp(conf_name, PBS_CONF_AUTH)) { if (!strcasecmp(conf_value, "MUNGE")) { pbs_conf.auth_method = AUTH_MUNGE; } else { fprintf(stderr, "pbsconf error: illegal value for %s\n",PBS_CONF_AUTH); goto err; } } #endif /* iff_path is inferred from pbs_conf.pbs_exec_path - see below */ } fclose(fp); free(pbs_loadconf_buf); pbs_loadconf_buf = NULL; pbs_loadconf_len = 0; } /* * Next, check the environment variables and set values accordingly * overriding those that were set in the configuration file. */ if ((gvalue = getenv(PBS_CONF_START_SERVER)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.start_server = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_START_MOM)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.start_mom = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_START_SCHED)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.start_sched = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_START_COMM)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.start_comm = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_LOCALLOG)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.locallog = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_SYSLOG)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.syslogfac = ((uvalue <= (23<<3)) ? uvalue : 0); } if ((gvalue = getenv(PBS_CONF_SYSLOGSEVR)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.syslogsvr = ((uvalue <= 7) ? uvalue : 0); } if ((gvalue = getenv(PBS_CONF_BATCH_SERVICE_PORT)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.batch_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port); } if ((gvalue = getenv(PBS_CONF_BATCH_SERVICE_PORT_DIS)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.batch_service_port_dis = ((uvalue <= 65535) ? uvalue : pbs_conf.batch_service_port_dis); } if ((gvalue = getenv(PBS_CONF_MOM_SERVICE_PORT)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.mom_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.mom_service_port); } if ((gvalue = getenv(PBS_CONF_MANAGER_SERVICE_PORT)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.manager_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.manager_service_port); } if ((gvalue = getenv(PBS_CONF_SCHEDULER_SERVICE_PORT)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.scheduler_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.scheduler_service_port); } if ((gvalue = getenv(PBS_CONF_HOME)) != NULL) { free(pbs_conf.pbs_home_path); pbs_conf.pbs_home_path = shorten_and_cleanup_path(gvalue); } if ((gvalue = getenv(PBS_CONF_EXEC)) != NULL) { free(pbs_conf.pbs_exec_path); pbs_conf.pbs_exec_path = shorten_and_cleanup_path(gvalue); } /* Check for PBS_DEFAULT for backward compatibility */ if ((gvalue = getenv(PBS_CONF_DEFAULT_NAME)) != NULL) { free(pbs_conf.pbs_server_name); if ((pbs_conf.pbs_server_name = strdup(gvalue)) == NULL) { goto err; } } if ((gvalue = getenv(PBS_CONF_SERVER_NAME)) != NULL) { free(pbs_conf.pbs_server_name); if ((pbs_conf.pbs_server_name = strdup(gvalue)) == NULL) { goto err; } } if ((gvalue = getenv(PBS_CONF_RCP)) != NULL) { free(pbs_conf.rcp_path); pbs_conf.rcp_path = shorten_and_cleanup_path(gvalue); } if ((gvalue = getenv(PBS_CONF_SCP)) != NULL) { free(pbs_conf.scp_path); pbs_conf.scp_path = shorten_and_cleanup_path(gvalue); } if ((gvalue = getenv(PBS_CONF_K5DCELOGIN)) != NULL) { free(pbs_conf.k5dcelogin_path); pbs_conf.k5dcelogin_path = shorten_and_cleanup_path(gvalue); } if ((gvalue = getenv(PBS_CONF_PRIMARY)) != NULL) { free(pbs_conf.pbs_primary); if ((pbs_conf.pbs_primary = strdup(gvalue)) == NULL) { goto err; } } if ((gvalue = getenv(PBS_CONF_SECONDARY)) != NULL) { free(pbs_conf.pbs_secondary); if ((pbs_conf.pbs_secondary = strdup(gvalue)) == NULL) { goto err; } } if ((gvalue = getenv(PBS_CONF_MOM_HOME)) != NULL) { free(pbs_conf.pbs_mom_home); if ((pbs_conf.pbs_mom_home = strdup(gvalue)) == NULL) { goto err; } } if ((gvalue = getenv(PBS_CONF_CORE_LIMIT)) != NULL) { free(pbs_conf.pbs_core_limit); if ((pbs_conf.pbs_core_limit = strdup(gvalue)) == NULL) { goto err; } } if ((gvalue = getenv(PBS_CONF_DATA_SERVICE_HOST)) != NULL) { free(pbs_conf.pbs_data_service_host); if ((pbs_conf.pbs_data_service_host = strdup(gvalue)) == NULL) { goto err; } } if ((gvalue = getenv(PBS_CONF_USE_TCP)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.pbs_use_tcp = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_USE_COMPRESSION)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.pbs_use_compression = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_USE_MCAST)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.pbs_use_mcast = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_FORCE_FT_COMM)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.pbs_use_ft = ((uvalue > 0) ? 1 : 0); } if ((gvalue = getenv(PBS_CONF_LEAF_NAME)) != NULL) { if (pbs_conf.pbs_leaf_name) free(pbs_conf.pbs_leaf_name); pbs_conf.pbs_leaf_name = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_LEAF_ROUTERS)) != NULL) { if (pbs_conf.pbs_leaf_routers) free(pbs_conf.pbs_leaf_routers); pbs_conf.pbs_leaf_routers = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_COMM_NAME)) != NULL) { if (pbs_conf.pbs_comm_name) free(pbs_conf.pbs_comm_name); pbs_conf.pbs_comm_name = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_COMM_ROUTERS)) != NULL) { if (pbs_conf.pbs_comm_routers) free(pbs_conf.pbs_comm_routers); pbs_conf.pbs_comm_routers = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_COMM_THREADS)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.pbs_comm_threads = uvalue; } if ((gvalue = getenv(PBS_CONF_COMM_LOG_EVENTS)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.pbs_comm_log_events = uvalue; } if ((gvalue = getenv(PBS_CONF_DATA_SERVICE_PORT)) != NULL) { if (sscanf(gvalue, "%u", &uvalue) == 1) pbs_conf.pbs_data_service_port = ((uvalue <= 65535) ? uvalue : pbs_conf.pbs_data_service_port); } if ((gvalue = getenv(PBS_CONF_SERVER_HOST_NAME)) != NULL) { free(pbs_conf.pbs_server_host_name); pbs_conf.pbs_server_host_name = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_PUBLIC_HOST_NAME)) != NULL) { free(pbs_conf.pbs_public_host_name); pbs_conf.pbs_public_host_name = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_MAIL_HOST_NAME)) != NULL) { free(pbs_conf.pbs_mail_host_name); pbs_conf.pbs_mail_host_name = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_SMTP_SERVER_NAME)) != NULL) { free(pbs_conf.pbs_smtp_server_name); pbs_conf.pbs_smtp_server_name = strdup(gvalue); } if ((gvalue = getenv(PBS_CONF_OUTPUT_HOST_NAME)) != NULL) { free(pbs_conf.pbs_output_host_name); pbs_conf.pbs_output_host_name = strdup(gvalue); } /* support PBS_MOM_NODE_NAME to tell MOM natural node name on server */ if ((gvalue = getenv(PBS_CONF_MOM_NODE_NAME)) != NULL) { free(pbs_conf.pbs_mom_node_name); pbs_conf.pbs_mom_node_name = strdup(gvalue); } /* rcp_path is inferred from pbs_conf.pbs_exec_path - see below */ /* pbs_demux_path is inferred from pbs_conf.pbs_exec_path - see below */ if ((gvalue = getenv(PBS_CONF_ENVIRONMENT)) != NULL) { free(pbs_conf.pbs_environment); pbs_conf.pbs_environment = shorten_and_cleanup_path(gvalue); } #ifdef WIN32 if ((gvalue = getenv(PBS_CONF_REMOTE_VIEWER)) != NULL) { free(pbs_conf.pbs_conf_remote_viewer); pbs_conf.pbs_conf_remote_viewer = strdup(gvalue); } #endif /* iff_path is inferred from pbs_conf.pbs_exec_path - see below */ /* * Now that we have parsed through the configuration file and the * environment variables, check to make sure that all the critical * items are set. */ buf[0] = '\0'; if (pbs_conf.pbs_home_path == NULL) sprintf(buf, "%s %s", buf, PBS_CONF_HOME); if (pbs_conf.pbs_exec_path == NULL) sprintf(buf, "%s %s", buf, PBS_CONF_EXEC); if (pbs_conf.pbs_server_name == NULL) sprintf(buf, "%s %s", buf, PBS_CONF_SERVER_NAME); if (buf[0] != '\0') { fprintf(stderr, "pbsconf error: pbs conf variables not found: %s\n", buf); goto err; } /* * Perform sanity checks on PBS_*_HOST_NAME values and PBS_CONF_SMTP_SERVER_NAME. * See IDD for SPID 4534. */ buf[0] = '\0'; if ((pbs_conf.pbs_server_host_name != NULL) && (strchr(pbs_conf.pbs_server_host_name, ':') != NULL)) strcpy(buf, PBS_CONF_SERVER_HOST_NAME); else if ((pbs_conf.pbs_public_host_name != NULL) && (strchr(pbs_conf.pbs_public_host_name, ':') != NULL)) strcpy(buf, PBS_CONF_PUBLIC_HOST_NAME); else if ((pbs_conf.pbs_mail_host_name != NULL) && (strchr(pbs_conf.pbs_mail_host_name, ':') != NULL)) strcpy(buf, PBS_CONF_MAIL_HOST_NAME); else if ((pbs_conf.pbs_smtp_server_name != NULL) && (strchr(pbs_conf.pbs_smtp_server_name, ':') != NULL)) strcpy(buf, PBS_CONF_SMTP_SERVER_NAME); else if ((pbs_conf.pbs_output_host_name != NULL) && (strchr(pbs_conf.pbs_output_host_name, ':') != NULL)) strcpy(buf, PBS_CONF_OUTPUT_HOST_NAME); else if ((pbs_conf.pbs_mom_node_name != NULL) && (strchr(pbs_conf.pbs_mom_node_name, ':') != NULL)) strcpy(buf, PBS_CONF_MOM_NODE_NAME); if (buf[0] != '\0') { fprintf(stderr, "pbsconf error: illegal value for: %s\n", buf); goto err; } /* * Finally, fill in the blanks for variables with inferred values. */ if (pbs_conf.pbs_environment == NULL) { /* a reasonable default for the pbs_environment file is in pbs_home */ /* strlen("/pbs_environment") + '\0' == 16 + 1 == 17 */ if ((pbs_conf.pbs_environment = malloc(strlen(pbs_conf.pbs_home_path) + 17)) != NULL) { sprintf(pbs_conf.pbs_environment, "%s/pbs_environment", pbs_conf.pbs_home_path); #ifdef WIN32 back2forward_slash(pbs_conf.pbs_environment); #endif } else { goto err; } } free(pbs_conf.iff_path); /* strlen("/sbin/pbs_iff") + '\0' == 13 + 1 == 14 */ if ((pbs_conf.iff_path = malloc(strlen(pbs_conf.pbs_exec_path) + 14)) != NULL) { sprintf(pbs_conf.iff_path, "%s/sbin/pbs_iff", pbs_conf.pbs_exec_path); #ifdef WIN32 back2forward_slash(pbs_conf.iff_path); #endif } else { goto err; } if (pbs_conf.rcp_path == NULL) { if ((pbs_conf.rcp_path = malloc(strlen(pbs_conf.pbs_exec_path) + 14)) != NULL) { sprintf(pbs_conf.rcp_path, "%s/sbin/pbs_rcp", pbs_conf.pbs_exec_path); #ifdef WIN32 back2forward_slash(pbs_conf.rcp_path); #endif } else { goto err; } } free(pbs_conf.pbs_demux_path); /* strlen("/sbin/pbs_demux") + '\0' == 15 + 1 == 16 */ if ((pbs_conf.pbs_demux_path = malloc(strlen(pbs_conf.pbs_exec_path) + 16)) != NULL) { sprintf(pbs_conf.pbs_demux_path, "%s/sbin/pbs_demux", pbs_conf.pbs_exec_path); #ifdef WIN32 back2forward_slash(pbs_conf.pbs_demux_path); #endif } else { goto err; } if ((gvalue = getenv(PBS_CONF_LICENSE_STRING)) != NULL) { free(pbs_conf.pbs_license_file_location); if ((pbs_conf.pbs_license_file_location = strdup(gvalue)) == NULL) { goto err; } } #ifndef WIN32 if ((gvalue = getenv(PBS_CONF_AUTH)) != NULL) { if (!strcasecmp(gvalue, "MUNGE")) { pbs_conf.auth_method = AUTH_MUNGE; } else { fprintf(stderr, "pbsconf error: illegal value for %s\n",PBS_CONF_AUTH); goto err; } } #endif pbs_conf.pbs_tmpdir = pbs_get_tmpdir(); /* if routers has null value populate with server name as the default */ if (pbs_conf.pbs_leaf_routers == NULL) { if (pbs_conf.pbs_primary && pbs_conf.pbs_secondary) { pbs_conf.pbs_leaf_routers = malloc(strlen(pbs_conf.pbs_primary) + strlen(pbs_conf.pbs_secondary) + 2); if (pbs_conf.pbs_leaf_routers == NULL) { fprintf(stderr, "Out of memory\n"); goto err; } sprintf(pbs_conf.pbs_leaf_routers, "%s,%s", pbs_conf.pbs_primary, pbs_conf.pbs_secondary); } else { if (pbs_conf.pbs_server_host_name) { pbs_conf.pbs_leaf_routers = strdup(pbs_conf.pbs_server_host_name); } else if (pbs_conf.pbs_server_name) { pbs_conf.pbs_leaf_routers = strdup(pbs_conf.pbs_server_name); } else { fprintf(stderr, "PBS server undefined\n"); goto err; } if (pbs_conf.pbs_leaf_routers == NULL) { fprintf(stderr, "Out of memory\n"); goto err; } } } if (pbs_conf.pbs_use_tcp == 0) { pbs_conf.pbs_use_compression = 0; pbs_conf.pbs_use_mcast = 0; pbs_conf.pbs_use_ft = 0; } pbs_conf.loaded = 1; if (pbs_client_thread_unlock_conf() != 0) return 0; return 1; /* success */ err: if (pbs_conf.pbs_conf_file) { free(pbs_conf.pbs_conf_file); pbs_conf.pbs_conf_file = NULL; } if (pbs_conf.pbs_data_service_host) { free(pbs_conf.pbs_data_service_host); pbs_conf.pbs_data_service_host = NULL; } if (pbs_conf.pbs_home_path) { free(pbs_conf.pbs_home_path); pbs_conf.pbs_home_path = NULL; } if (pbs_conf.pbs_exec_path) { free(pbs_conf.pbs_exec_path); pbs_conf.pbs_exec_path = NULL; } if (pbs_conf.pbs_server_name) { free(pbs_conf.pbs_server_name); pbs_conf.pbs_server_name = NULL; } if (pbs_conf.rcp_path) { free(pbs_conf.rcp_path); pbs_conf.rcp_path = NULL; } if (pbs_conf.scp_path) { free(pbs_conf.scp_path); pbs_conf.scp_path = NULL; } if (pbs_conf.k5dcelogin_path) { free(pbs_conf.k5dcelogin_path); pbs_conf.k5dcelogin_path = NULL; } if (pbs_conf.pbs_environment) { free(pbs_conf.pbs_environment); pbs_conf.pbs_environment = NULL; } if (pbs_conf.pbs_primary) { free(pbs_conf.pbs_primary); pbs_conf.pbs_primary = NULL; } if (pbs_conf.pbs_secondary) { free(pbs_conf.pbs_secondary); pbs_conf.pbs_secondary = NULL; } if (pbs_conf.pbs_mom_home) { free(pbs_conf.pbs_mom_home); pbs_conf.pbs_mom_home = NULL; } if (pbs_conf.pbs_core_limit) { free(pbs_conf.pbs_core_limit); pbs_conf.pbs_core_limit = NULL; } if (pbs_conf.pbs_license_file_location) { free(pbs_conf.pbs_license_file_location); pbs_conf.pbs_license_file_location = NULL; } pbs_conf.load_failed = 1; (void)pbs_client_thread_unlock_conf(); return 0; }
/** * @brief * pbs_get_tmpdir - Identify the configured tmpdir location * * @return char * * @retval !NULL pointer to the tmpdir string * @retval NULL failure */ char * pbs_get_tmpdir(void) { FILE *fp = NULL; char *tmpdir = NULL; char *conf_file = NULL; char *conf_name = NULL; char *conf_value = NULL; char *p = NULL; #ifdef WIN32 struct stat sb; #endif /* If pbs_conf already been populated use that value. */ if ((pbs_conf.loaded != 0) && (pbs_conf.pbs_tmpdir != NULL)) return (pbs_conf.pbs_tmpdir); /* Next, try the environment. */ #ifdef WIN32 if ((p = getenv("TMP")) != NULL) #else if ((p = getenv("TMPDIR")) != NULL) #endif { tmpdir = shorten_and_cleanup_path(p); } /* PBS_TMPDIR overrides TMP or TMPDIR if set */ if ((p = getenv(PBS_CONF_TMPDIR)) != NULL) { free(tmpdir); tmpdir = shorten_and_cleanup_path(p); } if (tmpdir != NULL) return tmpdir; /* Now try pbs.conf */ conf_file = pbs_get_conf_file(); if ((fp = fopen(conf_file, "r")) != NULL) { while (parse_config_line(fp, &conf_name, &conf_value) != NULL) { if ((conf_name == NULL) || (*conf_name == '\0')) continue; if ((conf_value == NULL) || (*conf_value == '\0')) continue; if (!strcmp(conf_name, PBS_CONF_TMPDIR)) { free(tmpdir); tmpdir = shorten_and_cleanup_path(conf_value); } } fclose(fp); } free(conf_file); conf_file = NULL; if (tmpdir != NULL) return tmpdir; /* Finally, resort to the default. */ #ifdef WIN32 if (stat(TMP_DIR, &sb) == 0) { tmpdir = shorten_and_cleanup_path(TMP_DIR); } else if (stat("C:\\WINDOWS\\TEMP", &sb) == 0) { tmpdir = shorten_and_cleanup_path("C:\\WINDOWS\\TEMP"); } #else tmpdir = shorten_and_cleanup_path(TMP_DIR); #endif if (tmpdir == NULL) { /* strlen("/spool") + '\0' == 6 + 1 = 7 */ if ((p = malloc(strlen(pbs_conf.pbs_home_path) + 7)) == NULL) { return NULL; } else { sprintf(p, "%s/spool", pbs_conf.pbs_home_path); tmpdir = shorten_and_cleanup_path(p); free(p); } } /* Strip the trailing separator. */ #ifdef WIN32 if (tmpdir[strlen(tmpdir)-1] == '\\') tmpdir[strlen(tmpdir)-1] = '\0'; #else if (tmpdir[strlen(tmpdir)-1] == '/') tmpdir[strlen(tmpdir)-1] = '\0'; #endif return tmpdir; }
/* * parse_config_file -- (internal) parse config file */ static int parse_config_file(const char *filename, struct rpmemd_config *config, uint64_t disabled) { RPMEMD_ASSERT(filename != NULL); FILE *file = fopen(filename, "r"); if (file == NULL) { if (filename != RPMEMD_DEFAULT_CONFIG_FILE) { RPMEMD_LOG(ERR, "!%s", filename); goto error_fopen; } else goto default_config_missing; } uint8_t line_max_increased = 0; uint64_t line_max = CONFIG_LINE_SIZE_INIT; uint64_t line_num = 1; char *line = (char *)malloc(sizeof(char) * line_max); if (line == NULL) { RPMEMD_LOG(ERR, "!malloc"); goto error_malloc_line; } char *line_copy = (char *)malloc(sizeof(char) * line_max); if (line_copy == NULL) { RPMEMD_LOG(ERR, "!malloc"); goto error_malloc_line_copy; } struct rpmemd_special_chars_pos pos; do { memset(&pos, INT32_MAX, sizeof(pos)); if (get_config_line(file, &line, &line_max, &line_max_increased, &pos) != 0) goto error; if (line_max_increased) { line_copy = (char *)realloc(line_copy, sizeof(char) * line_max); if (line_copy == NULL) { RPMEMD_LOG(ERR, "!malloc"); goto error_malloc_line_copy; } line_max_increased = 0; } if (pos.EOL_char != INVALID_CHAR_POS) { strcpy(line_copy, line); parse_config_line(line_copy, &pos, config, disabled); if (errno != 0) { size_t len = strlen(line); if (len > 0 && line[len - 1] == '\n') line[len - 1] = '\0'; RPMEMD_LOG(ERR, "Invalid config file line at " "%s:%lu\n%s", filename, line_num, line); goto error; } } ++line_num; } while (pos.EOL_char != INVALID_CHAR_POS); free(line_copy); free(line); fclose(file); default_config_missing: return 0; error: free(line_copy); error_malloc_line_copy: free(line); error_malloc_line: fclose(file); error_fopen: return -1; }
struct if_options * read_config(const char *file, const char *ifname, const char *ssid, const char *profile) { struct if_options *ifo; FILE *f; char *line, *option, *p, *platform; int skip = 0, have_profile = 0; struct utsname utn; /* Seed our default options */ ifo = xzalloc(sizeof(*ifo)); ifo->options |= DHCPCD_GATEWAY | DHCPCD_DAEMONISE | DHCPCD_LINK; ifo->options |= DHCPCD_ARP | DHCPCD_IPV4LL; ifo->options |= DHCPCD_IPV6RS | DHCPCD_IPV6RA_REQRDNSS; ifo->timeout = DEFAULT_TIMEOUT; ifo->reboot = DEFAULT_REBOOT; ifo->metric = -1; strlcpy(ifo->script, SCRIPT, sizeof(ifo->script)); gethostname(ifo->hostname, HOSTNAME_MAX_LEN); /* Ensure that the hostname is NULL terminated */ ifo->hostname[HOSTNAME_MAX_LEN] = '\0'; if (strcmp(ifo->hostname, "(none)") == 0 || strcmp(ifo->hostname, "localhost") == 0) ifo->hostname[0] = '\0'; platform = hardware_platform(); #ifndef ANDROID if (uname(&utn) == 0) ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1, VENDORCLASSID_MAX_LEN, "%s-%s:%s-%s:%s%s%s", PACKAGE, VERSION, utn.sysname, utn.release, utn.machine, platform ? ":" : "", platform ? platform : ""); else #endif ifo->vendorclassid[0] = snprintf((char *)ifo->vendorclassid + 1, VENDORCLASSID_MAX_LEN, "%s-%s", PACKAGE, VERSION); /* Parse our options file */ f = fopen(file ? file : CONFIG, "r"); if (f == NULL) { if (file != NULL) syslog(LOG_ERR, "fopen `%s': %m", file); return ifo; } while ((line = get_line(f))) { option = strsep(&line, " \t"); /* Trim trailing whitespace */ if (line && *line) { p = line + strlen(line) - 1; while (p != line && (*p == ' ' || *p == '\t') && *(p - 1) != '\\') *p-- = '\0'; } /* Start of an interface block, skip if not ours */ if (strcmp(option, "interface") == 0) { if (ifname && line && strcmp(line, ifname) == 0) skip = 0; else skip = 1; continue; } /* Start of an ssid block, skip if not ours */ if (strcmp(option, "ssid") == 0) { if (ssid && line && strcmp(line, ssid) == 0) skip = 0; else skip = 1; continue; } /* Start of a profile block, skip if not ours */ if (strcmp(option, "profile") == 0) { if (profile && line && strcmp(line, profile) == 0) { skip = 0; have_profile = 1; } else skip = 1; continue; } if (skip) continue; parse_config_line(ifo, option, line); } fclose(f); if (profile && !have_profile) { free_options(ifo); errno = ENOENT; ifo = NULL; } /* Terminate the encapsulated options */ if (ifo && ifo->vendor[0] && !(ifo->options & DHCPCD_VENDORRAW)) { ifo->vendor[0]++; ifo->vendor[ifo->vendor[0]] = DHO_END; } return ifo; }
static LV2_State_Status restore (LV2_Handle instance, LV2_State_Retrieve_Function retrieve, LV2_State_Handle handle, uint32_t flags, const LV2_Feature* const* features) { MidiMap* self = (MidiMap*)instance; if (self->state) { fprintf (stderr, "MidiMap.lv2 error: state restore ignored\n"); return LV2_STATE_SUCCESS; // or LV2_STATE_ERR_UNKNOWN ?? } size_t size; uint32_t type; uint32_t valflags; const void* value; free (self->cfg_file_path); self->cfg_file_path = NULL; bool loaded = false; value = retrieve (handle, self->uris.mem_state, &size, &type, &valflags); if (value) { const char* cfg = (const char*)value; const char* te; const char* ts = cfg; unsigned int cfg_version = 0; self->state = calloc (1, sizeof (RuleSet)); while (ts && *ts && (te = strchr (ts, '\n'))) { char line[MAX_CFG_LINE_LEN]; if (te - ts < 1023) { memcpy (line, ts, te - ts); line[te - ts]=0; parse_config_line (self, line, &cfg_version, 0); } ts = te + 1; } if (cfg_version > 0) { loaded = true; } else { free (self->state); self->state = NULL; } } LV2_State_Map_Path* map_path = NULL; for (int i = 0; features[i]; ++i) { if (!strcmp (features[i]->URI, LV2_STATE__mapPath)) { map_path = (LV2_State_Map_Path*) features[i]->data; } } if (!loaded && map_path) { // try re-loading saved file (v0.1.0) value = retrieve (handle, self->uris.mem_cfgfile, &size, &type, &valflags); if (value) { char* path = map_path->absolute_path (map_path->handle, (const char*)value); parse_config_file (self, path); #ifndef _WIN32 // https://github.com/drobilla/lilv/issues/14 free (path); #endif } } if (self->state) { activate_config (self); free (self->state); self->state = NULL; self->inform_ui = true; } return LV2_STATE_SUCCESS; }
static bool parse_options(int argc, char **argv) { config_t *cfg; int r; int option_index = 0; int lineno = 0; cmdline_conf = list_alloc((list_action_t)free_config); while((r = getopt_long(argc, argv, "c:DLd::n:so:RU:", long_options, &option_index)) != EOF) { switch (r) { case 0: /* long option */ break; case 'c': /* config file */ confbase = xstrdup(optarg); break; case 'D': /* no detach */ do_detach = false; break; case 'L': /* no detach */ #ifndef HAVE_MLOCKALL logger(DEBUG_ALWAYS, LOG_ERR, "The %s option is not supported on this platform.", argv[optind - 1]); return false; #else do_mlock = true; break; #endif case 'd': /* increase debug level */ if(!optarg && optind < argc && *argv[optind] != '-') optarg = argv[optind++]; if(optarg) debug_level = atoi(optarg); else debug_level++; break; case 'n': /* net name given */ netname = xstrdup(optarg); break; case 's': /* syslog */ use_logfile = false; use_syslog = true; break; case 'o': /* option */ cfg = parse_config_line(optarg, NULL, ++lineno); if (!cfg) return false; list_insert_tail(cmdline_conf, cfg); break; #ifdef HAVE_MINGW case 'R': case 'U': logger(DEBUG_ALWAYS, LOG_ERR, "The %s option is not supported on this platform.", argv[optind - 1]); return false; #else case 'R': /* chroot to NETNAME dir */ do_chroot = true; break; case 'U': /* setuid to USER */ switchuser = optarg; break; #endif case 1: /* show help */ show_help = true; break; case 2: /* show version */ show_version = true; break; case 3: /* bypass security */ bypass_security = true; break; case 4: /* write log entries to a file */ use_syslog = false; use_logfile = true; if(!optarg && optind < argc && *argv[optind] != '-') optarg = argv[optind++]; if(optarg) logfilename = xstrdup(optarg); break; case 5: /* open control socket here */ pidfilename = xstrdup(optarg); break; case '?': /* wrong options */ usage(true); return false; default: break; } } if(optind < argc) { fprintf(stderr, "%s: unrecognized argument '%s'\n", argv[0], argv[optind]); usage(true); return false; } if(!netname && (netname = getenv("NETNAME"))) netname = xstrdup(netname); /* netname "." is special: a "top-level name" */ if(netname && (!*netname || !strcmp(netname, "."))) { free(netname); netname = NULL; } if(netname && (strpbrk(netname, "\\/") || *netname == '.')) { fprintf(stderr, "Invalid character in netname!\n"); return false; } return true; }