📄 attr_fn_resc.c
字号:
/** 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.*/#include <pbs_config.h> /* the master config generated by configure */#include <assert.h>#include <ctype.h>#include <memory.h>#ifndef NDEBUG#include <stdio.h>#endif#include <stdlib.h>#include <string.h>#include <pbs_ifl.h>#include "log.h"#include "list_link.h"#include "attribute.h"#include "resource.h"#include "pbs_error.h"static char ident[] = "@(#) $RCSfile: attr_fn_resc.c,v $ $Revision: 2.1.10.5 $";/* * This file contains functions for manipulating attributes of type * resource * * A "resource" is similiar to an attribute but with two levels of * names. The first name is the attribute name, e.g. "resource-list", * the second name is the resource name, e.g. "mem". * * Each resource_def has functions for: * Decoding the value string to the internal representation. * Encoding the internal attribute to external form * Setting the value by =, + or - operators. * Comparing a (decoded) value with the attribute value. * freeing the resource value space (if extra memory is allocated) * * Some or all of the functions for an resource type may be shared with * other resource types or even attributes. * * The prototypes are declared in "attribute.h", also see resource.h * * ---------------------------------------------------------------------------- * Attribute functions for attributes with value type resource * ---------------------------------------------------------------------------- *//* Global Variables */int resc_access_perm;/* External Global Items */int comp_resc_gt; /* count of resources compared > */int comp_resc_eq; /* count of resources compared = */int comp_resc_lt; /* count of resources compared < */int comp_resc_nc; /* count of resources not compared */extern resource_def svr_resc_def[];extern int svr_resc_size;/* * decode_resc - decode a "attribute name/resource name/value" triplet into * a resource type attribute * * Returns: 0 if ok, * >0 error number if error, * *patr members set */int decode_resc(patr, name, rescn, val) struct attribute *patr; /* Modified on Return */ char *name; /* attribute name */ char *rescn; /* resource name - is used here */ char *val; /* resource value */{ resource *prsc; resource_def *prdef; int rc = 0; int rv; if (patr == (attribute *)0) return (PBSE_INTERNAL); if (rescn == (char *)0) return (PBSE_UNKRESC); if ( !(patr->at_flags & ATR_VFLAG_SET)) CLEAR_HEAD(patr->at_val.at_list); prdef = find_resc_def(svr_resc_def, rescn, svr_resc_size); if (prdef == (resource_def *)0) { /* * didn't find resource with matching name, use unknown; * but return PBSE_UNKRESC incase caller dosn`t wish to * accept unknown resources */ rc = PBSE_UNKRESC; prdef = svr_resc_def + (svr_resc_size-1); } prsc = find_resc_entry(patr, prdef); if (prsc == (resource *)0) /* no current resource entry, add it */ if ((prsc = add_resource_entry(patr,prdef)) == (resource *)0) { return (PBSE_SYSTEM); } /* note special use of ATR_DFLAG_ACCESS, see server/attr_recov() */ if (((prsc->rs_defin->rs_flags&resc_access_perm&ATR_DFLAG_WRACC) ==0) && (resc_access_perm != ATR_DFLAG_ACCESS)) return (PBSE_ATTRRO); patr->at_flags |= ATR_VFLAG_SET | ATR_VFLAG_MODIFY; rv = prdef->rs_decode(&prsc->rs_value, name, rescn, val); if (rv) return (rv); else return (rc);}/* * encode_resc - encode attr of type ATR_TYPE_RESR into attr_extern form * * Here we are a little different from the typical attribute. Most have a * single value to be encoded. But resource attribute may have a whole bunch. * First get the name of the parent attribute (typically "resource-list"). * Then for each resource in the list, call the individual resource decode * routine with "aname" set to the parent attribute name. * * If mode is either ATR_ENCODE_SAVE or ATR_ENCODE_SVR, then any resource * currently set to the default value is not encoded. This allows it to be * reset if the default changes or it is moved. * * If the mode is ATR_ENCODE_CLIENT or ATR_ENCODE_MOM, the client permission * passed in the global variable resc_access_perm is checked against each * definition. This allows a resource by resource access setting, not just * on the attribute. * * Returns: >0 if ok * =0 if no value to encode, no entries added to list * <0 if some resource entry had an encode error. */int encode_resc(attr, phead, atname, rsname, mode) attribute *attr; /* ptr to attribute to encode */ list_head *phead; /* head of attrlist list */ char *atname; /* attribute name */ char *rsname; /* resource name, null on call */ int mode; /* encode mode */{ int dflt; resource *prsc; int rc; int grandtotal = 0; int perm; if ( !attr ) return (-1); if ( !(attr->at_flags & ATR_VFLAG_SET)) return (0); /* no resources at all */ /* ok now do each separate resource */ prsc = (resource *)GET_NEXT(attr->at_val.at_list); while (prsc != (resource *)0) { /* * encode if sending to client or MOM with permission * encode if saving and not default value * encode if sending to server and not default and have permission */ perm = prsc->rs_defin->rs_flags & resc_access_perm ; dflt = prsc->rs_value.at_flags & ATR_VFLAG_DEFLT; if ( ((mode == ATR_ENCODE_CLIENT) && perm) || ((mode == ATR_ENCODE_MOM) && perm) || ((mode == ATR_ENCODE_SAVE) && (dflt == 0)) || ((mode == ATR_ENCODE_SVR) && (dflt == 0) && perm) ) { rsname = prsc->rs_defin->rs_name; rc = prsc->rs_defin->rs_encode(&prsc->rs_value, phead, atname, rsname, mode); if (rc < 0) return (rc); grandtotal += rc; } prsc = (resource *)GET_NEXT(prsc->rs_link); } return (grandtotal);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -