2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH EA_PACK_OBJECT 3EXACCT "Oct 4, 2007"
8 ea_pack_object, ea_unpack_object, ea_get_creator, ea_get_hostname,
9 ea_next_object, ea_previous_object, ea_get_object, ea_write_object,
10 ea_copy_object, ea_copy_object_tree, ea_get_object_tree \- construct, read, and
11 write extended accounting records
15 \fBcc\fR [ \fIflag\fR\&.\|.\|. ] \fIfile\fR\&.\|.\|. \fB-lexacct\fR [ \fIlibrary\fR\&.\|.\|. ]
18 \fBsize_t\fR \fBea_pack_object\fR(\fBea_object_t *\fR\fIobj\fR, \fBvoid *\fR\fIbuf\fR,
19 \fBsize_t\fR \fIbufsize\fR);
24 \fBea_object_type_t\fR \fBea_unpack_object\fR(\fBea_object_t **\fR\fIobjp\fR, \fBint\fR \fIflag\fR,
25 \fBvoid *\fR\fIbuf\fR, \fBsize_t\fR \fIbufsize\fR);
30 \fBconst char *\fR\fBea_get_creator\fR(\fBea_file_t *\fR\fIef\fR);
35 \fBconst char *\fR\fBea_get_hostname\fR(\fBea_file_t *\fR\fIef\fR);
40 \fBea_object_type_t\fR \fBea_next_object\fR(\fBea_file_t *\fR\fIef\fR, \fBea_object_t *\fR\fIobj\fR);
45 \fBea_object_type_t\fR \fBea_previous_object\fR(\fBea_file_t *\fR\fIef\fR,
46 \fBea_object_t *\fR\fIobj\fR);
51 \fBea_object_type_t\fR \fBea_get_object\fR(\fBea_file_t *\fR\fIef\fR, \fBea_object_t *\fR\fIobj\fR);
56 \fBint\fR \fBea_write_object\fR(\fBea_file_t *\fR\fIef\fR, \fBea_object_t *\fR\fIobj\fR);
61 \fBea_object_type_t *\fR\fBea_copy_object\fR(\fBconst ea_object_t *\fR\fIsrc\fR);
66 \fBea_object_type_t *\fR\fBea_copy_object_tree\fR(\fBconst ea_object_t *\fR\fIsrc\fR);
71 \fBea_object_type_t *\fR\fBea_get_object_tree\fR(\fBea_file_t *\fR\fIef\fR,
72 \fBuint32_t\fR\fInobj\fR);
78 The \fBea_pack_object()\fR function converts \fBexacct\fR objects from their
79 in-memory representation to their file representation. It is passed an object
80 pointer that points to the top of an \fBexacct\fR object hierarchy representing
81 one or more \fBexacct\fR records. It returns the size of the buffer required to
82 contain the packed buffer representing the object hierarchy. To obtain the
83 correct size of the required buffer, the \fIbuf\fR and \fIbufsize\fR parameters
84 can be set to \fINULL\fR and 0 respectively, and the required buffer size will
85 be returned. The resulting packed record can be passed to \fBputacct\fR(2) or
86 to \fBea_set_item\fR(3EXACCT) when constructing an object of type
87 \fBEXT_EXACCT_OBJECT\fR.
90 The \fBea_unpack_object()\fR function reverses the packing process performed by
91 \fBea_pack_object()\fR. A packed buffer passed to \fBea_unpack_object()\fR is
92 unpacked into the original hierarchy of objects. If the unpack operation fails
93 (for example, due to a corrupted or incomplete buffer), it returns
94 \fBEO_ERROR\fR; otherwise, the object type of the first object in the hierarchy
95 is returned. If \fBea_unpack_object()\fR is invoked with \fIflag\fR equal to
96 \fBEUP_ALLOC\fR, it allocates memory for the variable-length data in the
97 included objects. Otherwise, with \fIflag\fR equal to \fBEUP_NOALLOC\fR, it
98 sets the variable length data pointers within the unpacked object structures to
99 point within the buffer indicated by \fIbuf\fR. In both cases,
100 \fBea_unpack_object()\fR allocates all the necessary \fBexacct\fR objects to
101 represent the unpacked record. The resulting object hierarchy can be freed
102 using \fBea_free_object\fR(3EXACCT) with the same \fIflag\fR value.
105 The \fBea_get_creator()\fR function returns a pointer to a string representing
106 the recorded creator of the \fBexacct\fR file. The \fBea_get_hostname()\fR
107 function returns a pointer to a string representing the recorded hostname on
108 which the \fBexacct\fR file was created. These functions will return
109 \fINULL\fR if their respective field was not recorded in the exacct file
113 The \fBea_next_object()\fR function reads the basic fields (\fBeo_catalog\fR
114 and \fBeo_type\fR) into the \fBea_object_t\fR indicated by \fIobj\fR from the
115 \fBexacct\fR file referred to by \fIef\fR and rewinds to the head of the
116 record. If the read object is corrupted, \fBea_next_object()\fR returns
117 \fBEO_ERROR\fR and records the extended accounting error code, accessible with
118 \fBea_error\fR(3EXACCT). If end-of-file is reached, \fBEO_ERROR\fR is returned
119 and the extended accounting error code is set to \fBEXR_EOF\fR.
122 The \fBea_previous_object()\fR function skips back one object in the file and
123 reads its basic fields (\fBeo_catalog\fR and \fBeo_type\fR) into the indicated
124 \fBea_object_t\fR. If the read object is corrupted, \fBea_previous_object()\fR
125 returns \fBEO_ERROR\fR and records the extended accounting error code,
126 accessible with \fBea_error\fR(3EXACCT). If end-of-file is reached,
127 \fBEO_ERROR\fR is returned and the extended accounting error code is set to
131 The \fBea_get_object()\fR function reads the value fields into the
132 \fBea_object_t\fR indicated by \fIobj\fR, allocating memory as necessary, and
133 advances to the head of the next record. Once a record group object is
134 retrieved using \fBea_get_object()\fR, subsequent calls to
135 \fBea_get_object()\fR and \fBea_next_object()\fR will track through the objects
136 within the record group, and on reaching the end of the group, will return the
137 next object at the same level as the group from the file. If the read object is
138 corrupted, \fBea_get_object()\fR returns \fBEO_ERROR\fR and records the
139 extended accounting error code, accessible with \fBea_error\fR(3EXACCT). If
140 end-of-file is reached, \fBEO_ERROR\fR is returned and the extended accounting
141 error code is set to \fBEXR_EOF\fR.
144 The \fBea_write_object()\fR function appends the given object to the open
145 \fBexacct\fR file indicated by \fIef\fR and returns 0. If the write fails,
146 \fBea_write_object()\fR returns \(mi1 and sets the extended accounting error
147 code to indicate the error, accessible with \fBea_error\fR(3EXACCT).
150 The \fBea_copy_object()\fR function copies an \fBea_object_t\fR. If the source
151 object is part of a chain, only the current object is copied. If the source
152 object is a group, only the group object is copied without its list of members
153 and the \fBeg_nobjs\fR and \fBeg_objs\fR fields are set to 0 and \fINULL\fR,
154 respectively. Use \fBea_copy_tree()\fR to copy recursively a group or a list of
158 The \fBea_copy_object_tree()\fR function recursively copies an
159 \fBea_object_t\fR. All elements in the \fBeo_next\fR list are copied, and any
160 group objects are recursively copied. The returned object can be completely
161 freed with \fBea_free_object\fR(3EXACCT) by specifying the \fBEUP_ALLOC\fR
165 The \fBea_get_object_tree()\fR function reads in \fInobj\fR top-level objects
166 from the file, returning the same data structure that would have originally
167 been passed to \fBea_write_object()\fR. On encountering a group object, the
168 \fBea_get_object()\fR function reads only the group header part of the group,
169 whereas \fBea_get_object_tree()\fR reads the group and all its member items,
170 recursing into sub-records if necessary. The returned object data structure can
171 be completely freed with \fBea_free_object()\fR by specifying the
172 \fBEUP_ALLOC\fR flag.
176 The \fBea_pack_object()\fR function returns the number of bytes required to
177 hold the \fBexacct\fR object being operated upon. If the returned size exceeds
178 \fIbufsize\fR, the pack operation does not complete and the function returns
179 (\fBsize_t\fR) -1 and sets the extended accounting error code to indicate the
183 The \fBea_get_object()\fR function returns the \fBea_object_type\fR of the
184 object if the object was retrieved successfully. Otherwise, it returns
185 \fBEO_ERROR\fR and sets the extended accounting error code to indicate the
189 The \fBea_next_object()\fR function returns the \fBea_object_type\fR of the
190 next \fBexacct\fR object in the file. It returns \fBEO_ERROR\fR if the
191 \fBexacct\fR file is corrupted sets the extended accounting error code to
195 The \fBea_unpack_object()\fR function returns the \fBea_object_type\fR of the
196 first \fBexacct\fR object unpacked from the buffer. It returns \fBEO_ERROR\fR
197 if the exacct file is corrupted, and sets the extended accounting error code to
201 The \fBea_write_object()\fR function returns 0 on success. Otherwise it returns
202 \(mi1 and sets the extended accounting error code to indicate the error.
205 The \fBea_copy_object()\fR and \fBea_copy_object_tree()\fR functions return the
206 copied object on success. Otherwise they return \fINULL\fR and set the extended
207 accounting error code to indicate the error.
210 The \fBea_get_object_tree()\fR function returns the list of objects read from
211 the file on success. Otherwise it returns \fINULL\fR and sets the extended
212 accounting error code to indicate the error.
215 The extended account error code can be retrieved using \fBea_error\fR(3EXACCT).
219 These functions may fail if:
223 \fB\fBEXR_SYSCALL_FAIL\fR\fR
227 A system call invoked by the function failed. The \fBerrno\fR variable contains
228 the error value set by the underlying call. On memory allocation failure,
229 \fBerrno\fR will be set to \fBENOMEM\fR.
235 \fB\fBEXR_CORRUPT_FILE\fR\fR
239 The file referred to by \fIname\fR is not a valid \fBexacct\fR file, or is
240 unparsable, and therefore appears corrupted. This error is also used by
241 \fBea_unpack_buffer()\fR to indicate a corrupted buffer.
251 The end of the file has been reached. In the case of
252 \fBea_previous_record()\fR, the previous record could not be reached, either
253 because the head of the file was encountered or because the previous record
254 could not be skipped over.
260 The \fBexacct\fR file format can be used to represent data other than that in
261 the extended accounting format. By using a unique creator type in the file
262 header, application writers can develop their own format suited to the needs of
266 \fBExample 1 \fROpen and close \fBexacct\fR file.
269 The following example opens the extended accounting data file for processes.
270 The \fBexacct\fR file is then closed.
283 ea_open(&ef, "foo", O_RDONLY, ...);
285 while ((obj = ea_get_object_tree(&ef, 1)) != NULL) {
286 if (obj->eo_type == EO_ITEM) {
291 ea_free_object(obj, EUP_ALLOC);
294 if (ea_error() != EXR_EOF) {
303 \fBExample 2 \fRConstruct an \fBexacct\fR file consisting of a single object
304 containing the current process ID.
308 #include <sys/types.h>
318 ea_open(&ef, "foo", O_CREAT | O_WRONLY, ...);
321 ea_set_item(&obj, EXT_UINT32 | EXC_DEFAULT | EXT_PROC_PID, &my_pid, 0);
322 (void) ea_write_object(&ef, &obj);
333 See \fBattributes\fR(5) for descriptions of the following attributes:
341 ATTRIBUTE TYPE ATTRIBUTE VALUE
343 Interface Stability Committed
351 \fBread\fR(2), \fBea_error\fR(3EXACCT), \fBea_open\fR(3EXACCT),
352 \fBea_set_item\fR(3EXACCT), \fBlibexacct\fR(3LIB), \fBattributes\fR(5)