>> I would like the kernel not to spill messages to the console. I need to
>> do
>> this in my version of init. I call syslog(6, NULL, 0), but when some
>> SCSI
>> module is loaded the kernel spits out messages to the console. Please
>> note that syslogd, dmesg, /etc/syslog.conf are not available.
>> How do you correctly call syslog() to shut the messages down?
> Are you sure this has anything to do with syslog? By default
> all kernel messages will be printed directly to the console
> without going through any user process. Perhaps you want one
> of your init scripts to change on of the fields in
> /proc/sys/kernel/printk, I think it is the first one you
> should change.
Well, I have a function to direct the log messages to the given tty. It
seems to work fine, until a module is loaded. How do you change the first
field in /proc/sys/kernel/printk? echo "1\t4\t1\t7" >
/proc/sys/kernel/printf didn't change it.
Here's the function I'm talking about:
static int LclKernelLog(const char *logTerminal)
{
fd_set readSet;
int fdKernelMsg;
int fdTerminal, i;
int fdLogFile;
int pid;
char buf[1024];
/*---------------------------------------------------------------------
* Open the kmsg file...
*-------------------------------------------------------------------*/
fdKernelMsg = open("/proc/kmsg", O_RDONLY,0);
if (fdKernelMsg < 0)
return errno;
/*---------------------------------------------------------------------
* Create the temp log file
*-------------------------------------------------------------------*/
fdLogFile = open("/tmp/sys.log", O_WRONLY | O_CREAT, 0644);
if (fdLogFile < 0)
{
sleep(5);
close(fdKernelMsg);
return errno;
}
/*---------------------------------------------------------------------
* Create a process
*-------------------------------------------------------------------*/
pid = fork();
if (pid < 0)
return errno;
/*---------------------------------------------------------------------
* Parent process: Close the file handles
*-------------------------------------------------------------------*/
if (pid > 0)
{
close(fdKernelMsg);
close(fdLogFile);
return 0;
}
/*---------------------------------------------------------------------
* Child: Close the standard in/out/err fds
*-------------------------------------------------------------------*/
close(0);
close(1);
close(2);
/*---------------------------------------------------------------------
* Open the log terminal
*-------------------------------------------------------------------*/
fdTerminal = open(logTerminal, O_WRONLY, 0);
/*---------------------------------------------------------------------
* Disable log to console
*-------------------------------------------------------------------*/
syslog(6, NULL, 0);
/*---------------------------------------------------------------------
* Monitor and process the log
*-------------------------------------------------------------------*/
while (1)
{
/*-------------------------------------------------------------
* Set the file descriptor to monitor
*-----------------------------------------------------------*/
FD_ZERO(&readSet);
FD_SET(fdKernelMsg, &readSet);
/*-------------------------------------------------------------
* Monitor the log and catch it
*-----------------------------------------------------------*/
i = select(fdKernelMsg+1, &readSet, NULL, NULL, NULL);
if (i <= 0)
continue;
/*-------------------------------------------------------------
* Check descriptor for data to read
*-----------------------------------------------------------*/
if (FD_ISSET(fdKernelMsg, &readSet))
{
i = read(fdKernelMsg, buf, sizeof(buf));
if (i > 0)
{
write(fdTerminal, buf, i);
write(fdLogFile, buf, i);
}
}
}
return 0;
}
--
Quang