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