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]
21 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
22 * Use is subject to license terms.
25 #pragma ident "%Z%%M% %I% %E% SMI"
27 #include <sys/types.h>
36 #include <libscf_priv.h>
39 #include "rcapd_conf.h"
40 #include "rcapd_stat.h"
44 * Read configuration and set the fields of an rcfg_t correspondingly.
45 * Verify that the statistics file is writable, with the optional
46 * verify_stat_file_creation() callback.
49 rcfg_read(rcfg_t
*_rcfg
, int(*verify_stat_file_creation
)(void))
51 scf_simple_handle_t
*simple_h
;
57 if ((simple_h
= scf_general_pg_setup(RCAP_FMRI
, CONFIG_PG
))
59 warn(gettext("SMF initialization problem: %s\n"),
60 scf_strerror(scf_error()));
64 if (scf_read_count_property(simple_h
, PRESSURE
, &count_val
)
66 warn(gettext("Configuration property '%s' "
67 "not found. \n"), PRESSURE
);
71 _rcfg
->rcfg_memory_cap_enforcement_pressure
= 100;
73 _rcfg
->rcfg_memory_cap_enforcement_pressure
76 debug("cap max pressure: %d%%\n",
77 _rcfg
->rcfg_memory_cap_enforcement_pressure
);
80 if (scf_read_count_property(simple_h
, RECONFIG_INT
, &count_val
)
82 warn(gettext("Configuration property '%s' "
83 "not found. \n"), RECONFIG_INT
);
86 _rcfg
->rcfg_reconfiguration_interval
= count_val
;
87 debug("reconfiguration interval: %d seconds\n",
88 _rcfg
->rcfg_reconfiguration_interval
);
91 if (scf_read_count_property(simple_h
, REPORT_INT
, &count_val
)
93 warn(gettext("Configuration property '%s' "
94 "not found. \n"), REPORT_INT
);
97 _rcfg
->rcfg_report_interval
= count_val
;
98 debug("report interval: %d seconds\n",
99 _rcfg
->rcfg_report_interval
);
102 if (scf_read_count_property(simple_h
, RSS_SAMPLE_INT
, &count_val
)
104 warn(gettext("Configuration property '%s' "
105 "not found. \n"), RSS_SAMPLE_INT
);
108 _rcfg
->rcfg_rss_sample_interval
= count_val
;
109 debug("RSS sample interval: %d seconds\n",
110 _rcfg
->rcfg_rss_sample_interval
);
113 if (scf_read_count_property(simple_h
, WALK_INT
, &count_val
)
115 warn(gettext("Configuration property '%s' "
116 "not found. \n"), WALK_INT
);
119 _rcfg
->rcfg_proc_walk_interval
= count_val
;
120 debug("proc_walk interval: %d seconds\n",
121 _rcfg
->rcfg_proc_walk_interval
);
124 if (_rcfg
->rcfg_mode_name
== NULL
) {
126 * Set project mode, by default.
128 _rcfg
->rcfg_mode
= rctype_project
;
129 _rcfg
->rcfg_mode_name
= "project";
130 debug("mode: %s\n", _rcfg
->rcfg_mode_name
);
133 if (verify_stat_file_creation
!= 0 && verify_stat_file_creation()
135 warn(gettext("cannot create statistics file, " "%s"),
136 _rcfg
->rcfg_stat_file
);
140 debug("done parsing\n");
145 if (scf_error() != SCF_ERROR_NONE
) {
146 warn(gettext("Unexpected libscf error: %s. \n"),
147 scf_strerror(scf_error()));
151 scf_simple_handle_destroy(simple_h
);
156 rcfg_init(rcfg_t
*rcfg
)
158 bzero(rcfg
, sizeof (*rcfg
));
159 (void) strcpy(rcfg
->rcfg_stat_file
, STAT_FILE_DEFAULT
);
163 * Modify configuration in repository given the rcfg_t structure.
166 modify_config(rcfg_t
*conf
)
168 scf_simple_handle_t
*simple_h
;
169 scf_transaction_t
*tx
= NULL
;
170 int rval
, ret
= E_ERROR
;
172 if ((simple_h
= scf_general_pg_setup(RCAP_FMRI
, CONFIG_PG
))
174 warn(gettext("SMF initialization problem: %s\n"),
175 scf_strerror(scf_error()));
179 if ((tx
= scf_transaction_setup(simple_h
)) == NULL
) {
180 warn(gettext("SMF initialization problem: %s\n"),
181 scf_strerror(scf_error()));
186 if (scf_set_count_property(tx
, PRESSURE
,
187 conf
->rcfg_memory_cap_enforcement_pressure
, 0)
189 warn(gettext("Couldn't set '%s' property. \n"),
194 if (scf_set_count_property(tx
, RECONFIG_INT
,
195 conf
->rcfg_reconfiguration_interval
, 0) != SCF_SUCCESS
) {
196 warn(gettext("Couldn't set '%s' property. \n"),
201 if (scf_set_count_property(tx
, RSS_SAMPLE_INT
,
202 conf
->rcfg_rss_sample_interval
, 0) != SCF_SUCCESS
) {
203 warn(gettext("Couldn't set '%s' property. \n"),
208 if (scf_set_count_property(tx
, REPORT_INT
,
209 conf
->rcfg_report_interval
, 0) != SCF_SUCCESS
) {
210 warn(gettext("Couldn't set '%s' property. \n"),
215 if (scf_set_count_property(tx
, WALK_INT
,
216 conf
->rcfg_proc_walk_interval
, 0) != SCF_SUCCESS
) {
217 warn(gettext("Couldn't set '%s' property. \n"),
222 if ((rval
= scf_transaction_commit(tx
)) == -1)
226 if (scf_transaction_restart(simple_h
, tx
)
228 warn(gettext("SMF initialization problem: "
229 "%s\n"), scf_strerror(scf_error()));
239 scf_transaction_destroy_children(tx
);
240 scf_transaction_destroy(tx
);
242 scf_simple_handle_destroy(simple_h
);