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

📄 wti_nps.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
			g_strdown(sockname);  			if (strcmp(name, sockname) == 0) {  				ret = sockno;  				sprintf(buf, "%d ", sockno);  				strncat(*outlets, buf, left);  				left = left - 2;  			}  		}  	} while (strlen(NameMapping) > 2 && left > 0);  	return(ret);}static intwti_nps_status(StonithPlugin  *s){	struct pluginDevice*	nps;	int	rc;	if (Debug) {		LOG(PIL_DEBUG, "%s:called.", __FUNCTION__);	}	ERRIFNOTCONFIGED(s,S_OOPS);	nps = (struct pluginDevice*) s;       	if ((rc = NPSRobustLogin(nps) != S_OK)) {		LOG(PIL_CRIT, "%s", _("Cannot log into " DEVICE "."));		return(rc);	}	/* Send "/h" help command and expect back prompt */	SEND(nps->wrfd, "/h\r");	/* Expect "PS>" */	EXPECT(nps->rdfd, Prompt, 5);	return(NPSLogout(nps));}/* *	Return the list of hosts (outlet names) for the devices on this NPS unit */static char **wti_nps_hostlist(StonithPlugin  *s){	char		NameMapping[128];	char*		NameList[64];	unsigned int	numnames = 0;	char **		ret = NULL;	struct pluginDevice*	nps;	if (Debug) {		LOG(PIL_DEBUG, "%s:called.", __FUNCTION__);	}	ERRIFNOTCONFIGED(s,NULL);	nps = (struct pluginDevice*) s;	if (NPS_connect_device(nps) != S_OK) {		return(NULL);	} 	if (NPSRobustLogin(nps) != S_OK) {		LOG(PIL_CRIT, "%s", _("Cannot log into " DEVICE "."));		return(NULL);	}		/* Expect "PS>" */	NULLEXPECT(nps->rdfd, Prompt, 5);		/* The status command output contains mapping of hosts to outlets */	SEND(nps->wrfd, "/s\r");	/* Expect: "-----" so we can skip over it... */	NULLEXPECT(nps->rdfd, Separator, 5);	NULLEXPECT(nps->rdfd, CRNL, 5);		/* Looks Good!  Parse the status output */	do {		int	sockno;		char	sockname[64];		NameMapping[0] = EOS;		NULLSNARF(nps->rdfd, NameMapping, 5);		if (sscanf(NameMapping		,	"%d | %16c",&sockno, sockname) == 2) {			char *	last = sockname+16;			char *	nm;			*last = EOS;			--last;			/* Strip off trailing blanks */			for(; last > sockname; --last) {				if (*last == ' ') {					*last = EOS;				}else{					break;				}			}			if (numnames >= DIMOF(NameList)-1) {				break;			}			if ((nm = strdup(sockname)) == NULL) {				LOG(PIL_CRIT, "out of memory");				return(NULL);			}			g_strdown(nm);			NameList[numnames] = nm;			++numnames;			NameList[numnames] = NULL;		}	} while (strlen(NameMapping) > 2);	if (numnames >= 1) {		ret = (char **)MALLOC((numnames+1)*sizeof(char*));		if (ret == NULL) {			LOG(PIL_CRIT, "out of memory");		}else{			memset(ret, 0, (numnames+1)*sizeof(char*));			memcpy(ret, NameList, (numnames+1)*sizeof(char*));		}	}	(void)NPSLogout(nps);		return(ret);	}/* *	Parse the given configuration information, and stash it away... */static intNPS_parse_config_info(struct pluginDevice* nps, const char * info){	static char dev[1024];	static char passwd[1024];	if (Debug) {		LOG(PIL_DEBUG, "%s:called.", __FUNCTION__);	}	if (nps->config) {		return(S_OOPS);	}	if (sscanf(info, "%s %[^\n\r\t]", dev, passwd) == 2	&&	strlen(passwd) > 1) {		if ((nps->device = strdup(dev)) == NULL) {			LOG(PIL_CRIT, "out of memory");			return(S_OOPS);		}		if ((nps->passwd = strdup(passwd)) == NULL) {			free(nps->device);			nps->device=NULL;			LOG(PIL_CRIT, "out of memory");			return(S_OOPS);		}		nps->config = 1;		return(S_OK);	}	return(S_BADCONFIG);}/* *	Connect to the given NPS device.  We should add serial support here *	eventually... */static intNPS_connect_device(struct pluginDevice * nps){	char	TelnetCommand[256];		snprintf(TelnetCommand, sizeof(TelnetCommand)	,	"exec telnet %s 2>/dev/null", nps->device);		nps->pid=STARTPROC(TelnetCommand, &nps->rdfd, &nps->wrfd);	if (nps->pid <= 0) {			return(S_OOPS);	}	return(S_OK);}/* *	Reset the given host on this Stonith device.   */static intwti_nps_reset_req(StonithPlugin * s, int request, const char * host){	int	rc = 0;	int	lorc = 0;	struct pluginDevice*	nps;		if (Debug) {		LOG(PIL_DEBUG, "%s:called.", __FUNCTION__);	}	ERRIFNOTCONFIGED(s,S_OOPS);	nps = (struct pluginDevice*) s;        if ((rc = NPSRobustLogin(nps)) != S_OK) {		LOG(PIL_CRIT, "%s", _("Cannot log into " DEVICE "."));        }else{	        char *outlets;		char *shost;		int noutlet;     		if ((shost = STRDUP(host)) == NULL) {			LOG(PIL_CRIT, "strdup failed in NPS_reset_host");			return(S_OOPS);		}		g_strdown(shost);		noutlet = NPSNametoOutlet(nps, host, &outlets);		free(shost);		if (noutlet < 1) {			LOG(PIL_WARN, "%s %s %s[%s]"			,	nps->idinfo,	nps->unitid			,	_("doesn't control host [%s]."),	host);			Stonithkillcomm(&nps->rdfd, &nps->wrfd, &nps->pid);			return(S_BADHOST);		}		switch(request) {#if defined(ST_POWERON) && defined(ST_POWEROFF)		case ST_POWERON:		case ST_POWEROFF:			rc = NPS_onoff(nps, outlets, host, request);			if (outlets != NULL) {			  free(outlets);			  outlets = NULL;			}			break;#endif		case ST_GENERIC_RESET:			rc = NPSReset(nps, outlets, host);			break;			if (outlets != NULL) {			  free(outlets);			  outlets = NULL;			}		default:			rc = S_INVAL;						if (outlets != NULL) {			  free(outlets);			  outlets = NULL;			}			break;		}	}	lorc = NPSLogout(nps);	return(rc != S_OK ? rc : lorc);}/* *	Parse the information in the given string, *	and stash it away... */static intwti_nps_set_config(StonithPlugin * s, StonithNVpair *list){	char	WTIpluginid[MAX_WTIPLUGINID];	struct pluginDevice*	nps;	StonithNamesToGet	namestoget [] =	{	{ST_IPADDR,	NULL}	,	{ST_PASSWD,	NULL}	,	{NULL,		NULL}	};	int	rc;	if (Debug) {		LOG(PIL_DEBUG, "%s: called.\n", __FUNCTION__);	}	ERRIFWRONGDEV(s,S_OOPS);	nps = (struct pluginDevice*) s;	if ((rc = OurImports->GetAllValues(namestoget, list)) != S_OK) {		return rc;	}		if ((snprintf(WTIpluginid, MAX_WTIPLUGINID, "%s %s", 		namestoget[0].s_value, namestoget[1].s_value)) <= 0) {		LOG(PIL_CRIT, "Can not copy parameter to WTIpluginid");	}		return (NPS_parse_config_info(nps,WTIpluginid));	}/* * Return the Stonith plugin configuration parameter  * */static const char**wti_nps_get_confignames(StonithPlugin * p){	static	const char * names[] =  { ST_IPADDR , ST_PASSWD , NULL};	if (Debug) {		LOG(PIL_DEBUG, "%s: called.", __FUNCTION__);	}	return names;}/* * Get info about  the stonith device  * */static const char *wti_nps_get_info(StonithPlugin * s, int reqtype){	struct pluginDevice* nps;	const char *	ret;	if (Debug) {		LOG(PIL_DEBUG, "%s: called.", __FUNCTION__);	}	ERRIFWRONGDEV(s,NULL);	/*	 *	We look in the ST_TEXTDOMAIN catalog for our messages	 */	nps = (struct pluginDevice *)s;	switch (reqtype) {		case ST_DEVICEID:			ret = nps->idinfo;			break;		case ST_DEVICEDESCR:			ret = _("Western Telematic (WTI) Network Power Switch Devices (NPS-xxx)\n" 			"Also supports the WTI Telnet Power Switch Devices (TPS-xxx)\n" 			"NOTE: The WTI Network Power Switch, accepts only "			"one (telnet) connection/session at a time.");			break;		default:			ret = NULL;			break;	}	return ret;}/* *	WTI NPS Stonith destructor... */static voidwti_nps_destroy(StonithPlugin *s){	struct pluginDevice* nps;	if (Debug) {		LOG(PIL_DEBUG, "%s: called.", __FUNCTION__);	}	VOIDERRIFWRONGDEV(s);	nps = (struct pluginDevice *)s;	nps->pluginid = NOTnpsid;	Stonithkillcomm(&nps->rdfd, &nps->wrfd, &nps->pid);	if (nps->device != NULL) {		FREE(nps->device);		nps->device = NULL;	}	if (nps->passwd != NULL) {		FREE(nps->passwd);		nps->passwd = NULL;	}	if (nps->idinfo != NULL) {		FREE(nps->idinfo);		nps->idinfo = NULL;	}	if (nps->unitid != NULL) {		FREE(nps->unitid);		nps->unitid = NULL;	}}/* Create a new BayTech Stonith device. */static StonithPlugin *wti_nps_new(void){	struct pluginDevice*	nps = MALLOCT(struct pluginDevice);	if (Debug) {		LOG(PIL_DEBUG, "%s: called.", __FUNCTION__);	}	if (nps == NULL) {		LOG(PIL_CRIT, "out of memory");		return(NULL);	}	memset(nps, 0, sizeof(*nps));	nps->pluginid = pluginid;	nps->pid = -1;	nps->rdfd = -1;	nps->wrfd = -1;	nps->config = 0;	nps->device = NULL;	nps->passwd = NULL;	nps->idinfo = NULL;	nps->unitid = NULL;	REPLSTR(nps->idinfo, DEVICE);	REPLSTR(nps->unitid, "unknown");	nps->sp.s_ops = &wti_npsOps;	return &(nps->sp);}

⌨️ 快捷键说明

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