svc.c revision 95efa359b507db290a2484b8f615822b1e06096f
/*
* 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
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* This provides the basic mechanisms (str2nvl and nvl2str) for dealing with
* the service schema. The official version of a svc FMRI has the form:
*
* svc://[scope@][system-fqn]/service[:instance][@contract-id]
*
* Where 'service' is a slash-delimited list of names. Of these fields, the
* scope, constract-id, and system-fqn are rarely used, leaving the much more
* common form such as:
*
*
* Note that the SMF software typically uses a shorthard form, where the
* FMA FMRIs, we only support fully specified FMRIs.
*
* This module does not support enumeration, but implements methods for FMRI
* state (present, unusable, service state, and replaced).
*/
#include <fm/topo_mod.h>
#include <fm/fmd_fmri.h>
#include <topo_method.h>
#include <topo_subr.h>
#include <alloca.h>
#include <assert.h>
#include <svc.h>
#include <strings.h>
#include <libscf.h>
topo_instance_t, void *, void *);
static const topo_method_t svc_methods[] = {
{ NULL }
};
static const topo_modops_t svc_ops =
{ svc_enum, svc_release };
static const topo_modinfo_t svc_info =
static int
{
switch (scf_error()) {
case SCF_ERROR_NO_MEMORY:
default:
}
}
int
{
if (version != SVC_VERSION)
if (scf_handle_bind(hdl) != 0) {
}
return (-1);
}
return (0);
}
void
{
}
/*ARGSUSED*/
static int
{
return (0);
}
static void
{
}
static boolean_t
svc_component_valid(const char *str)
{
return (B_TRUE);
if (*str == '\0')
return (B_FALSE);
return (B_FALSE);
return (B_TRUE);
}
/*ARGSUSED*/
static int
{
char *service;
int err;
if (version > TOPO_METH_NVL2STR_VERSION)
/*
* Check for optional members.
*/
/*
* Get the service name.
*/
/*
* We make two passes through this code. The first time through we
* calculate the size of buffer that we'll need, and the second time
* through we fill it in.
*/
/*
* svc://[scope@][system-fqn]
*/
NULL, "://");
/* svc path */
if (*service == '\0')
/* [:instance][@contract-id] */
size = 0;
goto again;
}
/*
* Construct the nvlist to return as the result.
*/
}
}
return (0);
}
/*ARGSUSED*/
static int
{
if (version > TOPO_METH_STR2NVL_VERSION)
str += 6;
goto malformed;
if (*loc == '@') {
/* scope */
*loc = '\0';
if (!svc_component_valid(str)) {
*loc = '@';
goto malformed;
}
*loc = '@';
goto nomem;
}
*loc = '@';
goto malformed;
}
/* system-fqn */
*loc = '\0';
if (!svc_component_valid(str)) {
*loc = '/';
goto malformed;
}
str) != 0) {
*loc = '/';
goto nomem;
}
*loc = '/';
}
goto malformed;
*loc = '\0';
}
/* service name */
goto nomem;
}
/* instance */
goto malformed;
*loc = '\0';
str) != 0) {
*loc = '@';
goto nomem;
}
*loc = '@';
}
/* contract-id */
if (str[0] == '\0')
goto malformed;
str) != 0) {
goto nomem;
}
}
goto nomem;
return (0);
}
/*
* This common function is shared by all consumers (present, unusable, and
* service_state). It returns one of the FMD_SERVICE_STATE_* states, where
* FMD_SERVICE_STATE_UNKNOWN means that the FMRI is not present.
*/
static int
int *ret)
{
char *state;
goto error;
goto error;
/*
* If we fail to get the service due to _DELETED or _NOT_FOUND, then we
* treat this as not present.
*/
goto out;
} else {
goto error;
}
}
/*
* If there is no instance, then it is always present, and always
* usuable.
*/
goto out;
}
/*
* Again, check for _DELETED or _NOT_FOUND.
*/
goto out;
} else {
goto error;
}
}
/*
* For presence, we are done. Otherwise, we need to get the current
* state of the instance.
*/
if (presence_only) {
goto out;
}
goto error;
goto error;
goto error;
else
goto out;
retval = -1;
out:
return (retval);
}
/*ARGSUSED*/
static int
{
int state;
if (version > TOPO_METH_PRESENT_VERSION)
return (-1);
state != FMD_SERVICE_STATE_UNKNOWN) != 0) {
nvlist_free(*out);
}
return (0);
}
/*ARGSUSED*/
static int
{
int state;
return (-1);
FMD_OBJ_STATE_NOT_PRESENT : FMD_OBJ_STATE_UNKNOWN) != 0) {
nvlist_free(*out);
}
return (0);
}
/*ARGSUSED*/
static int
{
int state;
return (-1);
state) != 0) {
nvlist_free(*out);
}
return (0);
}
/*ARGSUSED*/
static int
{
int state;
return (-1);
(state == FMD_SERVICE_STATE_UNKNOWN ||
state == FMD_SERVICE_STATE_UNUSABLE)) != 0) {
nvlist_free(*out);
}
return (0);
}