⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getconfig.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
/**         OpenPBS (Portable Batch System) v2.3 Software License* * Copyright (c) 1999-2000 Veridian Information Solutions, Inc.* All rights reserved.* * ---------------------------------------------------------------------------* For a license to use or redistribute the OpenPBS software under conditions* other than those described below, or to purchase support for this software,* please contact Veridian Systems, PBS Products Department ("Licensor") at:* *    www.OpenPBS.org  +1 650 967-4675                  sales@OpenPBS.org*                        877 902-4PBS (US toll-free)* ---------------------------------------------------------------------------* * This license covers use of the OpenPBS v2.3 software (the "Software") at* your site or location, and, for certain users, redistribution of the* Software to other sites and locations.  Use and redistribution of* OpenPBS v2.3 in source and binary forms, with or without modification,* are permitted provided that all of the following conditions are met.* After December 31, 2001, only conditions 3-6 must be met:* * 1. Commercial and/or non-commercial use of the Software is permitted*    provided a current software registration is on file at www.OpenPBS.org.*    If use of this software contributes to a publication, product, or*    service, proper attribution must be given; see www.OpenPBS.org/credit.html* * 2. Redistribution in any form is only permitted for non-commercial,*    non-profit purposes.  There can be no charge for the Software or any*    software incorporating the Software.  Further, there can be no*    expectation of revenue generated as a consequence of redistributing*    the Software.* * 3. Any Redistribution of source code must retain the above copyright notice*    and the acknowledgment contained in paragraph 6, this list of conditions*    and the disclaimer contained in paragraph 7.* * 4. Any Redistribution in binary form must reproduce the above copyright*    notice and the acknowledgment contained in paragraph 6, this list of*    conditions and the disclaimer contained in paragraph 7 in the*    documentation and/or other materials provided with the distribution.* * 5. Redistributions in any form must be accompanied by information on how to*    obtain complete source code for the OpenPBS software and any*    modifications and/or additions to the OpenPBS software.  The source code*    must either be included in the distribution or be available for no more*    than the cost of distribution plus a nominal fee, and all modifications*    and additions to the Software must be freely redistributable by any party*    (including Licensor) without restriction.* * 6. All advertising materials mentioning features or use of the Software must*    display the following acknowledgment:* *     "This product includes software developed by NASA Ames Research Center,*     Lawrence Livermore National Laboratory, and Veridian Information *     Solutions, Inc.*     Visit www.OpenPBS.org for OpenPBS software support,*     products, and information."* * 7. DISCLAIMER OF WARRANTY* * THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. ANY EXPRESS* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT* ARE EXPRESSLY DISCLAIMED.* * IN NO EVENT SHALL VERIDIAN CORPORATION, ITS AFFILIATED COMPANIES, OR THE* U.S. GOVERNMENT OR ANY OF ITS AGENCIES BE LIABLE FOR ANY DIRECT OR INDIRECT,* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.* * This license will be governed by the laws of the Commonwealth of Virginia,* without reference to its choice of law rules.*//* $Id: getconfig.c,v 1.1.6.2 2000/08/09 00:18:41 hender Exp $ *//* * This module contains the necessary functions for * processing the config file and setting the  * appropriate variables.  These functions are: * * get_config:   main loop for processing the config file * open_config:  open the configuration file for read * close_config: close the configuration file * set_cf_gopt:  validate the configuration file and *               set appropriate variables */#include <sys/types.h>#include <ctype.h>#include <errno.h>#include <limits.h>#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <string.h>#include "pbs_ifl.h"#include "net_connect.h"#include "log.h"/* Scheduler header files */#include "toolkit.h"#include "gblxvars.h"#define	MAX_LINE_SIZE	512	/* maximum line size */extern int errno;static int post_config (void);static int validate_config (void);static int set_cfg_opt (char *, char *);static int arg_to_qlist (char *, char *, QueueList **);static int get_variance (char *, int *, int *);static void print_config (void);static int qlist_disjoint (QueueList *qlist1, QueueList *qlist2);static int qlist_unique (QueueList *qlist);static int qlist_one_per_host (QueueList *qlist);/* Main loop for processing the configuration file */int schd_get_config(char *filename){    char   *id = "schd_get_config";    char    line[MAX_LINE_SIZE];    char    cfg_option[MAX_LINE_SIZE];    char    cfg_arg[MAX_LINE_SIZE];    FILE   *cfgfd = NULL;    char   *comment;    int     linenum = 0, error = 0;    size_t  linelen;    cfgfd = fopen(filename, "r");    if (cfgfd == NULL) {	(void)sprintf(log_buffer, 	    "Opening '%s': %s", filename, strerror(errno));	log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);	DBPRT(("%s: %s\n", id, log_buffer));	return (-1);    }    /* Walk through the configuration file line by line. */    while (fgets(line, sizeof (line), cfgfd)) {	linenum++;	linelen = strlen(line);	if (linelen == (sizeof (line) - 1)) {	    (void)sprintf(log_buffer, 	       "Error in config file %s, line %d: Line too long",		filename, linenum);	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);	    DBPRT(( "%s\n", log_buffer));	    error = -1;	    break;	} else {	    linelen--;			/* Move back to newline. */	    line[linelen] = '\0';	/* And remove it. */	}	/* If there is a comment on this line, remove it from view. */	if ((comment = strchr(line, '#')) != NULL) 	    *comment = '\0';	if (strlen(line) < 2)	    continue;		/* skip blank lines */	/* Split the option and the argument. */	if (sscanf(line, "%s %s", cfg_option, cfg_arg) != 2) {	    /* Unable to read a cfg_option and cfg_arg */	    (void)sprintf(log_buffer, "Error in config file %s, line %d",		filename, linenum);	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);	    DBPRT(( "%s\n", log_buffer));	    error = -1;	    break;        }	/* Set the configurable options */	if (set_cfg_opt(cfg_option, cfg_arg)) {	    /* Unable to parse the option. */	    (void)sprintf(log_buffer, 		"Error parsing option '%s' in config file %s, line %d",		cfg_option, filename, linenum);	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id, log_buffer);	    DBPRT(( "%s\n", log_buffer));	    error = -1;	    break;	}    }    /* Close the config file */    fclose(cfgfd);    if (error)	return (error);    /* Do any post-configuration necessary. */    if (!post_config())	return (-1);    if (!validate_config())	return (-1);    print_config();    return (0);}/*  * Now that an option and its argument have been read, validate them and * set the appropriate global configuration variables. */static int set_cfg_opt(char *cfg_option, char *cfg_arg){    char   *id = "set_cfg_opt";    /* XXX Should smash case on these before doing string compares? */    if (!strcmp(cfg_option, "TARGET_LOAD_PCT")) {	schd_TARGET_LOAD_PCT = atoi(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "TARGET_LOAD_VARIANCE")) {	return (get_variance(cfg_arg, 	    &schd_TARGET_LOAD_MINUS, &schd_TARGET_LOAD_PLUS));    }        if (!strcmp(cfg_option, "HIGH_SYSTIME")) {	schd_HIGH_SYSTIME = atoi(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "MAX_JOBS")) {	schd_MAX_JOBS = atoi(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "MIN_JOBS")) {	schd_MIN_JOBS = atoi(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "MAX_DEDICATED_JOBS")) {	schd_MAX_DEDICATED_JOBS = atoi(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "MAX_USER_RUN_JOBS")) {	schd_MAX_USER_RUN_JOBS = atoi(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "ENFORCE_ALLOCATION")) {	return schd_val2booltime(cfg_arg, &schd_ENFORCE_ALLOCATION);    }        if (!strcmp(cfg_option, "TEST_ONLY")) {	return schd_val2bool(cfg_arg, &schd_TEST_ONLY);    }        if (!strcmp(cfg_option, "ENFORCE_DEDICATED_TIME")) {	return schd_val2booltime(cfg_arg, &schd_ENFORCE_DEDTIME);    }        if (!strcmp(cfg_option, "DEDICATED_TIME_COMMAND")) {	if (schd_DEDTIME_COMMAND)	    free(schd_DEDTIME_COMMAND);	schd_DEDTIME_COMMAND = schd_strdup(cfg_arg);	if (schd_DEDTIME_COMMAND == NULL) {	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,		"schd_strdup(schd_DEDTIME_COMMAND)");	    return (-1);	}	return (0);    }    if (!strcmp(cfg_option, "DEDICATED_TIME_CACHE_SECS")) {	schd_DEDTIME_CACHE_SECS = atoi(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "DECAY_FACTOR")) {	schd_DECAY_FACTOR = atof(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "OA_DECAY_FACTOR")) {	schd_OA_DECAY_FACTOR = atof(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "SCHED_ACCT_DIR")) {	if (schd_SCHED_ACCT_DIR)	    free(schd_SCHED_ACCT_DIR);	schd_SCHED_ACCT_DIR = schd_strdup(cfg_arg);	if (schd_SCHED_ACCT_DIR == NULL) {	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,		"schd_strdup(schd_SCHED_ACCT_DIR)");	    return (-1);	}	return (0);    }        if (!strcmp(cfg_option, "SYSTEM_NAME")) {	if (schd_SYSTEM_NAME)	    free(schd_SYSTEM_NAME);	schd_SYSTEM_NAME = schd_strdup(cfg_arg);	schd_lowercase(schd_SYSTEM_NAME);	return (0);    }        if (!strcmp(cfg_option, "SERVER_HOST")) {	if (schd_SERVER_HOST)	    free(schd_SERVER_HOST);	schd_SERVER_HOST = schd_strdup(cfg_arg);	if (schd_SERVER_HOST == NULL) {	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,		"schd_strdup(schd_SERVER_HOST)");	    return (-1);	}	schd_lowercase(schd_SERVER_HOST);	return (0);    }        if (!strcmp(cfg_option, "SCHED_HOST")) {	if (schd_SCHED_HOST)	    free(schd_SCHED_HOST);	schd_SCHED_HOST = schd_strdup(cfg_arg);	if (schd_SCHED_HOST == NULL) {	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,		"schd_strdup(schd_SCHED_HOST)");	    return (-1);	}	schd_lowercase(schd_SCHED_HOST);	return (0);    }        if (!strcmp(cfg_option, "SORTED_JOB_DUMPFILE")) {	if (schd_JOB_DUMPFILE)	    free(schd_JOB_DUMPFILE);	schd_JOB_DUMPFILE = schd_strdup(cfg_arg);	if (schd_JOB_DUMPFILE == NULL) {	    log_record(PBSEVENT_SYSTEM, PBS_EVENTCLASS_SERVER, id,		"schd_strdup(schd_JOB_DUMPFILE)");	    return (-1);	}	return (0);    }        if (!strcmp(cfg_option, "SCHED_RESTART_ACTION")) {	if (strcmp(cfg_arg, "NONE") == 0) {	    schd_SCHED_RESTART_ACTION = SCHD_RESTART_NONE;	    return (0);	}	if (strcmp(cfg_arg, "RESUBMIT") == 0) {	    schd_SCHED_RESTART_ACTION = SCHD_RESTART_RESUBMIT;	    return (0);	}	if (strcmp(cfg_arg, "RERUN") == 0) {	    schd_SCHED_RESTART_ACTION = SCHD_RESTART_RERUN;	    return (0);	}	return (-1);		/* Bad argument */    }        if (!strcmp(cfg_option, "SORT_BY_PAST_USAGE")) {	return schd_val2bool(cfg_arg, &schd_SORT_BY_PAST_USAGE);    }        if (!strcmp(cfg_option, "ENFORCE_PRIME_TIME")) {	return schd_val2booltime(cfg_arg, &schd_ENFORCE_PRIME_TIME);    }        if (!strcmp(cfg_option, "PRIME_TIME_START")) {	schd_PRIME_TIME_START = schd_val2sec(cfg_arg);	return (0);    }        if (!strcmp(cfg_option, "PRIME_TIME_END")) {	schd_PRIME_TIME_END = schd_val2sec(cfg_arg);	return (0);    }    if (!strcmp(cfg_option, "PRIME_TIME_SMALL_NODE_LIMIT")) {	schd_PT_SMALL_NODE_LIMIT = atoi(cfg_arg);	return (0);    }    if (!strcmp(cfg_option, "PRIME_TIME_SMALL_WALLT_LIMIT")) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -