502 lines
11 KiB
HTML
502 lines
11 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of FMTMSG</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>FMTMSG</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
fmtmsg - print formatted error messages
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/fmtmsg.h">fmtmsg.h</A>></B>
|
|
|
|
<B>int fmtmsg(long </B><I>classification</I><B>, const char *</B><I>label</I><B>,</B>
|
|
<B> int </B><I>severity</I><B>, const char *</B><I>text</I><B>,</B>
|
|
<B> const char *</B><I>action</I><B>, const char *</B><I>tag</I><B>);</B>
|
|
</PRE>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
This function displays a message described by its arguments on the device(s)
|
|
specified in the
|
|
<I>classification</I>
|
|
|
|
argument.
|
|
For messages written to
|
|
<I>stderr</I>,
|
|
|
|
the format depends on the
|
|
<B>MSGVERB</B>
|
|
|
|
environment variable.
|
|
<P>
|
|
|
|
The
|
|
<I>label</I>
|
|
|
|
argument identifies the source of the message.
|
|
The string must consist
|
|
of two colon separated parts where the first part has not more
|
|
than 10 and the second part not more than 14 characters.
|
|
<P>
|
|
|
|
The
|
|
<I>text</I>
|
|
|
|
argument describes the condition of the error.
|
|
<P>
|
|
|
|
The
|
|
<I>action</I>
|
|
|
|
argument describes possible steps to recover from the error.
|
|
If it is printed, it is prefixed by "TO FIX: ".
|
|
<P>
|
|
|
|
The
|
|
<I>tag</I>
|
|
|
|
argument is a reference to the online documentation where more
|
|
information can be found.
|
|
It should contain the
|
|
<I>label</I>
|
|
|
|
value and a unique identification number.
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Dummy arguments</H3>
|
|
|
|
Each of the arguments can have a dummy value.
|
|
The dummy classification value
|
|
<B>MM_NULLMC</B>
|
|
|
|
(0L) does not specify any output, so nothing is printed.
|
|
The dummy severity value
|
|
<B>NO_SEV</B>
|
|
|
|
(0) says that no severity is supplied.
|
|
The values
|
|
<B>MM_NULLLBL</B>,
|
|
|
|
<B>MM_NULLTXT</B>,
|
|
|
|
<B>MM_NULLACT</B>,
|
|
|
|
<B>MM_NULLTAG</B>
|
|
|
|
are synonyms for
|
|
<I>((char *) 0)</I>,
|
|
|
|
the empty string, and
|
|
<B>MM_NULLSEV</B>
|
|
|
|
is a synonym for
|
|
<B>NO_SEV</B>.
|
|
|
|
<A NAME="lbAF"> </A>
|
|
<H3>The classification argument</H3>
|
|
|
|
The
|
|
<I>classification</I>
|
|
|
|
argument is the sum of values describing 4 types of information.
|
|
<P>
|
|
|
|
The first value defines the output channel.
|
|
<DL COMPACT>
|
|
<DT id="1"><B>MM_PRINT</B>
|
|
|
|
<DD>
|
|
Output to
|
|
<I>stderr</I>.
|
|
|
|
<DT id="2"><B>MM_CONSOLE</B>
|
|
|
|
<DD>
|
|
Output to the system console.
|
|
<DT id="3"><B>MM_PRINT | MM_CONSOLE</B>
|
|
|
|
<DD>
|
|
Output to both.
|
|
</DL>
|
|
<P>
|
|
|
|
The second value is the source of the error:
|
|
<DL COMPACT>
|
|
<DT id="4"><B>MM_HARD</B>
|
|
|
|
<DD>
|
|
A hardware error occurred.
|
|
<DT id="5"><B>MM_FIRM</B>
|
|
|
|
<DD>
|
|
A firmware error occurred.
|
|
<DT id="6"><B>MM_SOFT</B>
|
|
|
|
<DD>
|
|
A software error occurred.
|
|
</DL>
|
|
<P>
|
|
|
|
The third value encodes the detector of the problem:
|
|
<DL COMPACT>
|
|
<DT id="7"><B>MM_APPL</B>
|
|
|
|
<DD>
|
|
It is detected by an application.
|
|
<DT id="8"><B>MM_UTIL</B>
|
|
|
|
<DD>
|
|
It is detected by a utility.
|
|
<DT id="9"><B>MM_OPSYS</B>
|
|
|
|
<DD>
|
|
It is detected by the operating system.
|
|
</DL>
|
|
<P>
|
|
|
|
The fourth value shows the severity of the incident:
|
|
<DL COMPACT>
|
|
<DT id="10"><B>MM_RECOVER</B>
|
|
|
|
<DD>
|
|
It is a recoverable error.
|
|
<DT id="11"><B>MM_NRECOV</B>
|
|
|
|
<DD>
|
|
It is a nonrecoverable error.
|
|
</DL>
|
|
<A NAME="lbAG"> </A>
|
|
<H3>The severity argument</H3>
|
|
|
|
The
|
|
<I>severity</I>
|
|
|
|
argument can take one of the following values:
|
|
<DL COMPACT>
|
|
<DT id="12"><B>MM_NOSEV</B>
|
|
|
|
<DD>
|
|
No severity is printed.
|
|
<DT id="13"><B>MM_HALT</B>
|
|
|
|
<DD>
|
|
This value is printed as HALT.
|
|
<DT id="14"><B>MM_ERROR</B>
|
|
|
|
<DD>
|
|
This value is printed as ERROR.
|
|
<DT id="15"><B>MM_WARNING</B>
|
|
|
|
<DD>
|
|
This value is printed as WARNING.
|
|
<DT id="16"><B>MM_INFO</B>
|
|
|
|
<DD>
|
|
This value is printed as INFO.
|
|
</DL>
|
|
<P>
|
|
|
|
The numeric values are between 0 and 4.
|
|
Using
|
|
<B><A HREF="/cgi-bin/man/man2html?3+addseverity">addseverity</A></B>(3)
|
|
|
|
or the environment variable
|
|
<B>SEV_LEVEL</B>
|
|
|
|
you can add more levels and strings to print.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
The function can return 4 values:
|
|
<DL COMPACT>
|
|
<DT id="17"><B>MM_OK</B>
|
|
|
|
<DD>
|
|
Everything went smooth.
|
|
<DT id="18"><B>MM_NOTOK</B>
|
|
|
|
<DD>
|
|
Complete failure.
|
|
<DT id="19"><B>MM_NOMSG</B>
|
|
|
|
<DD>
|
|
Error writing to
|
|
<I>stderr</I>.
|
|
|
|
<DT id="20"><B>MM_NOCON</B>
|
|
|
|
<DD>
|
|
Error writing to the console.
|
|
</DL>
|
|
<A NAME="lbAI"> </A>
|
|
<H2>ENVIRONMENT</H2>
|
|
|
|
The environment variable
|
|
<B>MSGVERB</B>
|
|
|
|
("message verbosity") can be used to suppress parts of
|
|
the output to
|
|
<I>stderr</I>.
|
|
|
|
(It does not influence output to the console.)
|
|
When this variable is defined, is non-NULL, and is a colon-separated
|
|
list of valid keywords, then only the parts of the message corresponding
|
|
to these keywords is printed.
|
|
Valid keywords are "label", "severity", "text", "action" and "tag".
|
|
<P>
|
|
|
|
The environment variable
|
|
<B>SEV_LEVEL</B>
|
|
|
|
can be used to introduce new severity levels.
|
|
By default, only the five severity levels described
|
|
above are available.
|
|
Any other numeric value would make
|
|
<B>fmtmsg</B>()
|
|
|
|
print nothing.
|
|
If the user puts
|
|
<B>SEV_LEVEL</B>
|
|
|
|
with a format like
|
|
<P>
|
|
|
|
<DL COMPACT><DT id="21"><DD>
|
|
SEV_LEVEL=[description[:description[:...]]]
|
|
</DL>
|
|
|
|
<P>
|
|
|
|
in the environment of the process before the first call to
|
|
<B>fmtmsg</B>(),
|
|
|
|
where each description is of the form
|
|
<P>
|
|
|
|
<DL COMPACT><DT id="22"><DD>
|
|
severity-keyword,level,printstring
|
|
</DL>
|
|
|
|
<P>
|
|
|
|
then
|
|
<B>fmtmsg</B>()
|
|
|
|
will also accept the indicated values for the level (in addition to
|
|
the standard levels 0-4), and use the indicated printstring when
|
|
such a level occurs.
|
|
<P>
|
|
|
|
The severity-keyword part is not used by
|
|
<B>fmtmsg</B>()
|
|
|
|
but it has to be present.
|
|
The level part is a string representation of a number.
|
|
The numeric value must be a number greater than 4.
|
|
This value must be used in the severity argument of
|
|
<B>fmtmsg</B>()
|
|
|
|
to select this class.
|
|
It is not possible to overwrite
|
|
any of the predefined classes.
|
|
The printstring
|
|
is the string printed when a message of this class is processed by
|
|
<B>fmtmsg</B>().
|
|
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>fmtmsg</B>()
|
|
|
|
is provided in glibc since version 2.1.
|
|
<A NAME="lbAK"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>fmtmsg</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>
|
|
glibc >= 2.16: MT-Safe
|
|
<BR>
|
|
|
|
glibc < 2.16: MT-Unsafe
|
|
<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
|
|
Before glibc 2.16, the
|
|
<B>fmtmsg</B>()
|
|
|
|
function uses a static variable that is not protected,
|
|
so it is not thread-safe.
|
|
<P>
|
|
|
|
Since glibc 2.16,
|
|
|
|
the
|
|
<B>fmtmsg</B>()
|
|
|
|
function uses a lock to protect the static variable, so it is thread-safe.
|
|
<A NAME="lbAL"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
The functions
|
|
<B>fmtmsg</B>()
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+addseverity">addseverity</A></B>(3),
|
|
|
|
and environment variables
|
|
<B>MSGVERB</B>
|
|
|
|
and
|
|
<B>SEV_LEVEL</B>
|
|
|
|
come from System V.
|
|
<P>
|
|
|
|
The function
|
|
<B>fmtmsg</B>()
|
|
|
|
and the environment variable
|
|
<B>MSGVERB</B>
|
|
|
|
are described in POSIX.1-2001 and POSIX.1-2008.
|
|
<A NAME="lbAM"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
System V and UnixWare man pages tell us that these functions
|
|
have been replaced by "pfmt() and addsev()" or by "pfmt(),
|
|
vpfmt(), lfmt(), and vlfmt()", and will be removed later.
|
|
<A NAME="lbAN"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/fmtmsg.h">fmtmsg.h</A>>
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
|
|
<BR> int err;
|
|
<P>
|
|
<BR> err = fmtmsg(class, "util-linux:mount", MM_ERROR,
|
|
<BR> "unknown mount option", "See <A HREF="/cgi-bin/man/man2html?8+mount">mount</A>(8).",
|
|
<BR> "util-linux:mount:017");
|
|
<BR> switch (err) {
|
|
<BR> case MM_OK:
|
|
<BR> break;
|
|
<BR> case MM_NOTOK:
|
|
<BR> printf("Nothing printed\n");
|
|
<BR> break;
|
|
<BR> case MM_NOMSG:
|
|
<BR> printf("Nothing printed to stderr\n");
|
|
<BR> break;
|
|
<BR> case MM_NOCON:
|
|
<BR> printf("No console output\n");
|
|
<BR> break;
|
|
<BR> default:
|
|
<BR> printf("Unknown error from fmtmsg()\n");
|
|
<BR> }
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<P>
|
|
|
|
The output should be:
|
|
<P>
|
|
|
|
|
|
|
|
util-linux:mount: ERROR: unknown mount option
|
|
TO FIX: See <A HREF="/cgi-bin/man/man2html?8+mount">mount</A>(8). util-linux:mount:017
|
|
|
|
|
|
<P>
|
|
|
|
and after
|
|
<P>
|
|
|
|
|
|
|
|
MSGVERB=text:action; export MSGVERB
|
|
|
|
|
|
<P>
|
|
|
|
the output becomes:
|
|
<P>
|
|
|
|
|
|
|
|
unknown mount option
|
|
TO FIX: See <A HREF="/cgi-bin/man/man2html?8+mount">mount</A>(8).
|
|
|
|
|
|
<P>
|
|
|
|
<A NAME="lbAO"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+addseverity">addseverity</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+perror">perror</A></B>(3)
|
|
|
|
<A NAME="lbAP"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="23"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="24"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="25"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="26"><A HREF="#lbAE">Dummy arguments</A><DD>
|
|
<DT id="27"><A HREF="#lbAF">The classification argument</A><DD>
|
|
<DT id="28"><A HREF="#lbAG">The severity argument</A><DD>
|
|
</DL>
|
|
<DT id="29"><A HREF="#lbAH">RETURN VALUE</A><DD>
|
|
<DT id="30"><A HREF="#lbAI">ENVIRONMENT</A><DD>
|
|
<DT id="31"><A HREF="#lbAJ">VERSIONS</A><DD>
|
|
<DT id="32"><A HREF="#lbAK">ATTRIBUTES</A><DD>
|
|
<DT id="33"><A HREF="#lbAL">CONFORMING TO</A><DD>
|
|
<DT id="34"><A HREF="#lbAM">NOTES</A><DD>
|
|
<DT id="35"><A HREF="#lbAN">EXAMPLE</A><DD>
|
|
<DT id="36"><A HREF="#lbAO">SEE ALSO</A><DD>
|
|
<DT id="37"><A HREF="#lbAP">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:43 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|