4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
39 #include <libcontract.h>
40 #include <libcontract_priv.h>
41 #include "libcontract_impl.h"
42 #include "process_dump.h"
43 #include "device_dump.h"
46 contract_type_t types
[CTT_MAXTYPE
] = {
47 { "process", event_process
},
48 { "device", event_device
}
54 int flags
= fcntl(fd
, F_GETFD
, 0);
55 if ((flags
!= -1) && (fcntl(fd
, F_SETFD
, flags
| FD_CLOEXEC
) != -1))
61 contract_latest(ctid_t
*id
)
67 if ((cfd
= open(CTFS_ROOT
"/process/latest", O_RDONLY
)) == -1)
70 if ((r
= ct_status_read(cfd
, CTD_COMMON
, &st
)) != 0) {
75 result
= ct_status_get_id(st
);
84 contract_open(ctid_t ctid
, const char *type
, const char *file
, int oflag
)
89 assert((oflag
& O_CREAT
) == 0);
94 n
= snprintf(path
, PATH_MAX
, CTFS_ROOT
"/%s/%ld/%s", type
, ctid
, file
);
100 fd
= open(path
, oflag
);
102 if (close_on_exec(fd
) == -1) {
113 contract_abandon_id(ctid_t ctid
)
117 fd
= contract_open(ctid
, "all", "ctl", O_WRONLY
);
121 err
= ct_ctl_abandon(fd
);
133 if ((fd
= open("/proc/self/psinfo", O_RDONLY
)) == -1)
135 if (read(fd
, &ps
, sizeof (ps
)) != sizeof (ps
)) {
140 return (ps
.pr_contract
);
144 contract_event_dump(FILE *file
, ct_evthdl_t hdl
, int verbose
)
147 struct ctlib_event_info
*info
= hdl
;
149 type
= info
->event
.ctev_cttype
;
150 types
[type
].type_event(file
, hdl
, verbose
);
154 contract_negend_dump(FILE *file
, ct_evthdl_t ev
)
157 ctid_t my_ctid
= ct_event_get_ctid(ev
);
161 (void) ct_event_get_nevid(ev
, &nevid
);
162 (void) ct_event_get_newct(ev
, &new_ctid
);
164 if (new_ctid
!= my_ctid
) {
165 s
= dgettext(TEXT_DOMAIN
, "negotiation %llu succeeded\n");
167 s
= dgettext(TEXT_DOMAIN
, "negotiation %llu failed\n");
170 (void) fprintf(file
, s
, (unsigned long long)nevid
);