Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / share / man / man3scf / scf_iter_create.3scf
blob186496941c1447303c2644799c2a1621d1933bf6
1 '\" te
2 .\" Copyright (c) 2008, Sun Microsystems, Inc.
3 .\" All Rights Reserved.
4 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
5 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
6 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
7 .TH SCF_ITER_CREATE 3SCF "Dec 4, 2008"
8 .SH NAME
9 scf_iter_create, scf_iter_handle, scf_iter_destroy, scf_iter_reset,
10 scf_iter_handle_scopes, scf_iter_scope_services, scf_iter_service_instances,
11 scf_iter_service_pgs, scf_iter_service_pgs_typed, scf_iter_instance_snapshots,
12 scf_iter_snaplevel_pgs, scf_iter_snaplevel_pgs_typed, scf_iter_instance_pgs,
13 scf_iter_instance_pgs_typed, scf_iter_instance_pgs_composed,
14 scf_iter_instance_pgs_typed_composed, scf_iter_pg_properties,
15 scf_iter_property_values, scf_iter_next_scope, scf_iter_next_service,
16 scf_iter_next_instance, scf_iter_next_snapshot, scf_iter_next_pg,
17 scf_iter_next_property, scf_iter_next_value \- iterate through the Service
18 Configuration Facility repository
19 .SH SYNOPSIS
20 .LP
21 .nf
22 cc [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lscf\fR [ \fIlibrary\fR\&.\|.\|. ]
23 #include <libscf.h>
25 \fBscf_iter_t *\fR\fBscf_iter_create\fR(\fBscf_handle_t *\fR\fIhandle\fR);
26 .fi
28 .LP
29 .nf
30 \fBscf_handle_t *\fR\fBscf_iter_handle\fR(\fBscf_iter_t *\fR\fIiter\fR);
31 .fi
33 .LP
34 .nf
35 \fBvoid\fR \fBscf_iter_destroy\fR(\fBscf_iter_t *\fR\fIiter\fR);
36 .fi
38 .LP
39 .nf
40 \fBvoid\fR \fBscf_iter_reset\fR(\fBscf_iter_t *\fR\fIiter\fR);
41 .fi
43 .LP
44 .nf
45 \fBint\fR \fBscf_iter_handle_scopes\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBconst scf_handle_t *\fR\fIh\fR);
46 .fi
48 .LP
49 .nf
50 \fBint\fR \fBscf_iter_scope_services\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBconst scf_scope_t *\fR\fIparent\fR);
51 .fi
53 .LP
54 .nf
55 \fBint\fR \fBscf_iter_service_instances\fR(\fBscf_iter_t *\fR\fIiter\fR,
56      \fBconst scf_service_t *\fR\fIparent\fR);
57 .fi
59 .LP
60 .nf
61 \fBint\fR \fBscf_iter_service_pgs\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBconst scf_service_t *\fR\fIparent\fR);
62 .fi
64 .LP
65 .nf
66 \fBint\fR \fBscf_iter_service_pgs_typed\fR(\fBscf_iter_t *\fR\fIiter\fR,
67      \fBconst scf_service_t *\fR\fIparent\fR, \fBconst char *\fR\fIpgtype\fR);
68 .fi
70 .LP
71 .nf
72 \fBint\fR \fBscf_iter_instance_snapshots\fR(\fBscf_iter_t *\fR\fIiter\fR,
73      \fBconst scf_instance_t *\fR\fIparent\fR);
74 .fi
76 .LP
77 .nf
78 \fBint\fR \fBscf_iter_snaplevel_pgs\fR(\fBscf_iter_t *\fR\fIiter\fR,
79      \fBconst scf_snaplevel_t *\fR\fIparent\fR);
80 .fi
82 .LP
83 .nf
84 \fBint\fR \fBscf_iter_snaplevel_pgs_typed\fR(\fBscf_iter_t *\fR\fIiter\fR,
85      \fBconst scf_snaplevel_t *\fR\fIparent\fR, \fBconst char *\fR\fIpgtype\fR);
86 .fi
88 .LP
89 .nf
90 \fBint\fR \fBscf_iter_instance_pgs\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_instance_t *\fR\fIparent\fR);
91 .fi
93 .LP
94 .nf
95 \fBint\fR \fBscf_iter_instance_pgs_typed\fR(\fBscf_iter_t *\fR\fIiter\fR,
96      \fBscf_instance_t *\fR\fIparent\fR, \fBconst char *\fR\fIpgtype\fR);
97 .fi
99 .LP
101 \fBint\fR \fBscf_iter_instance_pgs_composed\fR(\fBscf_iter_t *\fR\fIiter\fR,
102      \fBconst scf_instance_t *\fR\fIinstance\fR, \fBconst scf_snapshot_t *\fR\fIsnapshot\fR);
107 \fBint\fR \fBscf_iter_instance_pgs_typed_composed\fR(\fBscf_iter_t *\fR\fIiter\fR,
108      \fBconst scf_instance_t *\fR\fIinstance\fR, \fBconst scf_snapshot_t *\fR\fIsnapshot\fR,
109      \fBconst char *\fR\fIpgtype\fR);
114 \fBint\fR \fBscf_iter_pg_properties\fR(\fBscf_iter_t *\fR\fIiter\fR,
115      \fBconst scf_propertygroup_t *\fR\fIparent\fR);
120 \fBint\fR \fBscf_iter_property_values\fR(\fBscf_iter_t *\fR\fIiter\fR,
121      \fBconst scf_property_t *\fR\fIparent\fR);
126 \fBint\fR \fBscf_iter_next_scope\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_scope_t *\fR\fIout\fR);
131 \fBint\fR \fBscf_iter_next_service\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_service_t *\fR\fIout\fR);
136 \fBint\fR \fBscf_iter_next_instance\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_instance_t *\fR\fIout\fR);
141 \fBint\fR \fBscf_iter_next_snapshot\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_snapshot_t *\fR\fIout\fR);
146 \fBint\fR \fBscf_iter_next_pg\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_propertygroup_t  *\fR\fIout\fR);
151 \fBint\fR \fBscf_iter_next_property\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_property_t *\fR\fIout\fR);
156 \fBint\fR \fBscf_iter_next_value\fR(\fBscf_iter_t *\fR\fIiter\fR, \fBscf_value_t *\fR\fIout\fR);
159 .SH DESCRIPTION
162 The \fBscf_iter_create()\fR function creates a new iterator associated with
163 \fIhandle\fR. The \fBscf_iter_destroy()\fR function destroys an iteration.
166 The \fBscf_iter_reset()\fR function releases any resources involved with an
167 active iteration and returns the iterator to its initial state.
170 The \fBscf_iter_handle_scopes()\fR, \fBscf_iter_scope_services()\fR,
171 \fBscf_iter_service_instances()\fR, \fBscf_iter_instance_snapshots()\fR,
172 \fBscf_iter_service_pgs()\fR, \fBscf_iter_instance_pgs()\fR,
173 \fBscf_iter_snaplevel_pgs()\fR, \fBscf_iter_pg_properties()\fR, and
174 \fBscf_iter_property_values()\fR functions set up a new iteration of all the
175 children \fIparent\fR of a particular type. The
176 \fBscf_iter_property_values()\fR function will iterate over values in the order
177 in which they were specified with \fBscf_entry_add_value\fR(3SCF).
180 The \fBscf_iter_service_pgs_typed()\fR, \fBscf_iter_instance_pgs_typed()\fR,
181 and \fBscf_iter_snaplevel_pgs_typed()\fR functions iterate over the child
182 property groups of \fIparent\fR, but restrict them to a particular property
183 group type.
186 The \fBscf_iter_instance_pgs_composed()\fR function sets up a new iteration of
187 the composed view of instance's children at the time \fIsnapshot\fR was taken.
188 If \fIsnapshot\fR is \fINULL\fR, the current properties are used. The composed
189 view of an instance's properties is the union of the properties of the instance
190 and its ancestors. Properties of the instance take precedence over properties
191 of the service with the same name, including property group name. Property
192 groups retrieved with this iterator might not have \fIinstance\fR as their
193 parent and properties retrieved from such property groups might not have the
194 indicated property group as their parent. If \fIinstance\fR and its parent have
195 property groups with the same name but different types, the properties in the
196 property group of the parent are excluded. The
197 \fBscf_iter_instance_pgs_typed_composed()\fR function behaves as
198 \fBscf_iter_instance_pgs_composed()\fR, except the property groups of the type
199 \fIpgtype\fR are returned.
202 The \fBscf_iter_next_scope()\fR, \fBscf_iter_next_service()\fR,
203 \fBscf_iter_next_instance()\fR, \fBscf_iter_next_snapshot()\fR,
204 \fBscf_iter_next_pg()\fR, \fBscf_iter_next_property()\fR, and
205 \fBscf_iter_next_value()\fR functions retrieve the next element of the
206 iteration.
207 .SH RETURN VALUES
210 Upon successful completion, \fBscf_iter_create()\fR returns a pointer to a new
211 iterator. Otherwise, it returns \fINULL\fR.
214 Upon successful completion, \fBscf_iter_handle()\fR returns the handle
215 associated with \fIiter\fR. Otherwise it returns \fINULL\fR.
218 Upon successful completion, \fBscf_iter_handle_scopes()\fR,
219 \fBscf_iter_scope_services()\fR, \fBscf_iter_service_instances()\fR,
220 \fBscf_iter_instance_snapshots()\fR, \fBscf_iter_service_pgs()\fR,
221 \fBscf_iter_instance_pgs()\fR, \fBscf_iter_snaplevel_pgs()\fR,
222 \fBscf_iter_pg_properties()\fR, \fBscf_iter_property_values()\fR,
223 \fBscf_iter_service_pgs_typed()\fR, \fBscf_iter_instance_pgs_composed()\fR,
224 \fBscf_iter_instance_pgs_typed()\fR,
225 \fBscf_iter_instance_pgs_typed_composed()\fR, and
226 \fBscf_iter_snaplevel_pgs_typed()\fR return 0. Otherwise, they return -1.
229 Upon successful completion, \fBscf_iter_next_scope()\fR,
230 \fBscf_iter_next_service()\fR, \fBscf_iter_next_instance()\fR,
231 \fBscf_iter_next_snapshot()\fR, \fBscf_iter_next_pg()\fR,
232 \fBscf_iter_next_property()\fR, and \fBscf_iter_next_value()\fR return 1. If
233 the iterator is complete, they return 0. Otherwise, they return -1.
234 .SH ERRORS
237 The \fBscf_iter_create()\fR function will fail if:
239 .ne 2
241 \fB\fBSCF_ERROR_INVALID_ARGUMENT\fR\fR
243 .RS 30n
244 The handle argument is NULL.
248 .ne 2
250 \fB\fBSCF_ERROR_NO_MEMORY\fR\fR
252 .RS 30n
253 There is no memory available.
257 .ne 2
259 \fB\fBSCF_ERROR_NO_RESOURCES\fR\fR
261 .RS 30n
262 The server does not have adequate resources for a new iteration.
267 The \fBscf_iter_handle()\fR function will fail if:
269 .ne 2
271 \fB\fBSCF_ERROR_HANDLE_DESTROYED\fR\fR
273 .RS 30n
274 The handle associated with \fIiter\fR has been destroyed.
279 The \fBscf_iter_next_value()\fR function will fail if:
281 .ne 2
283 \fB\fBSCF_ERROR_PERMISSION_DENIED\fR\fR
285 .sp .6
286 .RS 4n
287 The value could not be read due to access restrictions.
292 The \fBscf_iter_handle_scopes()\fR, \fBscf_iter_scope_services()\fR,
293 \fBscf_iter_service_instances()\fR, \fBscf_iter_instance_snapshots()\fR,
294 \fBscf_iter_service_pgs()\fR, \fBscf_iter_instance_pgs()\fR,
295 \fBscf_iter_instance_pgs_composed()\fR, \fBscf_iter_snaplevel_pgs()\fR,
296 \fBscf_iter_pg_properties()\fR, \fBscf_iter_property_values()\fR,
297 \fBscf_iter_service_pgs_typed()\fR, \fBscf_iter_instance_pgs_typed()\fR,
298 \fBscf_iter_instance_pgs_typed_composed()\fR, and
299 \fBscf_iter_snaplevel_pgs_typed()\fR functions will fail if:
301 .ne 2
303 \fB\fBSCF_ERROR_DELETED\fR\fR
305 .sp .6
306 .RS 4n
307 The parent has been deleted.
311 .ne 2
313 \fB\fBSCF_ERROR_NOT_SET\fR\fR
315 .sp .6
316 .RS 4n
317 The parent is not set.
321 .ne 2
323 \fB\fBSCF_ERROR_NOT_BOUND\fR\fR
325 .sp .6
326 .RS 4n
327 The handle is not bound.
331 .ne 2
333 \fB\fBSCF_ERROR_CONNECTION_BROKEN\fR\fR
335 .sp .6
336 .RS 4n
337 The connection to the repository was lost.
341 .ne 2
343 \fB\fBSCF_ERROR_HANDLE_MISMATCH\fR\fR
345 .sp .6
346 .RS 4n
347 The \fIiter\fR and \fIparent\fR arguments are not derived from the same handle.
352 The \fBscf_iter_service_pgs_typed()\fR, \fBscf_iter_instance_pgs_typed()\fR,
353 \fBscf_iter_instance_pgs_typed_composed()\fR, and
354 \fBscf_iter_snaplevel_pgs_typed()\fR functions will fail if:
356 .ne 2
358 \fB\fBSCF_ERROR_INVALID_ARGUMENT\fR\fR
360 .RS 30n
361 The \fIpgtype\fR argument is not a valid property group type.
366 The \fBscf_iter_next_service()\fR, \fBscf_iter_next_instance()\fR,
367 \fBscf_iter_next_snapshot()\fR, \fBscf_iter_next_pg()\fR,
368 \fBscf_iter_next_property()\fR, and \fBscf_iter_next_value()\fR functions will
369 fail if:
371 .ne 2
373 \fB\fBSCF_ERROR_DELETED\fR\fR
375 .RS 21n
376 The parent the iterator is attached to has been deleted.
381 The \fBscf_iter_next_scope()\fR, \fBscf_iter_next_service()\fR,
382 \fBscf_iter_next_instance()\fR, \fBscf_iter_next_snapshot()\fR,
383 \fBscf_iter_next_pg()\fR,\fBscf_iter_next_property()\fR, and
384 \fBscf_iter_next_value()\fR functions will fail if:
386 .ne 2
388 \fB\fBSCF_ERROR_NOT_SET\fR\fR
390 .sp .6
391 .RS 4n
392 The iterator is not set.
396 .ne 2
398 \fB\fBSCF_ERROR_INVALID_ARGUMENT\fR\fR
400 .sp .6
401 .RS 4n
402 The requested object type does not match the type the iterator is walking.
406 .ne 2
408 \fB\fBSCF_ERROR_NOT_BOUND\fR\fR
410 .sp .6
411 .RS 4n
412 The handle is not bound.
416 .ne 2
418 \fB\fBSCF_ERROR_HANDLE_MISMATCH\fR\fR
420 .sp .6
421 .RS 4n
422 The \fIiter\fR and \fIparent\fR arguments are not derived from the same handle.
426 .ne 2
428 \fB\fBSCF_ERROR_CONNECTION_BROKEN\fR\fR
430 .sp .6
431 .RS 4n
432 The connection to the repository was lost.
437 The \fBscf_iter_scope_services()\fR, \fBscf_iter_service_instances()\fR,
438 \fBscf_iter_service_pgs()\fR, \fBscf_iter_instance_snapshots()\fR,
439 \fBscf_iter_instance_pgs()\fR, \fBscf_iter_instance_pgs_composed()\fR,
440 \fBscf_iter_snaplevel_pgs()\fR, \fBscf_iter_pg_properties()\fR,
441 \fBscf_iter_property_values()\fR, \fBscf_iter_service_pgs_typed()\fR,
442 \fBscf_iter_instance_pgs_typed()\fR,
443 \fBscf_iter_instance_pgs_typed_composed()\fR,
444 \fBscf_iter_snaplevel_pgs_typed()\fR, \fBscf_iter_next_service()\fR,
445 \fBscf_iter_next_instance()\fR, \fBscf_iter_next_snapshot()\fR,
446 \fBscf_iter_next_pg()\fR, and \fBscf_iter_next_property()\fR functions will
447 fail if:
449 .ne 2
451 \fB\fBSCF_ERROR_NO_RESOURCES\fR\fR
453 .RS 26n
454 The server does not have the resources to complete the request.
459 The \fBscf_error\fR(3SCF) function can be used to retrieve the error value.
460 .SH EXAMPLES
462 \fBExample 1 \fRIterate over all instances under a service.
464 .in +2
466 scf_iter_t *iter = scf_iter_create(handle);
468 if (iter == NULL || scf_iter_service_instances(iter, parent) == -1) {
469      /* failure */
471 while ((r = scf_iter_next_instance(iter, child)) > 0) {
472      /* process child */
474 if (r < 0) {
475      /* failure */
477 scf_iter_destroy(iter);
479 .in -2
482 \fBExample 2 \fRConnect to the repository, walk all services and instances and
483 print their FMRIs.
485 .in +2
487 scf_handle_t *handle = scf_handle_create(SCF_VERSION);
488 scf_scope_t *scope = scf_scope_create(handle);
489 scf_service_t *svc = scf_service_create(handle);
490 scf_instance_t *inst = scf_instance_create(handle);
491 scf_iter_t *svc_iter = scf_iter_create(handle);
492 scf_iter_t *inst_iter = scf_iter_create(handle);
494 size_t sz = scf_limit(SCF_LIMIT_MAX_FMRI_LENGTH) + 1;
495 char *fmri = malloc(sz + 1);
497 int r;
499 if (handle == NULL || scope == NULL || svc == NULL ||
500      inst == NULL || svc_iter == NULL || inst_iter == NULL ||
501      fmri == NULL) {
502          /* failure */
504 if (scf_handle_bind(handle) == -1 ||
505      scf_handle_get_scope(handle, SCF_SCOPE_LOCAL, scope) == -1 ||
506      scf_iter_scope_services(svc_iter, scope) == -1) {
507           /* failure */
509 while ((r = scf_iter_next_service(svc_iter, svc)) > 0) {
510      if (scf_service_to_fmri(svc, fmri, sz) < 0) {
511           /* failure */
512      }
513      puts(fmri);
514      if (scf_iter_service_instances(inst_iter, svc) < 0) {
515           /* failure */
516      }
517      while ((r = scf_iter_next_instance(inst_iter, inst)) > 0) {
518           if (scf_instance_to_fmri(inst, fmri, sz) < 0) {
519                /* failure */
520           }
521           puts(fmri);
522      }
523      if (r < 0)
524           break;
526 if (r < 0) {
527      /* failure */
530 scf_handle_destroy(handle);
531 scf_scope_destroy(scope);
532 scf_service_destroy(svc);
533 scf_instance_destroy(inst);
534 scf_iter_destroy(svc_iter);
535 scf_iter_destroy(inst_iter);
537 .in -2
539 .SH ATTRIBUTES
542 See \fBattributes\fR(5) for descriptions of the following attributes:
547 box;
548 c | c
549 l | l .
550 ATTRIBUTE TYPE  ATTRIBUTE VALUE
552 Interface Stability     Committed
554 MT-Level        Safe
557 .SH SEE ALSO
560 \fBlibscf\fR(3LIB), \fBscf_entry_add_value\fR(3SCF), \fBscf_error\fR(3SCF),
561 \fBscf_handle_create\fR(3SCF), \fBattributes\fR(5)