Example #1
0
void
destroy_method_infos(method_info_t **mis)
{
	int i;

	for (i = 0; i < NUM_METHODS; i++) {
		destroy_method_info(mis[i]);
		mis[i] = NULL;
	}
}
Example #2
0
/*
 * Transforms the properties read from the repository for a method into a
 * method_info_t and returns a pointer to it. If expansion of the exec
 * property fails, due to an invalid string or memory allocation failure,
 * NULL is returned and exec_invalid is set appropriately to indicate whether
 * it was a memory allocation failure or an invalid exec string.
 */
static method_info_t *
create_method_info(const inetd_prop_t *mprops, boolean_t *exec_invalid)
{
	method_info_t	*ret;
	int		i;

	debug_msg("Entering create_method_info");

	if ((ret = calloc(1, sizeof (method_info_t))) == NULL)
		goto alloc_fail;

	/* Expand the exec string. */
	if ((i = wordexp(get_prop_value_string(mprops, PR_EXEC_NAME),
	    &ret->exec_args_we, WRDE_NOCMD|WRDE_UNDEF)) != 0) {
		if (i == WRDE_NOSPACE)
			goto alloc_fail;

		*exec_invalid = B_TRUE;
		free(ret);
		return (NULL);
	}

	if ((ret->exec_path = strdup(ret->exec_args_we.we_wordv[0])) == NULL)
		goto alloc_fail;

	if (mprops[MP_ARG0].ip_error == IVE_VALID) {	/* arg0 is set */
		/*
		 * Keep a copy of arg0 of the wordexp structure so that
		 * wordfree() gets passed what wordexp() originally returned,
		 * as documented as required in the man page.
		 */
		ret->wordexp_arg0_backup = ret->exec_args_we.we_wordv[0];
		if ((ret->exec_args_we.we_wordv[0] =
		    strdup(get_prop_value_string(mprops, PR_ARG0_NAME)))
		    == NULL)
			goto alloc_fail;
	}

	if (mprops[MP_TIMEOUT].ip_error == IVE_VALID) {
		ret->timeout = get_prop_value_count(mprops,
		    SCF_PROPERTY_TIMEOUT);
	} else {
		ret->timeout = DEFAULT_METHOD_TIMEOUT;
	}

	/* exec_invalid not set on success */

	return (ret);

alloc_fail:
	error_msg(strerror(errno));
	destroy_method_info(ret);
	*exec_invalid = B_FALSE;
	return (NULL);
}