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

📄 rcd_serial.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
	*/	copy = STRDUP(info);	if (!copy) {		LOG(PIL_CRIT, "%s: out of memory!", __FUNCTION__);		return S_OOPS;	}	/* Grab the hostname */	token = strtok (copy, WHITESPACE);	if (!token) {		LOG(PIL_CRIT, "%s: Can't find hostname on config line '%s'",			pluginid, info);		ret = S_BADCONFIG;		goto token_error;	}	if ((rcd->hostlist = (char **)MALLOC(2*sizeof(char*))) == NULL) {		LOG(PIL_CRIT, "%s: out of memory!", __FUNCTION__);		ret = S_OOPS;		goto token_error;	}	memset(rcd->hostlist, 0, 2*sizeof(char*));	rcd->hostcount = 0;	rcd->hostlist[0] = STRDUP(token);	if (!rcd->hostlist[0]) {		LOG(PIL_CRIT, "%s: out of memory!", __FUNCTION__);		ret = S_OOPS;		goto token_error;	}	g_strdown(rcd->hostlist[0]);	rcd->hostcount = 1;	/* Grab the device name */	token = strtok (NULL, WHITESPACE);	if (!token) {		LOG(PIL_CRIT, "%s: Can't find device on config line '%s'",			pluginid, info);		ret = S_BADCONFIG;		goto token_error;	}	rcd->device = STRDUP(token);	if (!rcd->device) {		LOG(PIL_CRIT, "%s: out of memory!", __FUNCTION__);		ret = S_OOPS;		goto token_error;	}	/* Grab the signal name */	token = strtok (NULL, WHITESPACE);	if (!token) {		LOG(PIL_CRIT, "%s: Can't find signal on config line '%s'",			pluginid, info);		ret = S_BADCONFIG;		goto token_error;	}	rcd->signal = STRDUP(token);	if (!rcd->signal) {		LOG(PIL_CRIT, "%s: out of memory!", __FUNCTION__);		ret = S_OOPS;		goto token_error;	}        if (strcmp(rcd->signal, "rts") && strcmp(rcd->signal, "dtr")) {		LOG(PIL_CRIT, "%s: Invalid signal name on config line '%s'",			pluginid, info);		ret = S_BADCONFIG;		goto token_error;        }	/* Grab the duration in millisecs */	token = strtok (NULL, WHITESPACE);	if (!token) {		LOG(PIL_CRIT, "%s: Can't find msduration on config line '%s'",			pluginid, info);		ret = S_BADCONFIG;		goto token_error;	}	rcd->msduration = strtol(token, &endptr, 0);	if (*token == 0 || *endptr != 0 || rcd->msduration < 1) {		LOG(PIL_CRIT, "%s: Invalid msduration on config line '%s'",			pluginid, info);		ret = S_BADCONFIG;		goto token_error;	}	/* Make sure nothing extra provided */	token = strtok (NULL, WHITESPACE);	if (token) {		LOG(PIL_CRIT, "%s: Too many params on config line '%s'",			pluginid, info);		ret = S_BADCONFIG;		goto token_error;	}        /* free our private copy of the string we've been destructively           parsing with strtok()        */        FREE(copy);        return S_OK;token_error:        FREE(copy);        return(ret);}/* *	At last, we really do it! I don't know what the request argument *	is so am just ignoring it... */static intrcd_serial_reset_req(StonithPlugin * s, int request, const char * host){	struct pluginDevice*	rcd;	int fd;	int sigbit;	struct itimerval timer;	const char * err;	char* shost;		ERRIFWRONGDEV(s,S_OOPS);	rcd = (struct pluginDevice *) s;	/* check that host matches */	if ((shost = STRDUP(host)) == NULL) {		LOG(PIL_CRIT, "%s: strdup failed", __FUNCTION__);		return(S_OOPS);	}	g_strdown(shost);	if (strcmp(host, rcd->hostlist[0])) {		LOG(PIL_CRIT, "%s: host '%s' not in hostlist.",			__FUNCTION__, host);		free(shost);		return(S_BADHOST);	}	free(shost);	/* Set the appropriate bit for the signal */	sigbit = *(rcd->signal)=='r' ? TIOCM_RTS : TIOCM_DTR;	/* Set up the timer */	timer.it_interval.tv_sec  = 0;	timer.it_interval.tv_usec = 0;	timer.it_value.tv_sec  =  rcd->msduration / 1000;	timer.it_value.tv_usec = (rcd->msduration % 1000) * 1000;	/* Open the device */	if ((fd = RCD_open_serial_port(rcd->device)) == -1) {#ifdef HAVE_STRERROR                err = strerror(errno);#else		err = sys_errlist[errno];#endif		LOG(PIL_CRIT, "%s: open of %s failed - %s",			__FUNCTION__, rcd->device, err);		return(S_OOPS);	}	/* Start the timer */	RCD_alarm_handler(0);#ifdef RCD_NOPAUSE	RCD_alarmcaught = 0;#endif	setitimer(ITIMER_REAL, &timer, 0);        /* Set the line high */        ioctl(fd, TIOCMBIS, &sigbit);        /* Wait for the alarm signal */#ifdef RCD_NOPAUSE        while(!RCD_alarmcaught) ioctl(fd, TIOCMBIS, &sigbit);#else        pause();#endif        /* Clear the line low */        ioctl(fd, TIOCMBIC, &sigbit);        /* Close the port */	if (RCD_close_serial_port(fd) != 0) {                err = strerror(errno);		LOG(PIL_CRIT, "%s: close of %s failed - %s",			__FUNCTION__, rcd->device, err);		return(S_OOPS);	}	LOG(PIL_INFO,"%s: %s", _("Host rcd_serial-reset"), host);	return S_OK;}/* *	Parse the information in the given string  *	and stash it away... */static intrcd_serial_set_config(StonithPlugin* s, StonithNVpair *list){	char	RCD_SERIALline[MAX_RCD_SERIALLINE];	struct pluginDevice*	rcd;	StonithNamesToGet	namestoget [] =	{	{ST_HOSTLIST,	NULL}	,	{ST_TTYDEV,	NULL}	,	{ST_DTRRTS,	NULL}	,	{ST_MSDURATION,	NULL}	,	{NULL,		NULL}	};	int rc = 0;	ERRIFWRONGDEV(s,S_OOPS);	rcd = (struct pluginDevice*) s;	LOG(PIL_DEBUG, "%s:called", __FUNCTION__);		if ((rc = OurImports->GetAllValues(namestoget, list)) != S_OK) {		LOG(PIL_DEBUG, "get all value failed");		return rc;	}	if ((snprintf(RCD_SERIALline, MAX_RCD_SERIALLINE, "%s %s %s %s", 		namestoget[0].s_value, namestoget[1].s_value, namestoget[2].s_value, namestoget[3].s_value)) <= 0) {		LOG(PIL_CRIT, "Copy parameter to RCD_SERIALline failed");	}		return (RCD_SERIAL_parse_config_info(rcd, RCD_SERIALline));}/* * Return STONITH config vars */static const char**rcd_serial_get_confignames(StonithPlugin* p){	static const char *	RcdParams[] = {ST_HOSTLIST, ST_TTYDEV, ST_DTRRTS, ST_MSDURATION,  NULL };	return RcdParams;}/* * Return STONITH info string */static const char *rcd_serial_getinfo(StonithPlugin * s, int reqtype){	struct pluginDevice* rcd;	char *		ret;	ERRIFWRONGDEV(s,NULL);	/*	 *	We look in the ST_TEXTDOMAIN catalog for our messages	 */	rcd = (struct pluginDevice *)s;	switch (reqtype) {		case ST_DEVICEID:			ret = _(DEVICE);			break;		case ST_DEVICEDESCR:			ret = _("RC Delayed Serial STONITH Device\n"			"This device can be constructed cheaply from"			" readily available components,\n"			"with sufficient expertise and testing.\n"			"See README.rcd_serial for circuit diagram.\n");			break;		default:			ret = NULL;			break;	}	return ret;}/* *	RCD_SERIAL Stonith destructor... */static voidrcd_serial_destroy(StonithPlugin *s){	struct pluginDevice* rcd;	VOIDERRIFWRONGDEV(s);	rcd = (struct pluginDevice *)s;	rcd->pluginid = NOTrcd_serialID;	if (rcd->hostlist) {		stonith_free_hostlist(rcd->hostlist);		rcd->hostlist = NULL;	}	rcd->hostcount = -1;	if (rcd->device) {		FREE(rcd->device);	}	if (rcd->signal) {		FREE(rcd->signal);	}	FREE(rcd);}/* * Create a new RCD_Serial Stonith device. * Too bad this function can't be static. (Hmm, weird, it _is_ static?) */static StonithPlugin *rcd_serial_new(void){	struct pluginDevice*	rcd = MALLOCT(struct pluginDevice);	if (rcd == NULL) {		LOG(PIL_CRIT, "out of memory");		return(NULL);	}	memset(rcd, 0, sizeof(*rcd));	rcd->pluginid = pluginid;	rcd->hostlist = NULL;	rcd->hostcount = -1;	rcd->device = NULL;	rcd->signal = NULL;	rcd->msduration = 0;	rcd->sp.s_ops = &rcd_serialOps;	return &(rcd->sp);}

⌨️ 快捷键说明

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