1 .\" Copyright 2002 walter harms (walter.harms@informatik.uni-oldenburg.de)
3 .\" SPDX-License-Identifier: GPL-1.0-or-later
5 .\" adapted glibc info page
7 .\" This should run as 'Guru Meditation' (amiga joke :)
8 .\" The function is quite complex and deserves an example
10 .\" Polished, aeb, 2003-11-01
11 .TH FMTMSG 3 2021-03-22 "Linux man-pages (unreleased)" "Linux Programmer's Manual"
13 fmtmsg \- print formatted error messages
16 .RI ( libc ", " \-lc )
19 .B #include <fmtmsg.h>
21 .BI "int fmtmsg(long " classification ", const char *" label ,
22 .BI " int " severity ", const char *" text ,
23 .BI " const char *" action ", const char *" tag );
26 This function displays a message described by its arguments on the device(s)
30 For messages written to
32 the format depends on the
38 argument identifies the source of the message.
39 The string must consist
40 of two colon separated parts where the first part has not more
41 than 10 and the second part not more than 14 characters.
45 argument describes the condition of the error.
49 argument describes possible steps to recover from the error.
50 If it is printed, it is prefixed by "TO FIX: ".
54 argument is a reference to the online documentation where more
55 information can be found.
58 value and a unique identification number.
60 Each of the arguments can have a dummy value.
61 The dummy classification value
63 (0L) does not specify any output, so nothing is printed.
64 The dummy severity value
66 (0) says that no severity is supplied.
73 .IR "((char\ *)\ 0)" ,
78 .SS The classification argument
81 argument is the sum of values describing 4 types of information.
83 The first value defines the output channel.
90 Output to the system console.
92 .B "MM_PRINT | MM_CONSOLE"
95 The second value is the source of the error:
98 A hardware error occurred.
101 A firmware error occurred.
104 A software error occurred.
106 The third value encodes the detector of the problem:
109 It is detected by an application.
112 It is detected by a utility.
115 It is detected by the operating system.
117 The fourth value shows the severity of the incident:
120 It is a recoverable error.
123 It is a nonrecoverable error.
124 .SS The severity argument
127 argument can take one of the following values:
130 No severity is printed.
133 This value is printed as HALT.
136 This value is printed as ERROR.
139 This value is printed as WARNING.
142 This value is printed as INFO.
144 The numeric values are between 0 and 4.
147 or the environment variable
149 you can add more levels and strings to print.
151 The function can return 4 values:
154 Everything went smooth.
164 Error writing to the console.
166 The environment variable
168 ("message verbosity") can be used to suppress parts of
171 (It does not influence output to the console.)
172 When this variable is defined, is non-NULL, and is a colon-separated
173 list of valid keywords, then only the parts of the message corresponding
174 to these keywords is printed.
175 Valid keywords are "label", "severity", "text", "action", and "tag".
177 The environment variable
179 can be used to introduce new severity levels.
180 By default, only the five severity levels described
182 Any other numeric value would make
190 SEV_LEVEL=[description[:description[:...]]]
193 in the environment of the process before the first call to
195 where each description is of the form
198 severity-keyword,level,printstring
203 will also accept the indicated values for the level (in addition to
204 the standard levels 0\(en4), and use the indicated printstring when
207 The severity-keyword part is not used by
209 but it has to be present.
210 The level part is a string representation of a number.
211 The numeric value must be a number greater than 4.
212 This value must be used in the severity argument of
214 to select this class.
215 It is not possible to overwrite
216 any of the predefined classes.
218 is the string printed when a message of this class is processed by
222 is provided in glibc since version 2.1.
224 For an explanation of the terms used in this section, see
232 Interface Attribute Value
236 glibc\ >=\ 2.16: MT-Safe;
237 glibc\ <\ 2.16: MT-Unsafe
244 Before glibc 2.16, the
246 function uses a static variable that is not protected,
247 so it is not thread-safe.
250 .\" Modified in commit 7724defcf8873116fe4efab256596861eef21a94
253 function uses a lock to protect the static variable, so it is thread-safe.
259 and environment variables
267 and the environment variable
269 are described in POSIX.1-2001 and POSIX.1-2008.
271 System V and UnixWare man pages tell us that these functions
272 have been replaced by "pfmt() and addsev()" or by "pfmt(),
273 vpfmt(), lfmt(), and vlfmt()", and will be removed later.
283 long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
286 err = fmtmsg(class, "util\-linux:mount", MM_ERROR,
287 "unknown mount option", "See mount(8).",
288 "util\-linux:mount:017");
293 printf("Nothing printed\en");
296 printf("Nothing printed to stderr\en");
299 printf("No console output\en");
302 printf("Unknown error from fmtmsg()\en");
308 The output should be:
312 util\-linux:mount: ERROR: unknown mount option
313 TO FIX: See mount(8). util\-linux:mount:017
321 MSGVERB=text:action; export MSGVERB
330 TO FIX: See mount(8).