fmtmsgのヘルプ・マニュアル
日本語 英語
fmtmsg --help
man fmtmsg
FMTMSG(3) Linux Programmer’s Manual FMTMSG(3)
名前
fmtmsg - 整形されたエラーメッセージを表示する
書式
#include
int fmtmsg(long classification, const char *label,
int severity, const char *text,
const char *action, const char *tag);
説明
こ の関数は、引き数で記述されたメッセージを、 classification 引き数で指
定されたデバイス上に表示する。 stderr に書き出されるメッセージのフォ ー
マットは、 MSGVERB 環境変数に依存する。
label 引き数はメッセージの発生源を識別する。この文字列はコロンで区切ら
れた 2 つの部分から構成されていなければならない。 1 つ目の部分は 10 文
字以内でなければならず、 2 つ目の部分は 14 文字以内でなければならない。
text 引き数にはエラー条件を記述する。
action 引き数にはエラーから回復するために利用可能なステップを記述する。
これが表示される場合、"TO FIX: " が前に付く。
tag 引き数はより多くの情報を見つけるためのオンラインドキュメントへの参
照である。これは label 値とユニークな識別番号を含んでいるべきである。
ダミー引き数
各引き数にはダミーの値を入れることができる。ダミーの classification 値
MM_NULLMC (0L) は出力を何も指定しない。そのため何も表示されない。ダミー
の severity 値 NO_SEV (0) は重大度 (severity) が与えられていないこと を
表す。値 MM_NULLLBL, MM_NULLTXT, MM_NULLACT, MM_NULLTAG は ((char *) 0)
と空文字列の別名であり、 MM_NULLSEV は NO_SEV の別名である。
classification 引き数
classification 引き数は 4 種類の情報を記述する値の和である。
最初の値は出力チャンネルを定義する。
MM_PRINT stderr に出力する。
MM_CONSOLE システムコンソールに出力する。
MM_PRINT | MM_CONSOLE
両方に出力する。
2 番目の値はエラーの発生源である:
MM_HARD ハードウェアエラーが起こった。
MM_FIRM ファームウェアエラーが起こった。
MM_SOFT ソフトウェアエラーが起こった。
3 番目の値は問題の検知を行ったものをエンコードする:
MM_APPL アプリケーションによって検知された。
MM_UTIL ユーティリティによって検知された。
MM_OPSYS オペレーティングシステムによって検知された。
4 番目の値は問題の重大度を表す:
MM_RECOVER 回復可能なエラーである。
MM_NRECOV 回復不可能なエラーである。
severity 引き数
severity 引き数は以下の 1 つの値をとることができる。
MM_NOSEV 重大度は表示されない。
MM_HALT この値は HALT として表示される。
MM_ERROR この値は ERROR として表示される。
MM_WARNING この値は WARNING として表示される。
MM_INFO この値は INFO として表示される。
数値の場合は 0 から 4 である。 addseverity(3) または環境変数 SEV_LEVEL
を使うことにより、表示するレベルと文字列を更に追加できる。
返り値
関数は 4 つの値を返す:
MM_OK 全てがうまくいった。
MM_NOTOK 完全に失敗した。
MM_NOMSG stderr に書き込むときにエラーが起こった。
MM_NOCON コンソールに書き込むときにエラーが起こった。
環境変数
環境変数 MSGVERB ("message verbosity") は stderr への出力の一部を抑制す
るのに使うことができる。 (コンソールへの出力には影響しない。) この変 数
が定義されて、NULL でなく、コロンで区切られた有効なキーワードのリストで
ある場合、キーワードに対応するメッセージの一部のみが表示される。有効 な
キーワードは "label", "severity", "text", "action", "tag" である。
環境変数 SEV_LEVEL は新しい重大度レベルを導入するのに使用できる。デフォ
ルトでは、上記の 5 つの重大度レベルのみが利用可能である。他の数値の場合
、 fmtmsg() は何も表示しない。 fmtmsg() を初めて呼び出す前に、ユーザが
SEV_LEVEL を
SEV_LEVEL=[description[:description[:...]]]
のような形式でプロセスの環境に設定すると、 fmtmsg() は (標準の レ ベ ル
0-4 に加えて) level に指定された値も受け付け、そのようなレベルの問題が
発生すると指定された printstring を表示する。各 description は
severity-keyword,level,printstring
という形式である。
severity-keyword 部は fmtmsg() に使用されないが、存在しなければならない
。 level 部は数値を文字列で表したものである。数値は 4 より大きい値でな
ければならない。この値は fmtmsg() の severity 引き数で使用されなけれ ば
な らず、この重大度を選択する。前もって宣言された重大度を上書きすること
はできない。 printstring は、この重大度のメッセージが fmtmsg() によって
生成された場合に表示される文字列である。
バージョン
fmtmsg() は、バージョン 2.1 以降の glibc で提供されている。
準拠
関数 fmtmsg() と addseverity(3) と環境変数 MSGVERB と SEV_LEVEL は Sys-
tem V に由来している。関数 fmtmsg() と環境変数 MSGVERB は POSIX.1-2001
に記述されている。
注意
System V と Unixware の man ページには、「これらの関数は "pfmt() と
addsev()" または "pfmt(), vpfmt(), lfmt(), vlfmt()" で置き換えられて お
り、将来は削除される予定である」と書かれている。
例
#include
#include
#include
int
main(void)
{
long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
int err;
err = fmtmsg(class, "util-linux:mount", MM_ERROR,
"unknown mount option", "See mount(8).",
"util-linux:mount:017");
switch (err) {
case MM_OK:
break;
case MM_NOTOK:
printf("Nothing printed\n");
break;
case MM_NOMSG:
printf("Nothing printed to stderr\n");
break;
case MM_NOCON:
printf("No console output\n");
break;
default:
printf("Unknown error from fmtmsg()\n");
}
exit(EXIT_SUCCESS);
}
出力は
util-linux:mount: ERROR: unknown mount option
TO FIX: See mount(8). util-linux:mount:017
のようになり、
MSGVERB=text:action; export MSGVERB
を実行した後では
unknown mount option
TO FIX: See mount(8).
となる。
関連項目
addseverity(3), perror(3)
2008-06-14 FMTMSG(3)
FMTMSG(3) Linux Programmer’s Manual FMTMSG(3)
NAME
fmtmsg - print formatted error messages
SYNOPSIS
#include
int fmtmsg(long classification, const char *label,
int severity, const char *text,
const char *action, const char *tag);
DESCRIPTION
This function displays a message described by its arguments on the
device(s) specified in the classification argument. For messages writ-
ten to stderr, the format depends on the MSGVERB environment variable.
The label 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.
The text argument describes the condition of the error.
The action argument describes possible steps to recover from the error.
If it is printed, it is prefixed by "TO FIX: ".
The tag argument is a reference to the online documentation where more
information can be found. It should contain the label value and a
unique identification number.
Dummy arguments
Each of the arguments can have a dummy value. The dummy classification
value MM_NULLMC (0L) does not specify any output, so nothing is
printed. The dummy severity value NO_SEV (0) says that no severity is
supplied. The values MM_NULLLBL, MM_NULLTXT, MM_NULLACT, MM_NULLTAG
are synonyms for ((char *) 0), the empty string, and MM_NULLSEV is a
synonym for NO_SEV.
The classification argument
The classification argument is the sum of values describing 4 types of
information.
The first value defines the output channel.
MM_PRINT Output to stderr.
MM_CONSOLE Output to the system console.
MM_PRINT | MM_CONSOLE
Output to both.
The second value is the source of the error:
MM_HARD A hardware error occurred.
MM_FIRM A firmware error occurred.
MM_SOFT A software error occurred.
The third value encodes the detector of the problem:
MM_APPL It is detected by an application.
MM_UTIL It is detected by a utility.
MM_OPSYS It is detected by the operating system.
The fourth value shows the severity of the incident:
MM_RECOVER It is a recoverable error.
MM_NRECOV It is a non-recoverable error.
The severity argument
The severity argument can take one of the following values:
MM_NOSEV No severity is printed.
MM_HALT This value is printed as HALT.
MM_ERROR This value is printed as ERROR.
MM_WARNING This value is printed as WARNING.
MM_INFO This value is printed as INFO.
The numeric values are between 0 and 4. Using addseverity(3) or the
environment variable SEV_LEVEL you can add more levels and strings to
print.
RETURN VALUE
The function can return 4 values:
MM_OK Everything went smooth.
MM_NOTOK Complete failure.
MM_NOMSG Error writing to stderr.
MM_NOCON Error writing to the console.
ENVIRONMENT
The environment variable MSGVERB ("message verbosity") can be used to
suppress parts of the output to stderr. (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 mes-
sage corresponding to these keywords is printed. Valid keywords are
"label", "severity", "text", "action" and "tag".
The environment variable SEV_LEVEL can be used to introduce new sever-
ity levels. By default, only the five severity levels described above
are available. Any other numeric value would make fmtmsg() print noth-
ing. If the user puts SEV_LEVEL with a format like
SEV_LEVEL=[description[:description[:...]]]
in the environment of the process before the first call to fmtmsg(),
where each description is of the form
severity-keyword,level,printstring
then fmtmsg() 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.
The severity-keyword part is not used by fmtmsg() 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 fmtmsg() 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
fmtmsg().
VERSIONS
fmtmsg() is provided in glibc since version 2.1.
CONFORMING TO
The functions fmtmsg() and addseverity(3), and environment variables
MSGVERB and SEV_LEVEL come from System V. The function fmtmsg() and
the environment variable MSGVERB are described in POSIX.1-2001.
NOTES
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.
EXAMPLE
#include
#include
#include
int
main(void)
{
long class = MM_PRINT | MM_SOFT | MM_OPSYS | MM_RECOVER;
int err;
err = fmtmsg(class, "util-linux:mount", MM_ERROR,
"unknown mount option", "See mount(8).",
"util-linux:mount:017");
switch (err) {
case MM_OK:
break;
case MM_NOTOK:
printf("Nothing printed\n");
break;
case MM_NOMSG:
printf("Nothing printed to stderr\n");
break;
case MM_NOCON:
printf("No console output\n");
break;
default:
printf("Unknown error from fmtmsg()\n");
}
exit(EXIT_SUCCESS);
}
The output should be:
util-linux:mount: ERROR: unknown mount option
TO FIX: See mount(8). util-linux:mount:017
and after
MSGVERB=text:action; export MSGVERB
the output becomes:
unknown mount option
TO FIX: See mount(8).
SEE ALSO
addseverity(3), perror(3)
COLOPHON
This page is part of release 3.22 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
be found at http://www.kernel.org/doc/man-pages/.
2008-06-14 FMTMSG(3)