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

📄 rm.c

📁 openPBS的开放源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/**         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 */#if !defined(_BSD) && defined(_AIX)   /* this is needed by AIX */#define	_BSD	1#endif#include	<stdio.h>#include	<unistd.h>#include	<stdlib.h>#include	<errno.h>#include	<string.h>#include	<fcntl.h>#include	<sys/types.h>#include	<sys/socket.h>#include	<sys/param.h>#include	<sys/time.h>#include	<netdb.h>#include	<netinet/in.h>#include	<arpa/inet.h>#include	"pbs_ifl.h"#include	"net_connect.h"#include	"resmon.h"#include	"log.h"#include	"dis.h"#include	"dis_init.h"#include	"rm.h"#if	RPP#include	"rpp.h"#endifstatic	char	ident[] = "@(#) $RCSfile: rm.c,v $ $Revision: 2.2.6.4 $";static	int	full = 1;/***	This is the structure used to keep track of the resource**	monitor connections.  Each entry is linked into as list**	pointed to by "outs".  If len is -1, no**	request is active.  If len is -2, a request has been**	sent and is waiting to be read.  If len is > 0, the number**	indicates how much data is waiting to be sent.*/struct	out {	int	stream;	int	len;	struct	out	*next;};#define	HASHOUT	32static	struct	out	*outs[HASHOUT];/***	Create an "out" structure and put it in the hash table.*/staticintaddrm(stream)     int	stream;{	struct	out		*op, **head;	if ((op = (struct out *)malloc(sizeof(struct out))) == NULL) {		pbs_errno = errno;		return -1;	}	head = &outs[stream % HASHOUT];	op->stream = stream;	op->len = -1;	op->next = *head;	*head = op;	return 0;}#if	RPPstaticvoidfuncs_dis()		/* The equivalent of DIS_tcp_funcs() */{	if (dis_getc != rpp_getc) {		dis_getc = (int (*)(int))rpp_getc;		dis_puts = (int (*)(int, const char *, size_t))rpp_write;		dis_gets = (int (*)(int, char *, size_t))rpp_read;		disr_commit = (int (*)(int, int))rpp_rcommit;		disw_commit = (int (*)(int, int))rpp_wcommit;	}}#define	setup_dis(x)	funcs_dis()	/* RPP doesn't need reset */#define	close_dis(x)	rpp_close(x)#define	flush_dis(x)	rpp_flush(x)#else#define	funcs_dis()	DIS_tcp_funcs()#define	setup_dis(x)	DIS_tcp_setup(x)#define	close_dis(x)	close(x)#define	flush_dis(x)	DIS_tcp_wflush(x)#endif/***	Connects to a resource monitor and returns a file descriptor to**	talk to it.  If port is zero, use default port.*/intopenrm(host, port)     char	*host;     unsigned int port;{	int			stream;	static	int		first = 1;	static	unsigned int	gotport = 0;	DBPRT(("openrm: host %s port %u\n", host, port))	pbs_errno = 0;	if (port == 0) {		if (gotport == 0) {			gotport = get_svrport(PBS_MANAGER_SERVICE_NAME, "tcp",				   	PBS_MANAGER_SERVICE_PORT);			DBPRT(("found port %u\n", gotport))		}		port = gotport;	}#if	RPP	if (first) {		int	tryport = IPPORT_RESERVED;		first = 0;		while (--tryport > 0) {			if (rpp_bind(tryport) != -1)				break;			if ((errno != EADDRINUSE) && (errno != EADDRNOTAVAIL))				break;		}	}	stream = rpp_open(host, port);#else	if ((stream = socket(AF_INET, SOCK_STREAM, 0)) != -1) {		int	tryport = IPPORT_RESERVED;		struct	sockaddr_in	addr;		struct	hostent		*hp;		if ((hp = gethostbyname(host)) == NULL) {			DBPRT(("host %s not found\n", host))			pbs_errno = ENOENT;			return -1;		}		memset(&addr, '\0', sizeof(addr));		addr.sin_family = AF_INET;		addr.sin_addr.s_addr = htonl(INADDR_ANY);		while (--tryport > 0) {			addr.sin_port = htons((u_short)tryport);			if (bind(stream, (struct sockaddr *)&addr,					sizeof(addr)) != -1)				break;			if ((errno != EADDRINUSE) && (errno != EADDRNOTAVAIL))				break;		}		memset(&addr, '\0', sizeof(addr));		addr.sin_family = hp->h_addrtype;		addr.sin_port = htons((unsigned short)port);		memcpy(&addr.sin_addr, hp->h_addr, hp->h_length);		if (connect(stream, (struct sockaddr *)&addr,				sizeof(addr)) == -1) {			pbs_errno = errno;			close(stream);			return -1;		}	}#endif	pbs_errno = errno;	if (stream < 0)		return -1;	if (addrm(stream) == -1) {		pbs_errno = errno;		close_dis(stream);		return -1;	}	return stream;}/***	Routine to close a connection to a resource monitor**	and free the "out" structure.**	Return 0 if all is well, -1 on error.*/staticintdelrm(stream)     int	stream;{	struct	out	*op, *prev = NULL;	for (op=outs[stream % HASHOUT]; op; op=op->next) {		if (op->stream == stream)			break;		prev = op;	}	if (op) {		close_dis(stream);		if (prev)			prev->next = op->next;		else			outs[stream % HASHOUT] = op->next;		free(op);		return 0;	}	return -1;}/***	Internal routine to find the out structure for a stream number.**	Return non NULL if all is well, NULL on error.*/staticstruct	out *findout(stream)     int	stream;{	struct	out	*op;	for (op=outs[stream % HASHOUT]; op; op=op->next) {		if (op->stream == stream)			break;	}	if (op == NULL)		pbs_errno = ENOTTY;	return op;}staticintstartcom(stream, com)     int	stream;     int	com;{	int	ret;	setup_dis(stream);	ret = diswsi(stream, RM_PROTOCOL);	if (ret == DIS_SUCCESS) {		ret = diswsi(stream, RM_PROTOCOL_VER);		if (ret == DIS_SUCCESS)			ret = diswsi(stream, com);	}	if (ret != DIS_SUCCESS) {		DBPRT(("startcom: diswsi error %s\n", dis_emsg[ret]))		pbs_errno = errno;	}	return ret;}/***	Internal routine to compose and send a "simple" command.**	This means anything with a zero length body.**	Return 0 if all is well, -1 on error.*/staticintsimplecom(stream, com)     int	stream;     int	com;{	struct	out	*op;	if ((op = findout(stream)) == NULL)		return -1;	op->len = -1;	if (startcom(stream, com) != DIS_SUCCESS) {		close_dis(stream);		return -1;	}	if (flush_dis(stream) == -1) {		pbs_errno = errno;		DBPRT(("simplecom: flush error %d\n", pbs_errno))		close_dis(stream);		return -1;	}#if	RPP	(void)rpp_eom(stream);#endif	return 0;}/***	Internal routine to read the return value from a command.**	Return 0 if all is well, -1 on error.*/staticintsimpleget(stream)     int	stream;{	int	ret, num;	num = disrsi(stream, &ret);	if (ret != DIS_SUCCESS) {		DBPRT(("simpleget: %s\n", dis_emsg[ret]))		pbs_errno = errno ? errno : EIO;		close_dis(stream);		return -1;	}	if (num != RM_RSP_OK) {#ifdef	ENOMSG		pbs_errno = ENOMSG;#else		pbs_errno = EINVAL;#endif		return -1;	}	return 0;}/***	Close connection to resource monitor.  Return result 0 if**	all is ok or -1 if not (set pbs_errno).*/int

⌨️ 快捷键说明

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