xref: /freebsd/lib/libc/gen/fmtmsg.3 (revision ae828962685b8ae9e5104ce8e7fe8b05effcb9ec)
1823f68a2SMike Barcroft.\"
2823f68a2SMike Barcroft.\" Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
3823f68a2SMike Barcroft.\" All rights reserved.
4823f68a2SMike Barcroft.\"
5823f68a2SMike Barcroft.\" Redistribution and use in source and binary forms, with or without
6823f68a2SMike Barcroft.\" modification, are permitted provided that the following conditions
7823f68a2SMike Barcroft.\" are met:
8823f68a2SMike Barcroft.\" 1. Redistributions of source code must retain the above copyright
9823f68a2SMike Barcroft.\"    notice, this list of conditions and the following disclaimer.
10823f68a2SMike Barcroft.\" 2. Redistributions in binary form must reproduce the above copyright
11823f68a2SMike Barcroft.\"    notice, this list of conditions and the following disclaimer in the
12823f68a2SMike Barcroft.\"    documentation and/or other materials provided with the distribution.
13823f68a2SMike Barcroft.\"
14823f68a2SMike Barcroft.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15823f68a2SMike Barcroft.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16823f68a2SMike Barcroft.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17823f68a2SMike Barcroft.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18823f68a2SMike Barcroft.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19823f68a2SMike Barcroft.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20823f68a2SMike Barcroft.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21823f68a2SMike Barcroft.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22823f68a2SMike Barcroft.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23823f68a2SMike Barcroft.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24823f68a2SMike Barcroft.\" SUCH DAMAGE.
25823f68a2SMike Barcroft.\"
26823f68a2SMike Barcroft.\" $FreeBSD$
27823f68a2SMike Barcroft.\"
28823f68a2SMike Barcroft.Dd August 5, 2002
29823f68a2SMike Barcroft.Dt FMTMSG 3
30823f68a2SMike Barcroft.Os
31823f68a2SMike Barcroft.Sh NAME
32823f68a2SMike Barcroft.Nm fmtmsg
33823f68a2SMike Barcroft.Nd display a detailed diagnostic message
34823f68a2SMike Barcroft.Sh LIBRARY
35823f68a2SMike Barcroft.Lb libc
36823f68a2SMike Barcroft.Sh SYNOPSIS
37823f68a2SMike Barcroft.In fmtmsg.h
38823f68a2SMike Barcroft.Ft int
39304d1f73SRuslan Ermilov.Fo fmtmsg
40304d1f73SRuslan Ermilov.Fa "long classification" "const char *label" "int severity"
41304d1f73SRuslan Ermilov.Fa "const char *text" "const char *action" "const char *tag"
42304d1f73SRuslan Ermilov.Fc
43823f68a2SMike Barcroft.Sh DESCRIPTION
44823f68a2SMike BarcroftThe
45823f68a2SMike Barcroft.Fn fmtmsg
46823f68a2SMike Barcroftfunction displays a detailed diagnostic message, based on
47304d1f73SRuslan Ermilovthe supplied arguments, to
48ae828962SRuslan Ermilov.Dv stderr
49823f68a2SMike Barcroftand/or the system console.
50823f68a2SMike Barcroft.Pp
51823f68a2SMike BarcroftThe
52823f68a2SMike Barcroft.Fa classification
53823f68a2SMike Barcroftargument is the bitwise inclusive
54823f68a2SMike Barcroft.Tn OR
55823f68a2SMike Barcroftof zero or one of the manifest constants from
56823f68a2SMike Barcrofteach of the classification groups below.
57823f68a2SMike BarcroftThe Output classification group is an exception since both
58823f68a2SMike Barcroft.Dv MM_PRINT
59823f68a2SMike Barcroftand
60823f68a2SMike Barcroft.Dv MM_CONSOLE
61823f68a2SMike Barcroftmay be specified.
62304d1f73SRuslan Ermilov.Bl -tag -width indent
63304d1f73SRuslan Ermilov.It Output
64304d1f73SRuslan Ermilov.Bl -tag -width ".Dv MM_CONSOLE"
65823f68a2SMike Barcroft.It Dv MM_PRINT
66823f68a2SMike BarcroftOutput should take place on
67ae828962SRuslan Ermilov.Dv stderr .
68823f68a2SMike Barcroft.It Dv MM_CONSOLE
69823f68a2SMike BarcroftOutput should take place on the system console.
70823f68a2SMike Barcroft.El
71304d1f73SRuslan Ermilov.It "Source of Condition (Major)"
72304d1f73SRuslan Ermilov.Bl -tag -width ".Dv MM_CONSOLE"
73823f68a2SMike Barcroft.It Dv MM_HARD
74823f68a2SMike BarcroftThe source of the condition is hardware related.
75823f68a2SMike Barcroft.It Dv MM_SOFT
76823f68a2SMike BarcroftThe source of the condition is software related.
77823f68a2SMike Barcroft.It Dv MM_FIRM
78823f68a2SMike BarcroftThe source of the condition is firmware related.
79823f68a2SMike Barcroft.El
80304d1f73SRuslan Ermilov.It "Source of Condition (Minor)"
81304d1f73SRuslan Ermilov.Bl -tag -width ".Dv MM_CONSOLE"
82823f68a2SMike Barcroft.It Dv MM_APPL
83823f68a2SMike BarcroftThe condition was detected at the application level.
84823f68a2SMike Barcroft.It Dv MM_UTIL
85823f68a2SMike BarcroftThe condition was detected at the utility level.
86823f68a2SMike Barcroft.It Dv MM_OPSYS
87823f68a2SMike BarcroftThe condition was detected at the operating system level.
88823f68a2SMike Barcroft.El
89304d1f73SRuslan Ermilov.It Status
90304d1f73SRuslan Ermilov.Bl -tag -width ".Dv MM_CONSOLE"
91823f68a2SMike Barcroft.It Dv MM_RECOVER
92823f68a2SMike BarcroftThe application can recover from the condition.
93823f68a2SMike Barcroft.It Dv MM_NRECOV
94823f68a2SMike BarcroftThe application is unable to recover from the condition.
95823f68a2SMike Barcroft.El
96304d1f73SRuslan Ermilov.El
97823f68a2SMike Barcroft.Pp
98823f68a2SMike BarcroftAlternatively, the
99823f68a2SMike Barcroft.Dv MM_NULLMC
100823f68a2SMike Barcroftmanifest constant may be used to specify no classification.
101823f68a2SMike Barcroft.Pp
102823f68a2SMike BarcroftThe
103823f68a2SMike Barcroft.Fa label
104823f68a2SMike Barcroftargument indicates the source of the message.
1052b239dd1SJens SchweikhardtIt is made up of two fields separated by a colon
106304d1f73SRuslan Ermilov.Pq Ql \&: .
107823f68a2SMike BarcroftThe first field can be up to 10 bytes,
108823f68a2SMike Barcroftand the second field can be up to 14 bytes.
109823f68a2SMike BarcroftThe
110823f68a2SMike Barcroft.Dv MM_NULLLBL
111823f68a2SMike Barcroftmanifest constant may be used to specify no label.
112823f68a2SMike Barcroft.Pp
113823f68a2SMike BarcroftThe
114823f68a2SMike Barcroft.Fa severity
115823f68a2SMike Barcroftargument identifies the importance of the condition.
116823f68a2SMike BarcroftOne of the following manifest constants should be used for this argument.
117304d1f73SRuslan Ermilov.Bl -tag -offset indent -width ".Dv MM_WARNING"
118823f68a2SMike Barcroft.It Dv MM_HALT
119823f68a2SMike BarcroftThe application has confronted a serious fault and is halting.
120823f68a2SMike Barcroft.It Dv MM_ERROR
121823f68a2SMike BarcroftThe application has detected a fault.
122823f68a2SMike Barcroft.It Dv MM_WARNING
123823f68a2SMike BarcroftThe application has detected an unusual condition,
124823f68a2SMike Barcroftthat could be indicative of a problem.
125823f68a2SMike Barcroft.It Dv MM_INFO
126823f68a2SMike BarcroftThe application is providing information about a non-error condition.
127823f68a2SMike Barcroft.It Dv MM_NOSEV
128823f68a2SMike BarcroftNo severity level supplied.
129823f68a2SMike Barcroft.El
130823f68a2SMike Barcroft.Pp
131823f68a2SMike BarcroftThe
132823f68a2SMike Barcroft.Fa text
133823f68a2SMike Barcroftargument details the error condition that caused the message.
134823f68a2SMike BarcroftThere is no limit on the size of this character string.
135823f68a2SMike BarcroftThe
136823f68a2SMike Barcroft.Dv MM_NULLTXT
137823f68a2SMike Barcroftmanifest constant may be used to specify no text.
138823f68a2SMike Barcroft.Pp
139823f68a2SMike BarcroftThe
140823f68a2SMike Barcroft.Fa action
141823f68a2SMike Barcroftargument details how the error-recovery process should begin.
142823f68a2SMike BarcroftUpon output,
143823f68a2SMike Barcroft.Fn fmtmsg
144823f68a2SMike Barcroftwill prefix
145304d1f73SRuslan Ermilov.Qq Li "TO FIX:"
146304d1f73SRuslan Ermilovto the beginning of the
147823f68a2SMike Barcroft.Fa action
148823f68a2SMike Barcroftargument.
149823f68a2SMike BarcroftThe
150823f68a2SMike Barcroft.Dv MM_NULLACT
151823f68a2SMike Barcroftmanifest constant may be used to specify no action.
152823f68a2SMike Barcroft.Pp
153823f68a2SMike BarcroftThe
154823f68a2SMike Barcroft.Fa tag
155823f68a2SMike Barcroftargument should reference online documentation for the message.
156823f68a2SMike BarcroftThis usually includes the
157823f68a2SMike Barcroft.Fa label
158823f68a2SMike Barcroftand a unique identifying number.
159823f68a2SMike BarcroftAn example tag is
160304d1f73SRuslan Ermilov.Qq Li BSD:ls:168 .
161823f68a2SMike BarcroftThe
162823f68a2SMike Barcroft.Dv MM_NULLTAG
163823f68a2SMike Barcroftmanifest constant may be used to specify no tag.
164823f68a2SMike Barcroft.Sh RETURN VALUES
165823f68a2SMike BarcroftThe
166823f68a2SMike Barcroft.Fn fmtmsg
167823f68a2SMike Barcroftfunction returns
168823f68a2SMike Barcroft.Dv MM_OK
169823f68a2SMike Barcroftupon success,
170823f68a2SMike Barcroft.Dv MM_NOMSG
171823f68a2SMike Barcroftto indicate output to
172ae828962SRuslan Ermilov.Dv stderr
173823f68a2SMike Barcroftfailed,
174823f68a2SMike Barcroft.Dv MM_NOCON
175823f68a2SMike Barcroftto indicate output to the system console failed, or
176823f68a2SMike Barcroft.Dv MM_NOTOK
177823f68a2SMike Barcroftto indicate output to
178ae828962SRuslan Ermilov.Dv stderr
179823f68a2SMike Barcroftand the system console failed.
180823f68a2SMike Barcroft.Sh ENVIRONMENT
181823f68a2SMike BarcroftThe
182304d1f73SRuslan Ermilov.Ev MSGVERB
183304d1f73SRuslan Ermilov(message verbosity)
184823f68a2SMike Barcroftenvironment variable specifies which arguments to
185823f68a2SMike Barcroft.Fn fmtmsg
1862b239dd1SJens Schweikhardtwill be output to
187ae828962SRuslan Ermilov.Dv stderr ,
188823f68a2SMike Barcroftand in which order.
189304d1f73SRuslan Ermilov.Ev MSGVERB
190823f68a2SMike Barcroftshould be a colon
191304d1f73SRuslan Ermilov.Pq Ql \&:
1922b239dd1SJens Schweikhardtseparated list of identifiers.
193304d1f73SRuslan ErmilovValid identifiers include:
194304d1f73SRuslan Ermilov.Li label , severity , text , action ,
195304d1f73SRuslan Ermilovand
196304d1f73SRuslan Ermilov.Li tag .
1972b239dd1SJens SchweikhardtIf invalid identifiers are specified or incorrectly separated,
198823f68a2SMike Barcroftthe default message verbosity and ordering will be used.
199823f68a2SMike BarcroftThe default ordering is equivalent to a
200304d1f73SRuslan Ermilov.Ev MSGVERB
201823f68a2SMike Barcroftwith a value of
202304d1f73SRuslan Ermilov.Qq Li label:severity:text:action:tag .
203823f68a2SMike Barcroft.Sh EXAMPLES
204823f68a2SMike BarcroftThe code:
205823f68a2SMike Barcroft.Bd -literal -offset indent
206823f68a2SMike Barcroftfmtmsg(MM_UTIL | MM_PRINT, "BSD:ls", MM_ERROR,
207823f68a2SMike Barcroft    "illegal option -- z", "refer to manual", "BSD:ls:001");
208823f68a2SMike Barcroft.Ed
209823f68a2SMike Barcroft.Pp
210823f68a2SMike Barcroftwill output:
211823f68a2SMike Barcroft.Bd -literal -offset indent
212823f68a2SMike BarcroftBSD:ls: ERROR: illegal option -- z
213823f68a2SMike BarcroftTO FIX: refer to manual BSD:ls:001
214823f68a2SMike Barcroft.Ed
215823f68a2SMike Barcroft.Pp
216823f68a2SMike Barcroftto
217ae828962SRuslan Ermilov.Dv stderr .
218823f68a2SMike Barcroft.Pp
219823f68a2SMike BarcroftThe same code, with
220304d1f73SRuslan Ermilov.Ev MSGVERB
221823f68a2SMike Barcroftset to
222304d1f73SRuslan Ermilov.Qq Li "text:severity:action:tag" ,
223823f68a2SMike Barcroftproduces:
224823f68a2SMike Barcroft.Bd -literal -offset indent
225823f68a2SMike Barcroftillegal option -- z: ERROR
226823f68a2SMike BarcroftTO FIX: refer to manual BSD:ls:001
227823f68a2SMike Barcroft.Ed
228823f68a2SMike Barcroft.Sh SEE ALSO
229823f68a2SMike Barcroft.Xr err 3 ,
230823f68a2SMike Barcroft.Xr exit 3 ,
231823f68a2SMike Barcroft.Xr strerror 3
232823f68a2SMike Barcroft.Sh STANDARDS
233823f68a2SMike BarcroftThe
234823f68a2SMike Barcroft.Fn fmtmsg
235823f68a2SMike Barcroftfunction conforms to
236823f68a2SMike Barcroft.St -p1003.1-2001 .
237823f68a2SMike Barcroft.Sh HISTORY
238823f68a2SMike BarcroftThe
239823f68a2SMike Barcroft.Fn fmtmsg
240823f68a2SMike Barcroftfunction first appeared in
241823f68a2SMike Barcroft.Fx 5.0 .
242823f68a2SMike Barcroft.Sh BUGS
243823f68a2SMike BarcroftSpecifying
244823f68a2SMike Barcroft.Dv MM_NULLMC
245823f68a2SMike Barcroftfor the
246823f68a2SMike Barcroft.Fa classification
247823f68a2SMike Barcroftargument makes little sense, since without an output specified,
248823f68a2SMike Barcroft.Fn fmtmsg
249823f68a2SMike Barcroftis unable to do anything useful.
250823f68a2SMike Barcroft.Pp
251823f68a2SMike BarcroftIn order for
252823f68a2SMike Barcroft.Fn fmtmsg
253823f68a2SMike Barcroftto output to the system console, the effective
254823f68a2SMike Barcroftuser must have appropriate permission to write to
255823f68a2SMike Barcroft.Pa /dev/console .
256823f68a2SMike BarcroftThis means that on most systems
257823f68a2SMike Barcroft.Fn fmtmsg
258823f68a2SMike Barcroftwill return
259823f68a2SMike Barcroft.Dv MM_NOCON
260823f68a2SMike Barcroftunless the effective user is root.
261