1fmtmsg(3)                  Linux Programmer's Manual                 fmtmsg(3)
2
3
4

NAME

6       fmtmsg - print formatted error messages
7

SYNOPSIS

9       #include <fmtmsg.h>
10
11       int fmtmsg(long classification, const char *label,
12                  int severity, const char *text,
13                  const char *action, const char *tag);
14
15

DESCRIPTION

17       This  function  displays  a  message described by its parameters on the
18       device(s) specified in the classification parameter. For messages writ‐
19       ten to stderr, the format depends on the MSGVERB environment variable.
20
21       The  label  parameter identifies the source of the message.  The string
22       must consist of two colon separated parts where the first part has  not
23       more than 10 and the second part not more than 14 characters.
24
25       The text parameter describes the condition of the error.
26
27       The  action  parameter  describes  possible  steps  to recover from the
28       error.  If it is printed, it is prefixed by "TO FIX: ".
29
30       The tag parameter is a reference to the online documentation where more
31       information  can  be  found.   It  should contain the label value and a
32       unique identification number.
33
34   Dummy parameters
35       Each of the parameters can have a dummy value. The dummy classification
36       value  MM_NULLMC  (0L)  does  not  specify  any  output,  so nothing is
37       printed.  The dummy severity value NO_SEV (0) says that no severity  is
38       supplied.   The  values  MM_NULLLBL, MM_NULLTXT, MM_NULLACT, MM_NULLTAG
39       are synonyms for ((char *) 0), the empty string, and  MM_NULLSEV  is  a
40       synonym for NO_SEV.
41
42   The classification parameter
43       The classification parameter is the sum of values describing 4 types of
44       information.
45
46       The first value defines the output channel.
47
48       MM_PRINT    Output to stderr.
49
50       MM_CONSOLE  Output to the system console.
51
52       MM_PRINT | MM_CONSOLE
53                   Output to both.
54
55       The second value is the source of the error:
56
57       MM_HARD     A hardware error occurred.
58
59       MM_FIRM     A firmware error occurred.
60
61       MM_SOFT     A software error occurred.
62
63       The third value encodes the detector of the problem:
64
65       MM_APPL     It is detected by an application.
66
67       MM_UTIL     It is detected by a utility.
68
69       MM_OPSYS    It is detected by the operating system.
70
71       The fourth value shows the severity of the incident:
72
73       MM_RECOVER  It is a recoverable error.
74
75       MM_NRECOV   It is a non-recoverable error.
76
77   The severity parameter
78       The severity parameter can take one of the following values:
79
80       MM_NOSEV    No severity is printed.
81
82       MM_HALT     This value is printed as HALT.
83
84       MM_ERROR    This value is printed as ERROR.
85
86       MM_WARNING  This value is printed as WARNING.
87
88       MM_INFO     This value is printed as INFO.
89
90       The numeric values are between 0 and  4.  Using  addseverity()  or  the
91       environment  variable  SEV_LEVEL you can add more levels and strings to
92       print.
93

ENVIRONMENT

95       The environment variable MSGVERB ("message verbosity") can be  used  to
96       suppress  parts of the output to stderr.  (It does not influence output
97       to the console.)  When this variable is defined, is non-NULL, and is  a
98       colon-separated list of valid keywords, then only the parts of the mes‐
99       sage corresponding to these keywords is printed.   Valid  keywords  are
100       "label", "severity", "text", "action" and "tag".
101
102       The  environment variable SEV_LEVEL can be used to introduce new sever‐
103       ity levels.  By default, only the five severity levels described  above
104       are available.  Any other numeric value would make fmtmsg() print noth‐
105       ing.  If the user puts SEV_LEVEL with a format like
106
107              SEV_LEVEL=[description[:description[:...]]]
108
109       in the environment of the process before the first  call  to  fmtmsg(),
110       where each description is of the form
111
112              severity-keyword,level,printstring
113
114       then  fmtmsg()  will also accept the indicated values for the level (in
115       addition to the standard levels 0-4), and use the indicated printstring
116       when such a level occurs.
117
118       The  severity-keyword  part  is  not  used by fmtmsg() but it has to be
119       present.  The level part is a string representation of a  number.   The
120       numeric value must be a number greater than 4.  This value must be used
121       in the severity parameter of fmtmsg() to select this class.  It is  not
122       possible  to  overwrite any of the predefined classes.  The printstring
123       is the string printed when a message of  this  class  is  processed  by
124       fmtmsg().
125

RETURN VALUES

127       The function can return 4 values:
128
129       MM_OK       Everything went smooth.
130
131       MM_NOTOK    Complete failure.
132
133       MM_NOMSG    Error writing to stderr.
134
135       MM_NOCON    Error writing to the console.
136

CONFORMING TO

138       The  functions  fmtmsg()  and  addseverity(), and environment variables
139       MSGVERB and SEV_LEVEL come from System V.  The  function  fmtmsg()  and
140       the environment variable MSGVERB are described in POSIX.1-2001.
141

NOTES

143       System  V and Unixware man pages tell us that these functions have been
144       replaced by "pfmt() and addsev()" or by "pfmt(), vpfmt(),  lfmt(),  and
145       vlfmt()", and will be removed later.
146

EXAMPLE

148       #include <stdio.h>
149       #include <fmtmsg.h>
150
151       int main() {
152         long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
153         int err;
154         err = fmtmsg(class, "util-linux:mount", MM_ERROR,
155               "unknown mount option", "See mount(8).", "util-linux:mount:017");
156         switch(err) {
157           case MM_OK:
158             break;
159           case MM_NOTOK:
160             printf("Nothing printed\n");
161             break;
162           case MM_NOMSG:
163             printf("Nothing printed to stderr\n");
164             break;
165           case MM_NOCON:
166             printf("No console output\n");
167             break;
168           default:
169             printf("Unknown error from fmtmsg()\n");
170         }
171         return 0;
172       }
173
174       The output should be:
175         util-linux:mount: ERROR: unknown mount option
176         TO FIX: See mount(8).  util-linux:mount:017
177       and after
178         MSGVERB=text:action; export MSGVERB
179       the output becomes:
180         unknown mount option
181         TO FIX: See mount(8).
182

SEE ALSO

184       addseverity(3), perror(3)
185
186
187
188                                  2003-11-01                         fmtmsg(3)
Impressum