1N/A/*
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License (the "License").
1N/A * You may not use this file except in compliance with the License.
1N/A *
1N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * When distributing Covered Code, include this CDDL HEADER in each
1N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1N/A * If applicable, add the following below this CDDL HEADER, with the
1N/A * fields enclosed by brackets "[]" replaced with your own identifying
1N/A * information: Portions Copyright [yyyy] [name of copyright owner]
1N/A *
1N/A * CDDL HEADER END
1N/A */
1N/A/*
1N/A * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
1N/A * Use is subject to license terms.
1N/A */
1N/A
1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A#include <sys/ctfs.h>
1N/A#include <sys/contract.h>
1N/A#include <sys/contract/process.h>
1N/A#include <errno.h>
1N/A#include <unistd.h>
1N/A#include <libnvpair.h>
1N/A#include <libcontract.h>
1N/A#include "libcontract_impl.h"
1N/A
1N/A/*
1N/A * Process contract template routines
1N/A */
1N/A
1N/Aint
1N/Act_pr_tmpl_set_transfer(int fd, ctid_t ctid)
1N/A{
1N/A return (ct_tmpl_set_internal(fd, CTPP_SUBSUME, ctid));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_set_fatal(int fd, uint_t events)
1N/A{
1N/A return (ct_tmpl_set_internal(fd, CTPP_EV_FATAL, events));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_set_param(int fd, uint_t param)
1N/A{
1N/A return (ct_tmpl_set_internal(fd, CTPP_PARAMS, param));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_set_svc_fmri(int fd, const char *fmri)
1N/A{
1N/A return (ct_tmpl_set_internal_string(fd, CTPP_SVC_FMRI, fmri));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_set_svc_aux(int fd, const char *desc)
1N/A{
1N/A return (ct_tmpl_set_internal_string(fd, CTPP_CREATOR_AUX, desc));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_get_transfer(int fd, ctid_t *ctid)
1N/A{
1N/A return (ct_tmpl_get_internal(fd, CTPP_SUBSUME, (uint_t *)ctid));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_get_fatal(int fd, uint_t *events)
1N/A{
1N/A return (ct_tmpl_get_internal(fd, CTPP_EV_FATAL, events));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_get_param(int fd, uint_t *param)
1N/A{
1N/A return (ct_tmpl_get_internal(fd, CTPP_PARAMS, param));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_get_svc_fmri(int fd, char *fmri, size_t size)
1N/A{
1N/A return (ct_tmpl_get_internal_string(fd, CTPP_SVC_FMRI, fmri, size));
1N/A}
1N/A
1N/Aint
1N/Act_pr_tmpl_get_svc_aux(int fd, char *desc, size_t size)
1N/A{
1N/A return (ct_tmpl_get_internal_string(fd, CTPP_CREATOR_AUX, desc, size));
1N/A}
1N/A
1N/A/*
1N/A * Process contract event routines
1N/A */
1N/A
1N/Aint
1N/Act_pr_event_get_pid(ct_evthdl_t evthdl, pid_t *pid)
1N/A{
1N/A struct ctlib_event_info *info = evthdl;
1N/A if (info->event.ctev_cttype != CTT_PROCESS)
1N/A return (EINVAL);
1N/A if (info->nvl == NULL)
1N/A return (ENOENT);
1N/A return (nvlist_lookup_uint32(info->nvl, CTPE_PID, (uint_t *)pid));
1N/A}
1N/A
1N/Aint
1N/Act_pr_event_get_ppid(ct_evthdl_t evthdl, pid_t *ppid)
1N/A{
1N/A struct ctlib_event_info *info = evthdl;
1N/A if (info->event.ctev_cttype != CTT_PROCESS)
1N/A return (EINVAL);
1N/A if (info->event.ctev_type != CT_PR_EV_FORK)
1N/A return (EINVAL);
1N/A if (info->nvl == NULL)
1N/A return (ENOENT);
1N/A return (nvlist_lookup_uint32(info->nvl, CTPE_PPID, (uint_t *)ppid));
1N/A}
1N/A
1N/Aint
ct_pr_event_get_signal(ct_evthdl_t evthdl, int *signal)
{
struct ctlib_event_info *info = evthdl;
if (info->event.ctev_cttype != CTT_PROCESS)
return (EINVAL);
if (info->event.ctev_type != CT_PR_EV_SIGNAL)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTPE_SIGNAL, (uint_t *)signal));
}
int
ct_pr_event_get_sender(ct_evthdl_t evthdl, pid_t *sender)
{
struct ctlib_event_info *info = evthdl;
if (info->event.ctev_cttype != CTT_PROCESS)
return (EINVAL);
if (info->event.ctev_type != CT_PR_EV_SIGNAL)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTPE_SENDER, (uint_t *)sender));
}
int
ct_pr_event_get_senderct(ct_evthdl_t evthdl, ctid_t *sendct)
{
struct ctlib_event_info *info = evthdl;
if (info->event.ctev_cttype != CTT_PROCESS)
return (EINVAL);
if (info->event.ctev_type != CT_PR_EV_SIGNAL)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTPE_SENDCT, (uint_t *)sendct));
}
int
ct_pr_event_get_exitstatus(ct_evthdl_t evthdl, int *exitstatus)
{
struct ctlib_event_info *info = evthdl;
if (info->event.ctev_cttype != CTT_PROCESS)
return (EINVAL);
if (info->event.ctev_type != CT_PR_EV_EXIT)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_int32(info->nvl, CTPE_EXITSTATUS, exitstatus));
}
int
ct_pr_event_get_pcorefile(ct_evthdl_t evthdl, const char **pcorefile)
{
struct ctlib_event_info *info = evthdl;
if (info->event.ctev_cttype != CTT_PROCESS)
return (EINVAL);
if (info->event.ctev_type != CT_PR_EV_CORE)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_string(info->nvl, CTPE_PCOREFILE,
(char **)pcorefile));
}
int
ct_pr_event_get_gcorefile(ct_evthdl_t evthdl, const char **gcorefile)
{
struct ctlib_event_info *info = evthdl;
if (info->event.ctev_cttype != CTT_PROCESS)
return (EINVAL);
if (info->event.ctev_type != CT_PR_EV_CORE)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_string(info->nvl, CTPE_GCOREFILE,
(char **)gcorefile));
}
int
ct_pr_event_get_zcorefile(ct_evthdl_t evthdl, const char **zcorefile)
{
struct ctlib_event_info *info = evthdl;
if (info->event.ctev_cttype != CTT_PROCESS)
return (EINVAL);
if (info->event.ctev_type != CT_PR_EV_CORE)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_string(info->nvl, CTPE_ZCOREFILE,
(char **)zcorefile));
}
/*
* Process contract status routines
*/
int
ct_pr_status_get_param(ct_stathdl_t stathdl, uint_t *param)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTPS_PARAMS, param));
}
int
ct_pr_status_get_fatal(ct_stathdl_t stathdl, uint_t *fatal)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32(info->nvl, CTPS_EV_FATAL, fatal));
}
int
ct_pr_status_get_members(ct_stathdl_t stathdl, pid_t **members, uint_t *n)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32_array(info->nvl, CTPS_MEMBERS,
(uint_t **)members, n));
}
int
ct_pr_status_get_contracts(ct_stathdl_t stathdl, ctid_t **contracts,
uint_t *n)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_uint32_array(info->nvl, CTPS_CONTRACTS,
(uint_t **)contracts, n));
}
int
ct_pr_status_get_svc_fmri(ct_stathdl_t stathdl, char **svc_fmri)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_string(info->nvl, CTPS_SVC_FMRI, svc_fmri));
}
int
ct_pr_status_get_svc_aux(ct_stathdl_t stathdl, char **svc_aux)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_string(info->nvl, CTPS_CREATOR_AUX, svc_aux));
}
int
ct_pr_status_get_svc_ctid(ct_stathdl_t stathdl, ctid_t *ctid)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_int32(info->nvl, CTPS_SVC_CTID,
(int32_t *)ctid));
}
int
ct_pr_status_get_svc_creator(ct_stathdl_t stathdl, char **svc_creator)
{
struct ctlib_status_info *info = stathdl;
if (info->status.ctst_type != CTT_PROCESS)
return (EINVAL);
if (info->nvl == NULL)
return (ENOENT);
return (nvlist_lookup_string(info->nvl, CTPS_SVC_CREATOR, svc_creator));
}