syslogシステムコール(コンソールログレベル)
console_loglevel以下のログレベルのシステムログがコンソール画面へ出力されます。/proc/sys/kernel/printkと異なりsyslogシステムコールで更新できるのは、SYSLOG_ACTION_CONSOLE_LEVELのminimum_console_loglevelを最小値とするconsole_loglevelだけです。
SYSLOG_ACTION_CONSOLE_OFFはコンソール画面の出力を停止する物ですが、console_loglevel = minimum_console_loglevelでの実装であり、minimum_console_loglevel以下のシステムログは停止されません。デフォルトではminimum_console_loglevel=1で、KERN_EMERGは表示されます。
SYSLOG_ACTION_CONSOLE_ONは、SYSLOG_ACTION_CONSOLE_OFF更新時のconsole_loglevelに復元する事で、コンソール画面の出力開始とします。なおSYSLOG_ACTION_CONSOLE_LEVELで改めてconsole_loglevelを設定する事でもコンソール画面の出力開始の実現が可能となりなります。
SYSLOG_ACTION_CONSOLE_OFFはコンソール画面の出力を停止する物ですが、console_loglevel = minimum_console_loglevelでの実装であり、minimum_console_loglevel以下のシステムログは停止されません。デフォルトではminimum_console_loglevel=1で、KERN_EMERGは表示されます。
SYSLOG_ACTION_CONSOLE_ONは、SYSLOG_ACTION_CONSOLE_OFF更新時のconsole_loglevelに復元する事で、コンソール画面の出力開始とします。なおSYSLOG_ACTION_CONSOLE_LEVELで改めてconsole_loglevelを設定する事でもコンソール画面の出力開始の実現が可能となりなります。
#define KERN_EMERG "<0>" /* system is unusable */
#define KERN_ALERT "<1>" /* action must be taken immediately */
#define KERN_CRIT "<2>" /* critical conditions */
#define KERN_ERR "<3>" /* error conditions */
#define KERN_WARNING "<4>" /* warning conditions */
#define KERN_NOTICE "<5>" /* normal but significant condition */
#define KERN_INFO "<6>" /* informational */
#define KERN_DEBUG "<7>" /* debug-level messages */
#define console_loglevel (console_printk[0])
#define default_message_loglevel (console_printk[1])
#define minimum_console_loglevel (console_printk[2])
#define default_console_loglevel (console_printk[3])
#define DEFAULT_MESSAGE_LOGLEVEL CONFIG_DEFAULT_MESSAGE_LOGLEVEL
#define MINIMUM_CONSOLE_LOGLEVEL 1 /* Minimum loglevel we let people use */
#define DEFAULT_CONSOLE_LOGLEVEL 7 /* anything MORE serious than KERN_DEBUG */
int console_printk[4] = {
DEFAULT_CONSOLE_LOGLEVEL, /* console_loglevel */
DEFAULT_MESSAGE_LOGLEVEL, /* default_message_loglevel */
MINIMUM_CONSOLE_LOGLEVEL, /* minimum_console_loglevel */
DEFAULT_CONSOLE_LOGLEVEL, /* default_console_loglevel */
};
static int saved_console_loglevel = -1;
int do_syslog(int type, char __user *buf, int len, bool from_file)
{
unsigned i, j, limit, count;
int do_clear = 0;
char c;
int error;
error = check_syslog_permissions(type, from_file);
if (error)
goto out;
error = security_syslog(type);
if (error)
return error;
switch (type) {
:
case SYSLOG_ACTION_CONSOLE_OFF:
if (saved_console_loglevel == -1)
saved_console_loglevel = console_loglevel;
console_loglevel = minimum_console_loglevel;
break;
case SYSLOG_ACTION_CONSOLE_ON:
if (saved_console_loglevel != -1) {
console_loglevel = saved_console_loglevel;
saved_console_loglevel = -1;
}
break;
case SYSLOG_ACTION_CONSOLE_LEVEL:
error = -EINVAL;
if (len < 1 || len > 8)
goto out;
if (len < minimum_console_loglevel)
len = minimum_console_loglevel;
console_loglevel = len;
saved_console_loglevel = -1;
error = 0;
break;
:
default:
error = -EINVAL;
break;
}
out:
return error;
}






