Problem
How can I tell the kernel not to display any error messages on the system console?
Solution
The following program shows how to do it. Note that kernel messages
will still go to /usr/adm/messages, but not to the current
multiscreen. This will affect any routine that calls cmn_err(K).** Please note that you will need the Development System to compile this program**
---cut paste glue---
/* this program turns kernel messages on or off. they still go to /dev/error
* and hence to /usr/adm/messages via /etc/logger
* Note that this is more powerful than the FLIOCPRT floppy ioctl which
* just prevents floppy error messages from showing up on the screen -- this
* blocks everything except panic messages.
* I have another program which redirects all cmn_err messages from the
* active multiscreen to a *specific* multiscreen by patching cnputchar().
* Also take a look at Sdsk_verbosity in /etc/conf/pack.d/Sdsk/space.c
*
* this program requires read access on /unix and write access on /dev/kmem
* Only works on Vers. 4.[012] and 5.0 - version 3.2.2 uses macros which you
* can't patch.
* - Nathan
*
* Compile: cc kernel.c # for 3.2.4.x OS
* cc -DOSR5 kernel.c # for 3.2.5.0 OS
*
*/
#include <stdio.h>
#include <sys/types.h>
#include <nlist.h>
#ifndef UNIX
#define UNIX "/unix"
#endif
#ifndef KMEM
#define KMEM "/dev/kmem"
#endifstruct nlist nl[2]; /* sym, NULL */
char* malloc();
char* calloc();
char* strcpy();/* * turn kernel messages to screen "on" or "off" */ main(argc, argv) int argc; char *argv[]; { int i, fd, loop2; unsigned int val; int setval, doset = 0; char buf[100]; char ch;
if (argc == 1) { printf("This utility prevents kernel messages from going to the screen\n"); printf("They will still go to /dev/error (and hence /usr/adm/messages)\n"); printf("will work on 3.2.4.[012] and 3.2.5.0 OS -- will never work on "); printf("3.2.2OS\n"); printf("Usage: %s [off|on]\n",argv[0]); exit(1); }
if (strcmp(argv[1],"off") && strcmp(argv[1],"on")) {
printf("Usage: %s [off|on]\n",argv[0]);
exit(1);
} nl[0].n_name = "prfchar";
nl[1].n_name = NULL;
if (nlist(UNIX, nl) == -1)
error(UNIX);
if ((fd = open(KMEM, 2)) == -1)
error(KMEM);
#ifdef OSR5
#define OFFSET 0x51
#else
#define OFFSET 0x43 /* offset into routine where if (prt_where & PRF_CONS) */
#endif
lseek(fd, nl[0].n_value + OFFSET, 0); /* NOT _prfchar */
read(fd, &ch, 1);
if ( (ch != 0x2) && (ch != 0x0)) { /* feeble sanity check here */
/* PRF_CONS=2 in prfchar in kernel os/prf.c:see <sys/cmn_err.h> */
printf("wrong value (got 0x%x) should be 0x0 or 0x2\n",(int) ch);
exit(1);
}
lseek(fd, nl[0].n_value + OFFSET, 0);
ch= (strcmp(argv[1],"off") ? 0x2 : 0x0);/*can change to if (prt_where & 0)*/
if (write(fd, &ch, 1) == -1) { error("write"); exit(1); }
close(fd);
exit(0);
return(0);
}error(s)
char* s;
{
perror(s);
exit(1);
}/* end of program */