/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Utility functions used by all of libpower
*/
#include <stdlib.h>
#include <strings.h>
#include <ctype.h>
#include <libnvpair.h>
#include <libpower.h>
#include <libpower_impl.h>
void *, uint_t);
const char *, data_type_t, void *, uint_t);
static int match_pgname(nvlist_t *, const char *);
/*
* Add a property and value to a result set to be returned to a caller of
* libpower. The result list has the structure:
*
* Name Type Description
* ------------------- ------ -------------------------------------
* property_name nvlist The list of available values and
* other information about the
* property. See below for the structure
* of this list.
*
* Name Type Description
* ------------------- ------ -------------------------------------
* PM_PROP_PGNAME string The name of the SMF property
* group to which the property belongs
* other information about the
* property.
*
* PM_AUTHORITY_SMF_STR varies The value of the property from SMF.
* Optional.
*
* PM_AUTHORITY_CURRENT_STR
* varies The value of the property in use by
* the kernel.
* Optional.
*
* PM_AUTHORITY_PLATFORM_STR
* varies The value of the property contained
* in the platform.
* Optional.
*/
{
errno = 0;
return (PM_ERROR_INVALID_ARGUMENT);
}
/* Allocate a new result list if necessary */
if (errno != 0) {
return (PM_ERROR_NVLIST);
}
}
/* Get the list of values for this property from the result set */
err = PM_SUCCESS;
/*
* This property does not exist in the result set. Add it
* to the result
*/
} else {
/*
* The property exists. Update it with the data from the new
* authority.
*/
if (err == PM_ERROR_MISSING_PROPERTY_VALUE &&
authority == PM_AUTHORITY_SMF) {
"%s property %s: %s\n", __FUNCTION__,
/*
* Some properties in SMF may have no value. This is
* valid, but the property is intentionally not added
* to the result set.
*/
errno = 0;
err = PM_SUCCESS;
}
}
return (err);
}
/*
* Create a new property entry in a result set as specified by pm_result_add
*/
static pm_error_t
{
/* Create the new list and add required elements */
if (errno != 0) {
return (PM_ERROR_NVLIST);
}
if (errno != 0) {
return (PM_ERROR_NVLIST);
}
}
/* Add the new value to the list */
if (err == PM_SUCCESS) {
/* Add the property to the main list */
if (errno != 0) {
}
}
}
return (err);
}
/*
* Add a new value to a property value list
*/
static pm_error_t
{
char **sap;
const char *authname;
return (PM_ERROR_MISSING_PROPERTY_VALUE);
}
if (authority == PM_AUTHORITY_INVALID) {
return (PM_ERROR_INVALID_AUTHORITY);
}
/*
* We assume that a property cannot exist in multiple property
* groups and simply add the value from the authority.
*/
errno = 0;
switch (proptype) {
case DATA_TYPE_BOOLEAN_ARRAY:
break;
case DATA_TYPE_BOOLEAN_VALUE:
break;
case DATA_TYPE_UINT64_ARRAY:
break;
case DATA_TYPE_UINT64:
break;
case DATA_TYPE_STRING_ARRAY:
break;
case DATA_TYPE_STRING:
break;
default:
break;
}
if (errno == 0) {
err = PM_SUCCESS;
}
return (err);
}
/*
* Given a result set built by pm_result_add, above, created a new result set
* with just the requested properties.
*/
{
int i;
char *propname;
char *pgname;
return (PM_ERROR_INVALID_ARGUMENT);
}
/*
* Scan each requested property and find the matching entry in the
* result set.
*/
err = PM_SUCCESS;
/* This property entry is invalid. */
"%s null property at index %d\n", __FUNCTION__, i);
continue;
}
/*
* Get the property name and potential group name from the
* current token
*/
/*
* Get the unique property name from the list. There can be
* only one.
*/
if (errno != 0) {
/* The requested property is not found. Error. */
"%s property %s not found in result set\n",
break;
}
/* Now match the property group name */
/*
* This is the only property with this name and the
* group does not match.
*/
"%s property %s/%s not found in result set\n",
break;
}
/*
* Does this property contain an nvpair with the requested
* authority?
*/
if (errno != 0) {
if (authority == PM_AUTHORITY_ALL) {
/*
* This is the special match-everything
* authority. Declare success and add the value
*/
errno = 0;
} else {
/*
* The specified authority does not contain the
* requested property name.
*/
"%s authority %s not found in value list "
"for property %s\n", __FUNCTION__,
break;
}
}
/*
* Merge the requested nvpair into the results and remove
* all the the requested authorities.
*/
}
return (err);
}
/*
* Add a specified nvpair to an existing result set
*/
static pm_error_t
{
err = PM_SUCCESS;
return (PM_ERROR_INVALID_ARGUMENT);
}
if (errno != 0) {
return (PM_ERROR_NVLIST);
}
}
/* Add the property to the result set and retrieve it's value list */
"%s property %s could not be added\n", __FUNCTION__,
propname);
return (PM_ERROR_NVLIST);
}
/*
* Remove any authorities that do not match the requested authority
* from the result set.
*/
err = PM_SUCCESS;
if (authority == PM_AUTHORITY_ALL) {
/* The request is for all available authorities */
continue;
}
/* The request is for this authority. Do not remove */
continue;
}
/*
* Remove this authority from the list of authorities if
* it exists.
*/
"%s nvlist_remove_all returned %d for %s\n",
}
}
return (err);
}
/*
* Property name specifiers may also include a property group designation:
*
* Given a buffer with a property name specifier, determine the location of
* the property name and the property group name. Modify the given buffer
* if necessary.
*/
char *
{
char *propname;
char *sep;
return (NULL);
}
/* Find the potential separator in the buffer */
/* The buffer contains only a potential property name */
} else {
/*
* The buffer contains both a potential property name and a
* potential property group name. Modify the buffer and
* returned both.
*/
*sep = '\0';
"%s property group name has zero length\n",
}
}
return (propname);
}
/*
* Determine if the string in the given buffer is a valid boolean value
*/
{
return (PM_ERROR_INVALID_BOOLEAN);
}
/*
* Compare the given buffer with the valid values for a boolean value.
*/
/* The value is valid and true. */
err = PM_SUCCESS;
/* The value is valid and false. */
err = PM_SUCCESS;
}
return (err);
}
/*
* Determine if the string in the given buffer contains a valid integer value
*/
{
const char *cp;
return (PM_ERROR_INVALID_INTEGER);
}
/* Make sure that all the characters are numbers */
"string \"%s\" is not a valid integer\n", buf);
return (PM_ERROR_INVALID_INTEGER);
}
}
/* Convert the integer to an int64 value */
"integer \"%s\" could not be converted\n", buf);
return (PM_ERROR_INVALID_INTEGER);
}
return (PM_SUCCESS);
}
/*
* Determine if the given property group name matches a given property value
* list by comparing the strings. An input property group name of null
* matches all values.
*/
static int
{
char *sp;
/* Match. The request wants any possible property group */
return (1);
}
/*
* No match. The property group name for this property list
* does not exist and therefore does not match.
*/
return (0);
}
/*
* No match. The property group name for this property list
* does not match the requested property group name.
*/
"%s requested property group %s != %s\n", __FUNCTION__,
return (0);
}
/* Match. */
return (1);
}