Пример #1
0
static void
free_hmc_mansyspats(struct pluginDevice* dev)
{
	if (dev->mansyspats) {
		stonith_free_hostlist(dev->mansyspats);
		dev->mansyspats = NULL;
	}
}
Пример #2
0
/*
 *	SSH Stonith destructor...
 */
static void
ssh_destroy(StonithPlugin *s)
{
	struct pluginDevice* sd = (struct pluginDevice *)s;

	VOIDERRIFWRONGDEV(s);

	sd->pluginid = NOTpluginid;
	if (sd->hostlist) {
		stonith_free_hostlist(sd->hostlist);
		sd->hostlist = NULL;
	}
	sd->hostcount = -1;
	FREE(sd);
}
Пример #3
0
/*
 *	Meat Stonith destructor...
 */
static void
meatware_destroy(StonithPlugin *s)
{
	struct pluginDevice* nd;

	VOIDERRIFWRONGDEV(s);
	nd = (struct pluginDevice *)s;

	nd->pluginid = NOTpluginID;
	if (nd->hostlist) {
		stonith_free_hostlist(nd->hostlist);
		nd->hostlist = NULL;
	}
	nd->hostcount = -1;
	FREE(nd);
}
Пример #4
0
/*
 *	RILOE Stonith destructor...
 */
