📄 xpbs_scriptload.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.*//* * * xpbs_scriptload - parses a job script file, separating PBS directive * from non-PBS lines. Job attributes are reported to stdout, * and non-PBS lines are shown in script_tmp. This code * is a modification of "qsub". * * Authors: * Terry Heidelberg * Livermore Computing * * Bruce Kelly * National Energy Research Supercomputer Center * * Lawrence Livermore National Laboratory * University of California * * Albeaus Bayucan * Sterling Software * NASA Ames Research Center */#include <pbs_config.h> /* the master config generated by configure */#include <ctype.h>#include <sys/types.h>#include <sys/socket.h>#include <sys/stat.h>#include <sys/time.h>#include <sys/wait.h>#include <netinet/in.h>#include <errno.h>#include <fcntl.h>#include <netdb.h>#include <signal.h>#include <termios.h>#ifdef sun#include <sys/stream.h>#endif /* sun */#if defined(HAVE_SYS_IOCTL_H)#include <sys/ioctl.h>#endif /* HAVE_SYS_IOCTL_H */#if !defined(sgi) && !defined(_AIX) && !defined(linux)#include <sys/tty.h>#endif /* ! sgi */#include "cmds.h"static char ident[] = "@(#) $RCSfile: xpbs_scriptload.c,v $ $Revision: 2.1.10.4 $";#define MAX_QSUB_PREFIX_LEN 32#ifndef PBS_DEPEND_LEN#define PBS_DEPEND_LEN 2040#endifstatic char PBS_DPREFIX_DEFAULT[] = "#PBS";/* globals */int inter_sock;struct termios oldtio;struct winsize wsz;struct attrl *attrib = NULL;char *new_jobname; /* return from submit request */char dir_prefix[MAX_QSUB_PREFIX_LEN+1];char path_out[MAXPATHLEN+1];char destination[PBS_MAXDEST];/* state booleans for protecting already-set options */int a_opt = FALSE;int c_opt = FALSE;int e_opt = FALSE;int h_opt = FALSE;int j_opt = FALSE;int k_opt = FALSE;int l_opt = FALSE;int m_opt = FALSE;int o_opt = FALSE;int p_opt = FALSE;int q_opt = FALSE;int r_opt = FALSE;int u_opt = FALSE;int v_opt = FALSE;int z_opt = FALSE;int A_opt = FALSE;int C_opt = FALSE;int M_opt = FALSE;int N_opt = FALSE;int S_opt = FALSE;int V_opt = FALSE;int Depend_opt = FALSE;int Interact_opt = FALSE;int Stagein_opt = FALSE;int Stageout_opt = FALSE;int Grouplist_opt = FALSE;char *v_value = NULL;char *set_dir_prefix(prefix, diropt)char *prefix;int diropt;{ char *s; if ( notNULL(prefix) ) return(prefix); else if ( diropt == TRUE ) return(""); else if ( ( s = getenv("PBS_DPREFIX") ) != NULL ) return(s); else return(PBS_DPREFIX_DEFAULT);}intisexecutable(s)char *s;{ char *c; c = s; if ((*c == ':') || ((*c == '#') && (*(c+1) == '!'))) return FALSE; while ( isspace(*c) ) c++; if ( notNULL(c) ) return ( *c != '#' ); return FALSE;}char *ispbsdir(s, prefix)char *s;char *prefix;{ char *it; int l; it = s; while (isspace(*it)) it++; l = strlen(prefix); if ( l > 0 && strncmp(it, prefix, l) == 0 ) return(it+l); else return((char *)NULL);}voidmake_argv(argc, argv, line)int *argc;char *argv[];char *line;{ char *l, *b, *c; char buffer[4096]; int len; char quote; *argc = 0; argv[(*argc)++] = "scriptload"; l = line; b = buffer; while ( isspace(*l) ) l++; c = l; while ( *c != '\0' ) { if ((*c == '"') || (*c == '\'')) { quote = *c; c++; while ((*c != quote) && *c) *b++ = *c++; if ( *c == '\0' ) { fprintf(stderr, "scriptload: unmatched %c\n", *c); exit(1); } c++; } else if ( *c == '\\' ) { c++; *b++ = *c++; } else if ( isspace(*c) ) { len = c - l; if ( argv[*argc] != NULL ) free(argv[*argc]); argv[*argc] = (char *) malloc(len + 1); if ( argv[*argc] == NULL ) { fprintf(stderr, "scriptload: out of memory\n"); exit(2); } *b = '\0'; strcpy(argv[(*argc)++], buffer); while ( isspace(*c) ) c++; l = c; b = buffer; } else *b++ = *c++; } if ( c != l ) { len = c - l; if ( argv[*argc] != NULL ) free(argv[*argc]); argv[*argc] = (char *) malloc(len + 1); if ( argv[*argc] == NULL ) { fprintf(stderr, "scriptload: out of memory\n"); exit(2); } *b = '\0'; strcpy(argv[(*argc)++], buffer); }}intprocess_opts(argc, argv, pass)int argc;char **argv;int pass;{ int i; int c; int errflg = 0; int passet; time_t after; char *keyword; char *valuewd; char *pc; char *pdepend;#if !defined(PBS_NO_POSIX_VIOLATION)#define GETOPT_ARGS "a:A:c:C:e:hIj:k:l:m:M:N:o:p:q:r:S:u:v:VW:z"#else#define GETOPT_ARGS "a:A:c:C:e:hj:k:l:m:M:N:o:p:q:r:S:u:v:VW:z"#endif /* PBS_NO_POSIX_VIOLATION */#define MAX_RES_LIST_LEN 64/* The following macro, together the value of passet (pass + 1) is used *//* to enforce the following rules: 1. option on the command line take *//* precedence over those in script directives. 2. With in the command *//* line or within the script, the last occurance of an option takes *//* precedence over the earlier occurance. */#define if_cmd_line(x) if( (pass==0)||(x!=1) ) passet = pass + 1; if ( pass > 0 ) {#ifdef linux optind = 0; /* prime getopt's starting point */#else optind = 1; /* prime getopt's starting point */#endif } while ((c = getopt(argc, argv, GETOPT_ARGS )) != EOF) { switch (c) { case 'a': if_cmd_line(a_opt) { a_opt = passet; if ( (after = cvtdate(optarg)) < 0 ) { fprintf(stderr, "scriptload: illegal -a value\n"); errflg++; break; } printf("%s = %s\n", ATTR_a, ctime(&after)); } break; case 'A': if_cmd_line(A_opt) { A_opt = passet; printf("%s = %s\n", ATTR_A, optarg); } break; case 'c': if_cmd_line(c_opt) { c_opt = passet; while ( isspace((int)*optarg) ) optarg++; if ( strlen(optarg) == 0 ) { fprintf(stderr, "scriptload: illegal -c value\n"); errflg++; break; } pc = optarg; if ( strlen(optarg) == 1 ) { if ( *pc != 'n' && *pc != 's' && *pc != 'c' ) { fprintf(stderr, "scriptload: illegal -c value\n"); errflg++; break; } } else { if ( strncmp(optarg, "c=", 2) != 0 ) { fprintf(stderr, "scriptload: illegal -c value\n"); errflg++; break; } pc += 2; if ( *pc == '\0' ) { fprintf(stderr, "scriptload: illegal -c value\n"); errflg++; break; } while ( isdigit(*pc) ) pc++; if ( *pc != '\0' ) { fprintf(stderr, "scriptload: illegal -c value\n"); errflg++; break; } } printf("%s = %s\n", ATTR_c, optarg); } break; case 'C': if_cmd_line(C_opt) { C_opt = passet; strcpy(dir_prefix, optarg); } break; case 'e': if_cmd_line(e_opt) { e_opt = passet; if ( prepare_path(optarg, path_out) == 0 ) { printf("%s = %s\n", ATTR_e, path_out); } else { fprintf(stderr, "scriptload: illegal -e value\n"); errflg++; } } break; case 'h': if_cmd_line(h_opt) { h_opt = passet; printf("%s = %s\n", ATTR_h, "u"); } break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -