1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
/* $Id: error.c,v 1.1 1994/05/08 02:43:36 root Exp root $ */
#include "chinese.h"
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/vt.h>
static char err_buf[256];
FILE *stddebug;
void error_init()
{
char errlog[12];
int lcon;
int original_console;
struct vt_stat vstate;
ioctl(0,VT_GETSTATE,(int)&vstate);
original_console = vstate.v_active;
if ( getenv("CHDRV_LOG") != NULL )
{
strncpy(errlog,getenv("CHDRV_LOG"),11);
}
else
/* If user has not set the environment variable of the
* error logging VT, we determine a free one */
{
if ((ioctl(0,VT_OPENQRY,&lcon)<0)||(lcon==-1))
{
/* Can't find a free one, use /dev/tty8 to log error,
* not very graceful... */
strcpy(errlog,"/dev/tty8");
sys_config.errorVT = 8;
}
else
{
printf("Using virtual console #%d for error logging\n",
lcon);
snprintf(errlog,11,"/dev/tty%d", lcon);
sys_config.errorVT = lcon;
}
}
/* Open the error logging VT */
if ( (errorttyfd = open(errlog, O_RDWR, 0)) < 0 )
{
printf("Cannot open %s\n", errlog);
exit(-1);
}
else
{
ioctl(errorttyfd, VT_ACTIVATE, lcon);
ioctl(errorttyfd, VT_WAITACTIVE, lcon);
}
stddebug = fopen(errlog,"w");
if (!stddebug)
{
printf("Can't open error log %s\n",errlog);
sigquit(0);
exit(-1);
}
printf("Use %s as error log\n",errlog);
ioctl(errorttyfd, VT_ACTIVATE, original_console);
ioctl(errorttyfd, VT_WAITACTIVE, original_console);
}
void sys_error(char *file,int line,char *msg,...)
{
va_list AP;
va_start(AP,msg);
fprintf(stddebug,"in line %d of %s: ",line,file);
vfprintf(stddebug,msg,AP);
va_end(AP);
fprintf(stddebug,"\n");
}
|