static void
riloe_destroy(StonithPlugin *s)
{
	struct pluginDevice* nd;

	if (Debug) {
		LOG(PIL_DEBUG, "%s:called.", __FUNCTION__);
	}

	VOIDERRIFWRONGDEV(s);
	nd = (struct pluginDevice *)s;

	nd->pluginid = NOTriloeID;
	if (nd->hostlist) {
		stonith_free_hostlist(nd->hostlist);
		nd->hostlist = NULL;
	}
	nd->hostcount = -1;
	FREE(nd);
}
Пример #5
0
static int
get_hmc_mansyspats(struct pluginDevice * dev, const char *mansyspats)
{
	char *patscopy;
	int numpats;	
	int i;
	char *tmp;

	if(Debug){
		LOG(PIL_DEBUG, "%s: called, mansyspats=%s\n"
		,	__FUNCTION__, mansyspats);
	}
	
	patscopy = STRDUP(mansyspats);
	if (patscopy == NULL) {
		LOG(PIL_CRIT, "%s: out of memory", __FUNCTION__);
		return S_OOPS;
	}

	numpats = get_num_tokens(patscopy);	
	if (numpats > 0) {
		dev->mansyspats = MALLOC((numpats+1)*sizeof(char *));
		if (dev->mansyspats == NULL) {
			LOG(PIL_CRIT, "%s: out of memory"
			,	__FUNCTION__);
			FREE(patscopy);
			return S_OOPS;
		}

		memset(dev->mansyspats, 0, (numpats+1)*sizeof(char *));

		/* White-space split the output here */
		i = 0;
		tmp = strtok(patscopy, WHITESPACE);
		while (tmp != NULL) {
			dev->mansyspats[i] = STRDUP(tmp);
			if (dev->mansyspats[i] == NULL) {
				LOG(PIL_CRIT, "%s: out of memory"
				,	__FUNCTION__);
				free_hmc_mansyspats(dev);
				dev->mansyspats = NULL;
				FREE(patscopy);
				return S_OOPS;
			}
	
			if(Debug){
				LOG(PIL_DEBUG, "%s: adding pattern %s\n"
				,	__FUNCTION__, dev->mansyspats[i]);
			}

			/* no patterns necessary if all specified */
			if (strcmp(dev->mansyspats[i], "*") == 0) {
				stonith_free_hostlist(dev->mansyspats);
				dev->mansyspats = NULL;
				break;
			}

			i++;
			tmp = strtok(NULL, WHITESPACE);
		}
	}
	FREE(patscopy);
	return S_OK;
}
Пример #6
0
int
main(int argc, char** argv)
{
	char *		cmdname;
	int		rc;
	Stonith *	s;
	const char *	SwitchType = NULL;
	const char *	tmp;
	const char *	optfile = NULL;
	const char *	parameters = NULL;
	int		reset_type = ST_GENERIC_RESET;
	int		verbose = 0;
	int		status = 0;
	int		silent = 0;
	int		listhosts = 0;
	int		listtypes = 0;
	int 		listparanames = 0;

	int		c;
	int		errors = 0;
	int		argcount;
	StonithNVpair	nvargs[MAXNVARG];
	int		nvcount=0;
	int		j;
	int		count = 1;
	int		help = 0;

	if ((cmdname = strrchr(argv[0], '/')) == NULL) {
		cmdname = argv[0];
	}else{
		++cmdname;
	}


	while ((c = getopt(argc, argv, OPTIONS)) != -1) {
		switch(c) {

		case 'c':	count = atoi(optarg);
				if (count < 1) {
					fprintf(stderr
					,	"bad count [%s]\n"
					,	optarg);
					usage(cmdname, 1, NULL);
				}
				break;

		case 'd':	debug++;
				break;

		case 'F':	optfile = optarg;
				break;

		case 'h':	help++;
				break;

		case 'l':	++listhosts;
				break;

		case 'L':	++listtypes;
				break;

		case 'p':	parameters = optarg;
				break;

		case 's':	++silent;
				break;

		case 'S':	++status;
				break;

		case 't':	SwitchType = optarg;
				break;

		case 'T':	if (strcmp(optarg, "on")== 0) {
					reset_type = ST_POWERON;
				}else if (strcmp(optarg, "off")== 0) {
					reset_type = ST_POWEROFF;
				}else if (strcmp(optarg, "reset")== 0) {
					reset_type = ST_GENERIC_RESET;
				}else{
					fprintf(stderr
					,	"bad reset type [%s]\n"
					,	optarg);
					usage(cmdname, 1, NULL);
				}
				break;

		case 'n':	++listparanames;
				break;

		case 'v':	++verbose;
				break;

		default:	++errors;
				break;
		}
	}

	if (help && !errors) {
		usage(cmdname, 0, SwitchType);
	}
	if (debug) {
		PILpisysSetDebugLevel(debug);
	}
	if (optfile && parameters) {
		fprintf(stderr
		,	"Cannot include both -F and -p options\n");
		usage(cmdname, 1, NULL);
	}

	/*
	 *	Process name=value arguments on command line...
	 */
	for (;optind < argc; ++optind) {
		char *	eqpos;
		if ((eqpos=strchr(argv[optind], EQUAL)) == NULL) {
			break;
		}
		if (parameters)  {
			fprintf(stderr
			,	"Cannot include both -p and name=value "
			"style arguments\n");
			usage(cmdname, 1, NULL);
		}
		if (optfile)  {
			fprintf(stderr
			,	"Cannot include both -F and name=value "
			"style arguments\n");
			usage(cmdname, 1, NULL);
		}
		if (nvcount >= MAXNVARG) {
			fprintf(stderr
			,	"Too many name=value style arguments\n");
			exit(1);
		}
		nvargs[nvcount].s_name = argv[optind];
		*eqpos = EOS;
		nvargs[nvcount].s_value = eqpos+1;
		nvcount++;
	}
	nvargs[nvcount].s_name = NULL;
	nvargs[nvcount].s_value = NULL;

	argcount = argc - optind;

	if (!(argcount == 1 || (argcount < 1
	&&	(status||listhosts||listtypes||listparanames)))) {
		++errors;
	}

	if (errors) {
		usage(cmdname, 1, NULL);
	}

	if (listtypes) {
		char **	typelist;

		typelist = stonith_types();
		if (typelist == NULL) {
			syslog(LOG_ERR, "Could not list Stonith types.");
		}else{
			char **	this;

			for(this=typelist; *this; ++this) {
				printf("%s\n", *this);
			}
		}
		exit(0);
	}

	if (SwitchType == NULL) {
		fprintf(stderr,	"Must specify device type (-t option)\n");
		usage(cmdname, 1, NULL);
	}

	s = stonith_new(SwitchType);
	if (!listparanames && optfile == NULL && parameters == NULL && nvcount == 0) {
		const char**	names;
		int		needs_parms = 1;

		if (s != NULL && (names = stonith_get_confignames(s)) != NULL && names[0] == NULL) {
			needs_parms = 0;
		}

		if (needs_parms) {
			fprintf(stderr
			,	"Must specify either -p option, -F option or "
			"name=value style arguments\n");
			if (s != NULL) {
				stonith_delete(s); 
			}
			usage(cmdname, 1, NULL);
		}
	}

#ifndef LOG_PERROR
#	define LOG_PERROR	0
#endif
	openlog(cmdname, (LOG_CONS|(silent ? 0 : LOG_PERROR)), LOG_USER);
	if (s == NULL) {
		syslog(LOG_ERR, "Invalid device type: '%s'", SwitchType);
		exit(S_OOPS);
	}
	if (debug) {
		stonith_set_debug(s, debug);
	}

	if (listparanames) {
		const char**	names;
		int		i;
		names = stonith_get_confignames(s);

		if (names != NULL) {
			for (i=0; names[i]; ++i) {
				printf("%s  ", names[i]);
			}
		}
		printf("\n");
		stonith_delete(s); 
		s=NULL;
		exit(0);
	}

	/* Old STONITH version 1 stuff... */
	if (optfile) {
		/* Configure the Stonith object from a file */
		if ((rc=stonith_set_config_file(s, optfile)) != S_OK) {
			syslog(LOG_ERR
			,	"Invalid config file for %s device."
			,	SwitchType);
#if 0
			syslog(LOG_INFO, "Config file syntax: %s"
			,	s->s_ops->getinfo(s, ST_CONF_FILE_SYNTAX));
#endif
			stonith_delete(s); s=NULL;
			exit(S_BADCONFIG);
		}
	}else if (parameters) {
		/* Configure Stonith object from the -p argument */
		StonithNVpair *		pairs;
		if ((pairs = stonith1_compat_string_to_NVpair
		     (	s, parameters)) == NULL) {
			fprintf(stderr
			,	"Invalid STONITH -p parameter [%s]\n"
			,	parameters);
			stonith_delete(s); s=NULL;
			exit(1);
		}
		if ((rc = stonith_set_config(s, pairs)) != S_OK) {
			fprintf(stderr
			,	"Invalid config info for %s device"
			,	SwitchType);
		}
	}else{
		/*
		 *	Configure STONITH device using cmdline arguments...
		 */
		if ((rc = stonith_set_config(s, nvargs)) != S_OK) {
			const char**	names;
			int		j;
			fprintf(stderr
			,	"Invalid config info for %s device\n"
			,	SwitchType);

			names = stonith_get_confignames(s);

			if (names != NULL) {
				fprintf(stderr
				,	"Valid config names are:\n");
			
				for (j=0; names[j]; ++j) {
					fprintf(stderr
					,	"\t%s\n", names[j]);
				}
			}
			stonith_delete(s); s=NULL;
			exit(rc);
		}
	}


	for (j=0; j < count; ++j) {
		rc = stonith_get_status(s);

		if ((tmp = stonith_get_info(s, ST_DEVICEID)) == NULL) {
			SwitchType = tmp;
		}

		if (status && !silent) {
			if (rc == S_OK) {
				syslog(LOG_ERR, "%s device OK.", SwitchType);
			}else{
				/* Uh-Oh */
				syslog(LOG_ERR, "%s device not accessible."
				,	SwitchType);
			}
		}

		if (listhosts) {
			char **	hostlist;

			hostlist = stonith_get_hostlist(s);
			if (hostlist == NULL) {
				syslog(LOG_ERR, "Could not list hosts for %s."
				,	SwitchType);
			}else{
				char **	this;

				for(this=hostlist; *this; ++this) {
					printf("%s\n", *this);
				}
				stonith_free_hostlist(hostlist);
			}
		}

		if (optind < argc) {
			char *nodename;
			nodename = g_strdup(argv[optind]);
			g_strdown(nodename);
			rc = stonith_req_reset(s, reset_type, nodename);
			g_free(nodename);
		}
	}
	stonith_delete(s); s = NULL;
	return(rc);
}