xref: /minix3/crypto/external/bsd/heimdal/dist/lib/com_err/com_err.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: com_err.3,v 1.3 2014/04/24 13:45:34 pettai Exp $
2ebfedea0SLionel Sambuc.\"
3ebfedea0SLionel Sambuc.\" Copyright (c) 2005 Kungliga Tekniska Högskolan
4ebfedea0SLionel Sambuc.\" (Royal Institute of Technology, Stockholm, Sweden).
5ebfedea0SLionel Sambuc.\" All rights reserved.
6ebfedea0SLionel Sambuc.\"
7ebfedea0SLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
8ebfedea0SLionel Sambuc.\" modification, are permitted provided that the following conditions
9ebfedea0SLionel Sambuc.\" are met:
10ebfedea0SLionel Sambuc.\"
11ebfedea0SLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
12ebfedea0SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
13ebfedea0SLionel Sambuc.\"
14ebfedea0SLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
15ebfedea0SLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
16ebfedea0SLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
17ebfedea0SLionel Sambuc.\"
18ebfedea0SLionel Sambuc.\" 3. Neither the name of the Institute nor the names of its contributors
19ebfedea0SLionel Sambuc.\"    may be used to endorse or promote products derived from this software
20ebfedea0SLionel Sambuc.\"    without specific prior written permission.
21ebfedea0SLionel Sambuc.\"
22ebfedea0SLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
23ebfedea0SLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24ebfedea0SLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25ebfedea0SLionel Sambuc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
26ebfedea0SLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27ebfedea0SLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28ebfedea0SLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29ebfedea0SLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30ebfedea0SLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31ebfedea0SLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32ebfedea0SLionel Sambuc.\" SUCH DAMAGE.
33ebfedea0SLionel Sambuc.\"
34ebfedea0SLionel Sambuc.\" Id
35ebfedea0SLionel Sambuc.\"
36ebfedea0SLionel Sambuc.\" This manpage was contributed by Gregory McGarry.
37ebfedea0SLionel Sambuc.\"
38ebfedea0SLionel Sambuc.Dd July  7, 2005
39ebfedea0SLionel Sambuc.Dt COM_ERR 3
40ebfedea0SLionel Sambuc.Os
41ebfedea0SLionel Sambuc.Sh NAME
42ebfedea0SLionel Sambuc.Nm com_err ,
43ebfedea0SLionel Sambuc.Nm com_err_va ,
44ebfedea0SLionel Sambuc.Nm error_message ,
45ebfedea0SLionel Sambuc.Nm error_table_name ,
46ebfedea0SLionel Sambuc.Nm init_error_table ,
47ebfedea0SLionel Sambuc.Nm set_com_err_hook ,
48ebfedea0SLionel Sambuc.Nm reset_com_err_hook ,
49ebfedea0SLionel Sambuc.Nm add_to_error_table ,
50ebfedea0SLionel Sambuc.Nm initialize_error_table_r
51ebfedea0SLionel Sambuc.Nm free_error_table ,
52ebfedea0SLionel Sambuc.Nm com_right
53ebfedea0SLionel Sambuc.Nd common error display library
54ebfedea0SLionel Sambuc.Sh LIBRARY
55ebfedea0SLionel SambucCommon Error Library (libcom_err, -lcom_err)
56ebfedea0SLionel Sambuc.Sh SYNOPSIS
57ebfedea0SLionel Sambuc.Fd #include <stdio.h>
58ebfedea0SLionel Sambuc.Fd #include <stdarg.h>
59ebfedea0SLionel Sambuc.Fd #include <krb5/com_err.h>
60ebfedea0SLionel Sambuc.Fd #include \&"XXX_err.h\&"
61ebfedea0SLionel Sambuc.Pp
62ebfedea0SLionel Sambuctypedef void (*errf)(const char *, long, const char *, ...);
63ebfedea0SLionel Sambuc.Ft void
64ebfedea0SLionel Sambuc.Fn com_err "const char *whoami" "long code" "const char *format" "..."
65ebfedea0SLionel Sambuc.Ft void
66ebfedea0SLionel Sambuc.Fn com_err_va "const char *whoami" "long code" "const char *format" "..."
67ebfedea0SLionel Sambuc.Ft const char *
68ebfedea0SLionel Sambuc.Fn error_message "long code"
69ebfedea0SLionel Sambuc.Ft const char *
70ebfedea0SLionel Sambuc.Fn error_table_name "int num"
71ebfedea0SLionel Sambuc.Ft int
72ebfedea0SLionel Sambuc.Fn init_error_table "const char **msgs" "long base" "int count"
73ebfedea0SLionel Sambuc.Ft errf
74ebfedea0SLionel Sambuc.Fn set_com_err_hook "errf func"
75ebfedea0SLionel Sambuc.Ft errf
76ebfedea0SLionel Sambuc.Fn reset_com_err_hook ""
77ebfedea0SLionel Sambuc.Ft void
78ebfedea0SLionel Sambuc.Fn add_to_error_table "struct et_list *new_table"
79ebfedea0SLionel Sambuc.Ft void
80ebfedea0SLionel Sambuc.Fn initialize_error_table_r "struct et_list **et_list" "const char **msgs" "int base" "long count"
81ebfedea0SLionel Sambuc.Ft void
82ebfedea0SLionel Sambuc.Fn free_error_table "struct et_list *"
83ebfedea0SLionel Sambuc.Ft const char *
84ebfedea0SLionel Sambuc.Fn com_right "struct et_list *list" long code"
85ebfedea0SLionel Sambuc.Sh DESCRIPTION
86ebfedea0SLionel SambucThe
87ebfedea0SLionel Sambuc.Nm
88ebfedea0SLionel Sambuclibrary provides a common error-reporting mechanism for defining and
89ebfedea0SLionel Sambucaccessing error codes and descriptions for application software
90ebfedea0SLionel Sambucpackages.  Error descriptions are defined in a table and error codes
91ebfedea0SLionel Sambucare used to index the table.  The error table, the descriptions and
92ebfedea0SLionel Sambucthe error codes are generated using
93ebfedea0SLionel Sambuc.Xr compile_et 1 .
94ebfedea0SLionel Sambuc.Pp
95ebfedea0SLionel SambucThe error table is registered with the
96ebfedea0SLionel Sambuc.Nm
97ebfedea0SLionel Sambuclibrary by calling its initialisation function defined in its header
98ebfedea0SLionel Sambucfile.  The initialisation function is generally defined as
99ebfedea0SLionel Sambuc.Fn initialize_<name>_error_table ,
100ebfedea0SLionel Sambucwhere
101ebfedea0SLionel Sambuc.Em name
102ebfedea0SLionel Sambucis the name of the error table.
103ebfedea0SLionel Sambuc.Pp
104ebfedea0SLionel SambucIf a thread-safe version of the library is needed
105ebfedea0SLionel Sambuc.Fn initialize_<name>_error_table_r
106ebfedea0SLionel Sambucthat internally calls
107ebfedea0SLionel Sambuc.Fn initialize_error_table_r
108ebfedea0SLionel Sambucinstead be used.
109ebfedea0SLionel Sambuc.Pp
110ebfedea0SLionel SambucAny variable which is to contain an error code should be declared
111ebfedea0SLionel Sambuc.Em <name>_error_number
112ebfedea0SLionel Sambucwhere
113ebfedea0SLionel Sambuc.Em name
114ebfedea0SLionel Sambucis the name of the error table.
115ebfedea0SLionel Sambuc.Sh FUNCTIONS
116ebfedea0SLionel SambucThe following functions are available to the application developer:
117ebfedea0SLionel Sambuc.Bl -tag -width compact
118ebfedea0SLionel Sambuc.It Fn com_err "whoami" "code" "format" "..."
119ebfedea0SLionel SambucDisplays an error message on standard error composed of the
120ebfedea0SLionel Sambuc.Fa whoami
121ebfedea0SLionel Sambucstring, which should specify the program name, followed by an error
122ebfedea0SLionel Sambucmessage generated from
123ebfedea0SLionel Sambuc.Fa code ,
124ebfedea0SLionel Sambucand a string produced using the
125ebfedea0SLionel Sambuc.Xr printf 3
126ebfedea0SLionel Sambuc.Fa format
127ebfedea0SLionel Sambucstring and any following arguments.  If
128ebfedea0SLionel Sambuc.Fa format
129ebfedea0SLionel Sambucis NULL, the formatted message will not be
130ebfedea0SLionel Sambucprinted.  The argument
131ebfedea0SLionel Sambuc.Fa format
132ebfedea0SLionel Sambucmay not be omitted.
133ebfedea0SLionel Sambuc.It Fn com_err_va "whoami" "code" "format" "va_list args"
134ebfedea0SLionel SambucThis routine provides an interface, equivalent to
135ebfedea0SLionel Sambuc.Fn com_err ,
136ebfedea0SLionel Sambucwhich may be used by higher-level variadic functions (functions which
137ebfedea0SLionel Sambucaccept variable numbers of arguments).
138ebfedea0SLionel Sambuc.It Fn error_message "code"
139ebfedea0SLionel SambucReturns the character string error message associated with
140ebfedea0SLionel Sambuc.Fa code .
141ebfedea0SLionel SambucIf
142ebfedea0SLionel Sambuc.Fa code
143ebfedea0SLionel Sambucis associated with an unknown error table, or if
144ebfedea0SLionel Sambuc.Fa code
145ebfedea0SLionel Sambucis associated with a known error table but is not in the table, a
146ebfedea0SLionel Sambucstring of the form `Unknown code XXXX NN' is returned, where XXXX is
147ebfedea0SLionel Sambucthe error table name produced by reversing the compaction performed on
148ebfedea0SLionel Sambucthe error table number implied by that error code, and NN is the
149ebfedea0SLionel Sambucoffset from that base value.
150ebfedea0SLionel Sambuc.Pp
151ebfedea0SLionel SambucAlthough this routine is available for use when needed, its use should
152ebfedea0SLionel Sambucbe left to circumstances which render
153ebfedea0SLionel Sambuc.Fn com_err
154ebfedea0SLionel Sambucunusable.
155ebfedea0SLionel Sambuc.Pp
156ebfedea0SLionel Sambuc.Fn com_right
157ebfedea0SLionel Sambucreturns the error string just like
158ebfedea0SLionel Sambuc.Fa com_err
159ebfedea0SLionel Sambucbut in a thread-safe way.
160ebfedea0SLionel Sambuc.Pp
161ebfedea0SLionel Sambuc.It Fn error_table_name "num"
162ebfedea0SLionel SambucConvert a machine-independent error table number
163ebfedea0SLionel Sambuc.Fa num
164ebfedea0SLionel Sambucinto an error table name.
165ebfedea0SLionel Sambuc.It Fn init_error_table "msgs" "base" "count"
166ebfedea0SLionel SambucInitialise the internal error table with the array of character string
167ebfedea0SLionel Sambucerror messages in
168ebfedea0SLionel Sambuc.Fa msgs
169ebfedea0SLionel Sambucof length
170ebfedea0SLionel Sambuc.Fa count .
171ebfedea0SLionel SambucThe error codes are assigned incrementally from
172ebfedea0SLionel Sambuc.Fa base .
173ebfedea0SLionel SambucThis function is useful for using the error-reporting mechanism with
174ebfedea0SLionel Sambuccustom error tables that have not been generated with
175ebfedea0SLionel Sambuc.Xr compile_et 1 .
176ebfedea0SLionel SambucAlthough this routine is available for use when needed, its use should
177ebfedea0SLionel Sambucbe restricted.
178ebfedea0SLionel Sambuc.Pp
179ebfedea0SLionel Sambuc.Fn initialize_error_table_r
180ebfedea0SLionel Sambucinitialize the
181ebfedea0SLionel Sambuc.Fa et_list
182ebfedea0SLionel Sambucin the same way as
183ebfedea0SLionel Sambuc.Fn init_error_table ,
184ebfedea0SLionel Sambucbut in a thread-safe way.
185ebfedea0SLionel Sambuc.Pp
186ebfedea0SLionel Sambuc.It Fn set_com_err_hook "func"
187ebfedea0SLionel SambucProvides a hook into the
188ebfedea0SLionel Sambuc.Nm
189ebfedea0SLionel Sambuclibrary to allow the routine
190ebfedea0SLionel Sambuc.Fa func
191ebfedea0SLionel Sambucto be dynamically substituted for
192ebfedea0SLionel Sambuc.Fn com_err .
193ebfedea0SLionel SambucAfter
194ebfedea0SLionel Sambuc.Fn set_com_err_hook
195ebfedea0SLionel Sambuc has been called, calls to
196ebfedea0SLionel Sambuc.Fn com_err
197ebfedea0SLionel Sambucwill turn into calls to the new hook routine.  This function is
198ebfedea0SLionel Sambucintended to be used in daemons to use a routine which calls
199ebfedea0SLionel Sambuc.Xr syslog 3 ,
200ebfedea0SLionel Sambucor in a window system application to pop up a dialogue box.
201ebfedea0SLionel Sambuc.It Fn reset_com_err_hook ""
202ebfedea0SLionel SambucTurns off the hook set in
203ebfedea0SLionel Sambuc.Fn set_com_err_hook .
204ebfedea0SLionel Sambuc.It Fn add_to_error_table "new_table"
205ebfedea0SLionel SambucAdd the error table, its messages strings and error codes in
206ebfedea0SLionel Sambuc.Fa new_table
207ebfedea0SLionel Sambucto the internal error table.
208ebfedea0SLionel Sambuc.El
209ebfedea0SLionel Sambuc.Sh EXAMPLES
210ebfedea0SLionel SambucThe following is an example using the table defined in
211ebfedea0SLionel Sambuc.Xr compile_et 1 :
212ebfedea0SLionel Sambuc.Pp
213ebfedea0SLionel Sambuc.Bd -literal
214ebfedea0SLionel Sambuc	#include <stdio.h>
215ebfedea0SLionel Sambuc	#include <stdarg.h>
216ebfedea0SLionel Sambuc	#include <syslog.h>
217ebfedea0SLionel Sambuc
218ebfedea0SLionel Sambuc	#include "test_err.h"
219ebfedea0SLionel Sambuc
220ebfedea0SLionel Sambuc	void
221ebfedea0SLionel Sambuc	hook(const char *whoami, long code,
222ebfedea0SLionel Sambuc		const char *format, va_list args)
223ebfedea0SLionel Sambuc	{
224ebfedea0SLionel Sambuc		char buffer[BUFSIZ];
225ebfedea0SLionel Sambuc		static int initialized = 0;
226ebfedea0SLionel Sambuc
227ebfedea0SLionel Sambuc		if (!initialized) {
228ebfedea0SLionel Sambuc			openlog(whoami, LOG_NOWAIT, LOG_DAEMON);
229ebfedea0SLionel Sambuc			initialized = 1;
230ebfedea0SLionel Sambuc		}
231ebfedea0SLionel Sambuc		vsprintf(buffer, format, args);
232ebfedea0SLionel Sambuc		syslog(LOG_ERR, "%s %s", error_message(code), buffer);
233ebfedea0SLionel Sambuc	}
234ebfedea0SLionel Sambuc
235ebfedea0SLionel Sambuc	int
236ebfedea0SLionel Sambuc	main(int argc, char *argv[])
237ebfedea0SLionel Sambuc	{
238ebfedea0SLionel Sambuc		char *whoami = argv[0];
239ebfedea0SLionel Sambuc
240ebfedea0SLionel Sambuc		initialize_test_error_table();
241ebfedea0SLionel Sambuc		com_err(whoami, TEST_INVAL, "before hook");
242ebfedea0SLionel Sambuc		set_com_err_hook(hook);
243ebfedea0SLionel Sambuc		com_err(whoami, TEST_IO, "after hook");
244ebfedea0SLionel Sambuc		return (0);
245ebfedea0SLionel Sambuc	}
246ebfedea0SLionel Sambuc.Ed
247ebfedea0SLionel Sambuc.Sh SEE ALSO
248ebfedea0SLionel Sambuc.Xr compile_et 1
249