10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*6073Sacruz * Common Development and Distribution License (the "License").
6*6073Sacruz * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*6073Sacruz * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
270Sstevel@tonic-gate
280Sstevel@tonic-gate #include <sys/ctfs.h>
290Sstevel@tonic-gate #include <sys/contract.h>
300Sstevel@tonic-gate #include <sys/contract/process.h>
310Sstevel@tonic-gate #include <errno.h>
320Sstevel@tonic-gate #include <unistd.h>
330Sstevel@tonic-gate #include <libnvpair.h>
340Sstevel@tonic-gate #include <libcontract.h>
350Sstevel@tonic-gate #include "libcontract_impl.h"
360Sstevel@tonic-gate
370Sstevel@tonic-gate /*
380Sstevel@tonic-gate * Process contract template routines
390Sstevel@tonic-gate */
400Sstevel@tonic-gate
410Sstevel@tonic-gate int
ct_pr_tmpl_set_transfer(int fd,ctid_t ctid)420Sstevel@tonic-gate ct_pr_tmpl_set_transfer(int fd, ctid_t ctid)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate return (ct_tmpl_set_internal(fd, CTPP_SUBSUME, ctid));
450Sstevel@tonic-gate }
460Sstevel@tonic-gate
470Sstevel@tonic-gate int
ct_pr_tmpl_set_fatal(int fd,uint_t events)480Sstevel@tonic-gate ct_pr_tmpl_set_fatal(int fd, uint_t events)
490Sstevel@tonic-gate {
500Sstevel@tonic-gate return (ct_tmpl_set_internal(fd, CTPP_EV_FATAL, events));
510Sstevel@tonic-gate }
520Sstevel@tonic-gate
530Sstevel@tonic-gate int
ct_pr_tmpl_set_param(int fd,uint_t param)540Sstevel@tonic-gate ct_pr_tmpl_set_param(int fd, uint_t param)
550Sstevel@tonic-gate {
560Sstevel@tonic-gate return (ct_tmpl_set_internal(fd, CTPP_PARAMS, param));
570Sstevel@tonic-gate }
580Sstevel@tonic-gate
590Sstevel@tonic-gate int
ct_pr_tmpl_set_svc_fmri(int fd,const char * fmri)60*6073Sacruz ct_pr_tmpl_set_svc_fmri(int fd, const char *fmri)
61*6073Sacruz {
62*6073Sacruz return (ct_tmpl_set_internal_string(fd, CTPP_SVC_FMRI, fmri));
63*6073Sacruz }
64*6073Sacruz
65*6073Sacruz int
ct_pr_tmpl_set_svc_aux(int fd,const char * desc)66*6073Sacruz ct_pr_tmpl_set_svc_aux(int fd, const char *desc)
67*6073Sacruz {
68*6073Sacruz return (ct_tmpl_set_internal_string(fd, CTPP_CREATOR_AUX, desc));
69*6073Sacruz }
70*6073Sacruz
71*6073Sacruz int
ct_pr_tmpl_get_transfer(int fd,ctid_t * ctid)720Sstevel@tonic-gate ct_pr_tmpl_get_transfer(int fd, ctid_t *ctid)
730Sstevel@tonic-gate {
740Sstevel@tonic-gate return (ct_tmpl_get_internal(fd, CTPP_SUBSUME, (uint_t *)ctid));
750Sstevel@tonic-gate }
760Sstevel@tonic-gate
770Sstevel@tonic-gate int
ct_pr_tmpl_get_fatal(int fd,uint_t * events)780Sstevel@tonic-gate ct_pr_tmpl_get_fatal(int fd, uint_t *events)
790Sstevel@tonic-gate {
800Sstevel@tonic-gate return (ct_tmpl_get_internal(fd, CTPP_EV_FATAL, events));
810Sstevel@tonic-gate }
820Sstevel@tonic-gate
830Sstevel@tonic-gate int
ct_pr_tmpl_get_param(int fd,uint_t * param)840Sstevel@tonic-gate ct_pr_tmpl_get_param(int fd, uint_t *param)
850Sstevel@tonic-gate {
860Sstevel@tonic-gate return (ct_tmpl_get_internal(fd, CTPP_PARAMS, param));
870Sstevel@tonic-gate }
880Sstevel@tonic-gate
89*6073Sacruz int
ct_pr_tmpl_get_svc_fmri(int fd,char * fmri,size_t size)90*6073Sacruz ct_pr_tmpl_get_svc_fmri(int fd, char *fmri, size_t size)
91*6073Sacruz {
92*6073Sacruz return (ct_tmpl_get_internal_string(fd, CTPP_SVC_FMRI, fmri, size));
93*6073Sacruz }
94*6073Sacruz
95*6073Sacruz int
ct_pr_tmpl_get_svc_aux(int fd,char * desc,size_t size)96*6073Sacruz ct_pr_tmpl_get_svc_aux(int fd, char *desc, size_t size)
97*6073Sacruz {
98*6073Sacruz return (ct_tmpl_get_internal_string(fd, CTPP_CREATOR_AUX, desc, size));
99*6073Sacruz }
100*6073Sacruz
1010Sstevel@tonic-gate /*
1020Sstevel@tonic-gate * Process contract event routines
1030Sstevel@tonic-gate */
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate int
ct_pr_event_get_pid(ct_evthdl_t evthdl,pid_t * pid)1060Sstevel@tonic-gate ct_pr_event_get_pid(ct_evthdl_t evthdl, pid_t *pid)
1070Sstevel@tonic-gate {
1080Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1090Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
1100Sstevel@tonic-gate return (EINVAL);
1110Sstevel@tonic-gate if (info->nvl == NULL)
1120Sstevel@tonic-gate return (ENOENT);
1130Sstevel@tonic-gate return (nvlist_lookup_uint32(info->nvl, CTPE_PID, (uint_t *)pid));
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate
1160Sstevel@tonic-gate int
ct_pr_event_get_ppid(ct_evthdl_t evthdl,pid_t * ppid)1170Sstevel@tonic-gate ct_pr_event_get_ppid(ct_evthdl_t evthdl, pid_t *ppid)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1200Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
1210Sstevel@tonic-gate return (EINVAL);
1220Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_FORK)
1230Sstevel@tonic-gate return (EINVAL);
1240Sstevel@tonic-gate if (info->nvl == NULL)
1250Sstevel@tonic-gate return (ENOENT);
1260Sstevel@tonic-gate return (nvlist_lookup_uint32(info->nvl, CTPE_PPID, (uint_t *)ppid));
1270Sstevel@tonic-gate }
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate int
ct_pr_event_get_signal(ct_evthdl_t evthdl,int * signal)1300Sstevel@tonic-gate ct_pr_event_get_signal(ct_evthdl_t evthdl, int *signal)
1310Sstevel@tonic-gate {
1320Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1330Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
1340Sstevel@tonic-gate return (EINVAL);
1350Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_SIGNAL)
1360Sstevel@tonic-gate return (EINVAL);
1370Sstevel@tonic-gate if (info->nvl == NULL)
1380Sstevel@tonic-gate return (ENOENT);
1390Sstevel@tonic-gate return (nvlist_lookup_uint32(info->nvl, CTPE_SIGNAL, (uint_t *)signal));
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate
1420Sstevel@tonic-gate int
ct_pr_event_get_sender(ct_evthdl_t evthdl,pid_t * sender)1430Sstevel@tonic-gate ct_pr_event_get_sender(ct_evthdl_t evthdl, pid_t *sender)
1440Sstevel@tonic-gate {
1450Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1460Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
1470Sstevel@tonic-gate return (EINVAL);
1480Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_SIGNAL)
1490Sstevel@tonic-gate return (EINVAL);
1500Sstevel@tonic-gate if (info->nvl == NULL)
1510Sstevel@tonic-gate return (ENOENT);
1520Sstevel@tonic-gate return (nvlist_lookup_uint32(info->nvl, CTPE_SENDER, (uint_t *)sender));
1530Sstevel@tonic-gate }
1540Sstevel@tonic-gate
1550Sstevel@tonic-gate int
ct_pr_event_get_senderct(ct_evthdl_t evthdl,ctid_t * sendct)1560Sstevel@tonic-gate ct_pr_event_get_senderct(ct_evthdl_t evthdl, ctid_t *sendct)
1570Sstevel@tonic-gate {
1580Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1590Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
1600Sstevel@tonic-gate return (EINVAL);
1610Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_SIGNAL)
1620Sstevel@tonic-gate return (EINVAL);
1630Sstevel@tonic-gate if (info->nvl == NULL)
1640Sstevel@tonic-gate return (ENOENT);
1650Sstevel@tonic-gate return (nvlist_lookup_uint32(info->nvl, CTPE_SENDCT, (uint_t *)sendct));
1660Sstevel@tonic-gate }
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate int
ct_pr_event_get_exitstatus(ct_evthdl_t evthdl,int * exitstatus)1690Sstevel@tonic-gate ct_pr_event_get_exitstatus(ct_evthdl_t evthdl, int *exitstatus)
1700Sstevel@tonic-gate {
1710Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1720Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
1730Sstevel@tonic-gate return (EINVAL);
1740Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_EXIT)
1750Sstevel@tonic-gate return (EINVAL);
1760Sstevel@tonic-gate if (info->nvl == NULL)
1770Sstevel@tonic-gate return (ENOENT);
1780Sstevel@tonic-gate return (nvlist_lookup_int32(info->nvl, CTPE_EXITSTATUS, exitstatus));
1790Sstevel@tonic-gate }
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate int
ct_pr_event_get_pcorefile(ct_evthdl_t evthdl,const char ** pcorefile)1820Sstevel@tonic-gate ct_pr_event_get_pcorefile(ct_evthdl_t evthdl, const char **pcorefile)
1830Sstevel@tonic-gate {
1840Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1850Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
1860Sstevel@tonic-gate return (EINVAL);
1870Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_CORE)
1880Sstevel@tonic-gate return (EINVAL);
1890Sstevel@tonic-gate if (info->nvl == NULL)
1900Sstevel@tonic-gate return (ENOENT);
1910Sstevel@tonic-gate return (nvlist_lookup_string(info->nvl, CTPE_PCOREFILE,
1920Sstevel@tonic-gate (char **)pcorefile));
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate
1950Sstevel@tonic-gate int
ct_pr_event_get_gcorefile(ct_evthdl_t evthdl,const char ** gcorefile)1960Sstevel@tonic-gate ct_pr_event_get_gcorefile(ct_evthdl_t evthdl, const char **gcorefile)
1970Sstevel@tonic-gate {
1980Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
1990Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
2000Sstevel@tonic-gate return (EINVAL);
2010Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_CORE)
2020Sstevel@tonic-gate return (EINVAL);
2030Sstevel@tonic-gate if (info->nvl == NULL)
2040Sstevel@tonic-gate return (ENOENT);
2050Sstevel@tonic-gate return (nvlist_lookup_string(info->nvl, CTPE_GCOREFILE,
2060Sstevel@tonic-gate (char **)gcorefile));
2070Sstevel@tonic-gate }
2080Sstevel@tonic-gate
2090Sstevel@tonic-gate int
ct_pr_event_get_zcorefile(ct_evthdl_t evthdl,const char ** zcorefile)2100Sstevel@tonic-gate ct_pr_event_get_zcorefile(ct_evthdl_t evthdl, const char **zcorefile)
2110Sstevel@tonic-gate {
2120Sstevel@tonic-gate struct ctlib_event_info *info = evthdl;
2130Sstevel@tonic-gate if (info->event.ctev_cttype != CTT_PROCESS)
2140Sstevel@tonic-gate return (EINVAL);
2150Sstevel@tonic-gate if (info->event.ctev_type != CT_PR_EV_CORE)
2160Sstevel@tonic-gate return (EINVAL);
2170Sstevel@tonic-gate if (info->nvl == NULL)
2180Sstevel@tonic-gate return (ENOENT);
2190Sstevel@tonic-gate return (nvlist_lookup_string(info->nvl, CTPE_ZCOREFILE,
2200Sstevel@tonic-gate (char **)zcorefile));
2210Sstevel@tonic-gate }
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate /*
2240Sstevel@tonic-gate * Process contract status routines
2250Sstevel@tonic-gate */
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate int
ct_pr_status_get_param(ct_stathdl_t stathdl,uint_t * param)2280Sstevel@tonic-gate ct_pr_status_get_param(ct_stathdl_t stathdl, uint_t *param)
2290Sstevel@tonic-gate {
2300Sstevel@tonic-gate struct ctlib_status_info *info = stathdl;
2310Sstevel@tonic-gate if (info->status.ctst_type != CTT_PROCESS)
2320Sstevel@tonic-gate return (EINVAL);
2330Sstevel@tonic-gate if (info->nvl == NULL)
2340Sstevel@tonic-gate return (ENOENT);
2350Sstevel@tonic-gate return (nvlist_lookup_uint32(info->nvl, CTPS_PARAMS, param));
2360Sstevel@tonic-gate }
2370Sstevel@tonic-gate
2380Sstevel@tonic-gate int
ct_pr_status_get_fatal(ct_stathdl_t stathdl,uint_t * fatal)2390Sstevel@tonic-gate ct_pr_status_get_fatal(ct_stathdl_t stathdl, uint_t *fatal)
2400Sstevel@tonic-gate {
2410Sstevel@tonic-gate struct ctlib_status_info *info = stathdl;
2420Sstevel@tonic-gate if (info->status.ctst_type != CTT_PROCESS)
2430Sstevel@tonic-gate return (EINVAL);
2440Sstevel@tonic-gate if (info->nvl == NULL)
2450Sstevel@tonic-gate return (ENOENT);
2460Sstevel@tonic-gate return (nvlist_lookup_uint32(info->nvl, CTPS_EV_FATAL, fatal));
2470Sstevel@tonic-gate }
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate int
ct_pr_status_get_members(ct_stathdl_t stathdl,pid_t ** members,uint_t * n)2500Sstevel@tonic-gate ct_pr_status_get_members(ct_stathdl_t stathdl, pid_t **members, uint_t *n)
2510Sstevel@tonic-gate {
2520Sstevel@tonic-gate struct ctlib_status_info *info = stathdl;
2530Sstevel@tonic-gate if (info->status.ctst_type != CTT_PROCESS)
2540Sstevel@tonic-gate return (EINVAL);
2550Sstevel@tonic-gate if (info->nvl == NULL)
2560Sstevel@tonic-gate return (ENOENT);
2570Sstevel@tonic-gate return (nvlist_lookup_uint32_array(info->nvl, CTPS_MEMBERS,
2580Sstevel@tonic-gate (uint_t **)members, n));
2590Sstevel@tonic-gate }
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate int
ct_pr_status_get_contracts(ct_stathdl_t stathdl,ctid_t ** contracts,uint_t * n)2620Sstevel@tonic-gate ct_pr_status_get_contracts(ct_stathdl_t stathdl, ctid_t **contracts,
2630Sstevel@tonic-gate uint_t *n)
2640Sstevel@tonic-gate {
2650Sstevel@tonic-gate struct ctlib_status_info *info = stathdl;
2660Sstevel@tonic-gate if (info->status.ctst_type != CTT_PROCESS)
2670Sstevel@tonic-gate return (EINVAL);
2680Sstevel@tonic-gate if (info->nvl == NULL)
2690Sstevel@tonic-gate return (ENOENT);
2700Sstevel@tonic-gate return (nvlist_lookup_uint32_array(info->nvl, CTPS_CONTRACTS,
2710Sstevel@tonic-gate (uint_t **)contracts, n));
2720Sstevel@tonic-gate }
273*6073Sacruz
274*6073Sacruz int
ct_pr_status_get_svc_fmri(ct_stathdl_t stathdl,char ** svc_fmri)275*6073Sacruz ct_pr_status_get_svc_fmri(ct_stathdl_t stathdl, char **svc_fmri)
276*6073Sacruz {
277*6073Sacruz struct ctlib_status_info *info = stathdl;
278*6073Sacruz if (info->status.ctst_type != CTT_PROCESS)
279*6073Sacruz return (EINVAL);
280*6073Sacruz if (info->nvl == NULL)
281*6073Sacruz return (ENOENT);
282*6073Sacruz return (nvlist_lookup_string(info->nvl, CTPS_SVC_FMRI, svc_fmri));
283*6073Sacruz }
284*6073Sacruz
285*6073Sacruz int
ct_pr_status_get_svc_aux(ct_stathdl_t stathdl,char ** svc_aux)286*6073Sacruz ct_pr_status_get_svc_aux(ct_stathdl_t stathdl, char **svc_aux)
287*6073Sacruz {
288*6073Sacruz struct ctlib_status_info *info = stathdl;
289*6073Sacruz if (info->status.ctst_type != CTT_PROCESS)
290*6073Sacruz return (EINVAL);
291*6073Sacruz if (info->nvl == NULL)
292*6073Sacruz return (ENOENT);
293*6073Sacruz return (nvlist_lookup_string(info->nvl, CTPS_CREATOR_AUX, svc_aux));
294*6073Sacruz }
295*6073Sacruz
296*6073Sacruz int
ct_pr_status_get_svc_ctid(ct_stathdl_t stathdl,ctid_t * ctid)297*6073Sacruz ct_pr_status_get_svc_ctid(ct_stathdl_t stathdl, ctid_t *ctid)
298*6073Sacruz {
299*6073Sacruz struct ctlib_status_info *info = stathdl;
300*6073Sacruz if (info->status.ctst_type != CTT_PROCESS)
301*6073Sacruz return (EINVAL);
302*6073Sacruz if (info->nvl == NULL)
303*6073Sacruz return (ENOENT);
304*6073Sacruz return (nvlist_lookup_int32(info->nvl, CTPS_SVC_CTID,
305*6073Sacruz (int32_t *)ctid));
306*6073Sacruz }
307*6073Sacruz
308*6073Sacruz int
ct_pr_status_get_svc_creator(ct_stathdl_t stathdl,char ** svc_creator)309*6073Sacruz ct_pr_status_get_svc_creator(ct_stathdl_t stathdl, char **svc_creator)
310*6073Sacruz {
311*6073Sacruz struct ctlib_status_info *info = stathdl;
312*6073Sacruz if (info->status.ctst_type != CTT_PROCESS)
313*6073Sacruz return (EINVAL);
314*6073Sacruz if (info->nvl == NULL)
315*6073Sacruz return (ENOENT);
316*6073Sacruz return (nvlist_lookup_string(info->nvl, CTPS_SVC_CREATOR, svc_creator));
317*6073Sacruz }
318