]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/fmtmsg.3
ffix
[thirdparty/man-pages.git] / man3 / fmtmsg.3
CommitLineData
fea681da
MK
1.\" Copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de)
2.\" Distributed under GPL
3.\" adapted glibc info page
c13182ef 4.\"
fea681da
MK
5.\" This should run as 'Guru Meditation' (amiga joke :)
6.\" The function is quite complex an deserves an example
7.\"
8.\" Polished, aeb, 2003-11-01
3d5a3539 9.TH FMTMSG 3 2003-11-01 "" "Linux Programmer's Manual"
fea681da
MK
10.SH NAME
11fmtmsg \- print formatted error messages
12.SH SYNOPSIS
13.nf
fea681da
MK
14.B #include <fmtmsg.h>
15.sp
16.BI "int fmtmsg(long " classification ", const char *" label ,
17.br
18.BI " int " severity ", const char *" text ,
19.br
20.BI " const char *" action ", const char *" tag );
fea681da
MK
21.fi
22.SH DESCRIPTION
23This function displays a message described by its parameters on the device(s)
24specified in the
25.I classification
c13182ef
MK
26parameter.
27For messages written to
fea681da
MK
28.IR stderr ,
29the format depends on the
30.B MSGVERB
31environment variable.
32.LP
33The
34.I label
c13182ef
MK
35parameter identifies the source of the message.
36The string must consist
fea681da 37of two colon separated parts where the first part has not more
c13182ef 38than 10 and the second part not more than 14 characters.
fea681da
MK
39.LP
40The
41.I text
42parameter describes the condition of the error.
43.LP
44The
45.I action
46parameter describes possible steps to recover from the error.
47If it is printed, it is prefixed by "TO FIX: ".
48.LP
49The
50.I tag
51parameter is a reference to the online documentation where more
c13182ef
MK
52information can be found.
53It should contain the
fea681da
MK
54.I label
55value and a unique identification number.
56.SS "Dummy parameters"
c13182ef
MK
57Each of the parameters can have a dummy value.
58The dummy classification value
fea681da
MK
59.B MM_NULLMC
60(0L) does not specify any output, so nothing is printed.
61The dummy severity value
62.B NO_SEV
63(0) says that no severity is supplied.
64The values
65.BR MM_NULLLBL ,
66.BR MM_NULLTXT ,
67.BR MM_NULLACT ,
0daa9e92 68.B MM_NULLTAG
cab87712
MK
69are synonyms for
70.IR "((char *) 0)" ,
71the empty string, and
fea681da
MK
72.B MM_NULLSEV
73is a synonym for
74.BR NO_SEV .
75.SS "The classification parameter"
c13182ef
MK
76The
77.I classification
fea681da 78parameter is the sum of values describing 4 types of information.
c13182ef 79.br
fea681da
MK
80.sp
81The first value defines the output channel.
82.TP 12n
83.B MM_PRINT
84Output to
85.IR stderr .
86.TP
87.B MM_CONSOLE
88Output to the system console.
89.TP
90.B "MM_PRINT | MM_CONSOLE"
91Output to both.
92.PP
93The second value is the source of the error:
94.TP 12n
95.B MM_HARD
96A hardware error occurred.
97.TP
98.B MM_FIRM
99A firmware error occurred.
100.TP
101.B MM_SOFT
102A software error occurred.
103.PP
104The third value encodes the detector of the problem:
105.TP 12n
106.B MM_APPL
107It is detected by an application.
108.TP
109.B MM_UTIL
110It is detected by a utility.
111.TP
112.B MM_OPSYS
113It is detected by the operating system.
114.PP
115The fourth value shows the severity of the incident:
116.TP 12n
117.B MM_RECOVER
118It is a recoverable error.
119.TP
120.B MM_NRECOV
121It is a non-recoverable error.
122.SS "The severity parameter"
c13182ef
MK
123The
124.I severity
fea681da
MK
125parameter can take one of the following values:
126.TP 12n
127.B MM_NOSEV
128No severity is printed.
129.TP
130.B MM_HALT
131This value is printed as HALT.
132.TP
133.B MM_ERROR
134This value is printed as ERROR.
135.TP
136.B MM_WARNING
137This value is printed as WARNING.
138.TP
139.B MM_INFO
140This value is printed as INFO.
141.PP
c13182ef
MK
142The numeric values are between 0 and 4.
143Using
fb186734 144.BR addseverity (3)
fea681da
MK
145or the environment variable
146.B SEV_LEVEL
147you can add more levels and strings to print.
2b2581ee
MK
148.SH "RETURN VALUE"
149The function can return 4 values:
150.TP 12n
151.B MM_OK
152Everything went smooth.
153.TP
154.B MM_NOTOK
155Complete failure.
156.TP
157.B MM_NOMSG
158Error writing to
159.IR stderr .
160.TP
161.B MM_NOCON
162Error writing to the console.
fea681da 163.SH ENVIRONMENT
c13182ef 164The environment variable
fea681da
MK
165.B MSGVERB
166("message verbosity") can be used to suppress parts of
167the output to
168.IR stderr .
169(It does not influence output to the console.)
170When this variable is defined, is non-NULL, and is a colon-separated
171list of valid keywords, then only the parts of the message corresponding
172to these keywords is printed.
173Valid keywords are "label", "severity", "text", "action" and "tag".
174.PP
175The environment variable
176.B SEV_LEVEL
177can be used to introduce new severity levels.
178By default, only the five severity levels described
c13182ef
MK
179above are available.
180Any other numeric value would make
181.BR fmtmsg ()
b5cc2ffb 182print nothing.
c13182ef 183If the user puts
fea681da
MK
184.B SEV_LEVEL
185with a format like
186.sp
187.RS
188SEV_LEVEL=[description[:description[:...]]]
189.RE
190.sp
c13182ef 191in the environment of the process before the first call to
b5cc2ffb 192.BR fmtmsg (),
fea681da
MK
193where each description is of the form
194.sp
195.RS
196severity-keyword,level,printstring
197.RE
198.sp
199then
31e9a9ec 200.BR fmtmsg ()
fea681da
MK
201will also accept the indicated values for the level (in addition to
202the standard levels 0-4), and use the indicated printstring when
203such a level occurs.
204.LP
205The severity-keyword part is not used by
31e9a9ec 206.BR fmtmsg ()
c13182ef
MK
207but it has to be present.
208The level part is a string representation of a number.
fea681da 209The numeric value must be a number greater than 4.
c13182ef 210This value must be used in the severity parameter of
31e9a9ec 211.BR fmtmsg ()
c13182ef
MK
212to select this class.
213It is not possible to overwrite
214any of the predefined classes.
215The printstring
fea681da 216is the string printed when a message of this class is processed by
31e9a9ec 217.BR fmtmsg ().
fea681da
MK
218.SH "CONFORMING TO"
219The functions
31e9a9ec 220.BR fmtmsg ()
fea681da 221and
fb186734 222.BR addseverity (3),
fea681da
MK
223and environment variables
224.B MSGVERB
225and
226.B SEV_LEVEL
68e1685c 227come from System V.
fea681da 228The function
31e9a9ec 229.BR fmtmsg ()
fea681da
MK
230and the environment variable
231.B MSGVERB
68e1685c 232are described in POSIX.1-2001.
fea681da
MK
233.SH NOTES
234System V and Unixware man pages tell us that these functions
235have been replaced by "pfmt() and addsev()" or by "pfmt(),
236vpfmt(), lfmt(), and vlfmt()", and will be removed later.
237.SH EXAMPLE
238.nf
239#include <stdio.h>
af9c7ff2 240#include <stdlib.h>
fea681da
MK
241#include <fmtmsg.h>
242
c13182ef
MK
243int
244main(void)
cf0a9ace
MK
245{
246 long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
247 int err;
29059a65 248 err = fmtmsg(class, "util\-linux:mount", MM_ERROR,
c13182ef 249 "unknown mount option", "See mount(8).",
29059a65 250 "util\-linux:mount:017");
d4949190 251 switch (err) {
fea681da 252 case MM_OK:
cf0a9ace 253 break;
fea681da 254 case MM_NOTOK:
cf0a9ace
MK
255 printf("Nothing printed\en");
256 break;
fea681da 257 case MM_NOMSG:
cf0a9ace
MK
258 printf("Nothing printed to stderr\en");
259 break;
fea681da 260 case MM_NOCON:
cf0a9ace
MK
261 printf("No console output\en");
262 break;
fea681da 263 default:
cf0a9ace
MK
264 printf("Unknown error from fmtmsg()\en");
265 }
5bc8c34c 266 exit(EXIT_SUCCESS);
fea681da
MK
267}
268.fi
269.PP
270The output should be:
271.nf
cab87712
MK
272
273 util\-linux:mount: ERROR: unknown mount option
274 TO FIX: See mount(8). util\-linux:mount:017
275
fea681da
MK
276.fi
277and after
278.nf
cab87712
MK
279
280 MSGVERB=text:action; export MSGVERB
281
fea681da
MK
282.fi
283the output becomes:
284.nf
cab87712
MK
285
286 unknown mount option
287 TO FIX: See mount(8).
fea681da
MK
288.fi
289.SH "SEE ALSO"
290.BR addseverity (3),
291.BR perror (3)