5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2012 Milan Jurik. All rights reserved.
25 */
26
27
28 #include <sys/contract/process.h>
29 #include <assert.h>
30 #include <errno.h>
31 #include <libscf.h>
32 #include <libscf_priv.h>
33 #include <poll.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <unistd.h>
37
38 #include "startd.h"
39
40 #define SMF_SNAPSHOT_RUNNING "running"
41
42 #define INFO_EVENTS_ALL "info_events_all"
43
44 char *
1664 {
1665 return (libscf_inst_set_boolean_prop(inst, SCF_PG_GENERAL_OVR,
1666 SCF_PG_GENERAL_OVR_TYPE, SCF_PG_GENERAL_OVR_FLAGS,
1667 SCF_PROPERTY_ENABLED, enable));
1668 }
1669
1670 /*
1671 * Returns 0 on success, ECONNABORTED if the repository connection is broken,
1672 * ECANCELED if inst is deleted, EROFS if the backend is readonly, or EPERM if
1673 * permission was denied.
1674 */
1675 int
1676 libscf_set_deathrow(scf_instance_t *inst, int deathrow)
1677 {
1678 return (libscf_inst_set_boolean_prop(inst, SCF_PG_DEATHROW,
1679 SCF_PG_DEATHROW_TYPE, SCF_PG_DEATHROW_FLAGS,
1680 SCF_PROPERTY_DEATHROW, deathrow));
1681 }
1682
1683 /*
1684 * Returns 0, ECONNABORTED, ECANCELED, or EPERM.
1685 */
1686 int
1687 libscf_delete_enable_ovr(scf_instance_t *inst)
1688 {
1689 return (scf_instance_delete_prop(inst, SCF_PG_GENERAL_OVR,
1690 SCF_PROPERTY_ENABLED));
1691 }
1692
1693 /*
1694 * Fails with
1695 * ECONNABORTED - repository connection was broken
1696 * ECANCELED - pg was deleted
1697 * ENOENT - pg has no milestone property
1698 * EINVAL - the milestone property is misconfigured
1699 */
1700 static int
1701 pg_get_milestone(scf_propertygroup_t *pg, scf_property_t *prop,
1702 scf_value_t *val, char *buf, size_t buf_sz)
1703 {
1704 if (scf_pg_get_property(pg, SCF_PROPERTY_MILESTONE, prop) != 0) {
1705 switch (scf_error()) {
1706 case SCF_ERROR_CONNECTION_BROKEN:
1707 default:
1708 return (ECONNABORTED);
1709
1710 case SCF_ERROR_DELETED:
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2012 Milan Jurik. All rights reserved.
25 * Copyright 2020 Joyent, Inc.
26 */
27
28
29 #include <sys/contract/process.h>
30 #include <assert.h>
31 #include <errno.h>
32 #include <libscf.h>
33 #include <libscf_priv.h>
34 #include <poll.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <unistd.h>
38
39 #include "startd.h"
40
41 #define SMF_SNAPSHOT_RUNNING "running"
42
43 #define INFO_EVENTS_ALL "info_events_all"
44
45 char *
1665 {
1666 return (libscf_inst_set_boolean_prop(inst, SCF_PG_GENERAL_OVR,
1667 SCF_PG_GENERAL_OVR_TYPE, SCF_PG_GENERAL_OVR_FLAGS,
1668 SCF_PROPERTY_ENABLED, enable));
1669 }
1670
1671 /*
1672 * Returns 0 on success, ECONNABORTED if the repository connection is broken,
1673 * ECANCELED if inst is deleted, EROFS if the backend is readonly, or EPERM if
1674 * permission was denied.
1675 */
1676 int
1677 libscf_set_deathrow(scf_instance_t *inst, int deathrow)
1678 {
1679 return (libscf_inst_set_boolean_prop(inst, SCF_PG_DEATHROW,
1680 SCF_PG_DEATHROW_TYPE, SCF_PG_DEATHROW_FLAGS,
1681 SCF_PROPERTY_DEATHROW, deathrow));
1682 }
1683
1684 /*
1685 * Since we're clearing the over-ridden enabled state for the service, we'll
1686 * also take the opportunity to remove any comment.
1687 *
1688 * Returns 0, ECONNABORTED, ECANCELED, or EPERM.
1689 */
1690 int
1691 libscf_delete_enable_ovr(scf_instance_t *inst)
1692 {
1693 int r = scf_instance_delete_prop(inst, SCF_PG_GENERAL_OVR,
1694 SCF_PROPERTY_ENABLED);
1695 if (r != 0)
1696 return (r);
1697 return (scf_instance_delete_prop(inst, SCF_PG_GENERAL_OVR,
1698 SCF_PROPERTY_COMMENT));
1699 }
1700
1701 /*
1702 * Fails with
1703 * ECONNABORTED - repository connection was broken
1704 * ECANCELED - pg was deleted
1705 * ENOENT - pg has no milestone property
1706 * EINVAL - the milestone property is misconfigured
1707 */
1708 static int
1709 pg_get_milestone(scf_propertygroup_t *pg, scf_property_t *prop,
1710 scf_value_t *val, char *buf, size_t buf_sz)
1711 {
1712 if (scf_pg_get_property(pg, SCF_PROPERTY_MILESTONE, prop) != 0) {
1713 switch (scf_error()) {
1714 case SCF_ERROR_CONNECTION_BROKEN:
1715 default:
1716 return (ECONNABORTED);
1717
1718 case SCF_ERROR_DELETED:
|