2005-01-02 16:10:14 +00:00
|
|
|
/* LOGGER.C (c) Copyright Jan Jaeger, 2003-2005 */
|
2003-06-02 13:16:07 +00:00
|
|
|
/* System logger functions */
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
/* If standard output or standard error is redirected then the log */
|
|
|
|
|
/* is written to the redirection. */
|
|
|
|
|
/* If standard output and standard error are both redirected then */
|
|
|
|
|
/* the system log is written to the redirection of standard error */
|
|
|
|
|
/* the redirection of standard output is ignored in this case, */
|
|
|
|
|
/* and background mode is assumed. */
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
/* Any thread can determine background mode by inspecting stderr */
|
|
|
|
|
/* for isatty() */
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-11-26 08:31:31 +00:00
|
|
|
#include "hercules.h"
|
2003-08-19 21:00:41 +00:00
|
|
|
#include "opcode.h" /* Required for SETMODE macro */
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2004-08-27 13:43:16 +00:00
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
static ATTR logger_attr;
|
|
|
|
|
static COND logger_cond;
|
|
|
|
|
static LOCK logger_lock;
|
|
|
|
|
static TID logger_tid;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-28 10:53:58 +00:00
|
|
|
static char *logger_buffer;
|
2003-07-19 08:12:56 +00:00
|
|
|
static int logger_bufsize;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
static int logger_currmsg;
|
|
|
|
|
static int logger_wrapped;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
static int logger_active;
|
|
|
|
|
|
|
|
|
|
static FILE *logger_syslog[2]; /* Syslog read/write pipe */
|
|
|
|
|
static int logger_syslogfd[2]; /* pairs */
|
|
|
|
|
static FILE *logger_hrdcpy; /* Hardcopy log or zero */
|
|
|
|
|
static int logger_hrdcpyfd; /* Hardcopt fd or -1 */
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
/* Find the index for a specific line number in the log, */
|
|
|
|
|
/* one being the most recent line */
|
|
|
|
|
/* Example: */
|
|
|
|
|
/* read the last 5 lines in the syslog: */
|
|
|
|
|
/* */
|
|
|
|
|
/* int msgnum; */
|
|
|
|
|
/* int msgidx; */
|
|
|
|
|
/* char *msgbuf; */
|
|
|
|
|
/* */
|
|
|
|
|
/* msgidx = log_line(5); */
|
|
|
|
|
/* while((msgcnt = log_read(&msgbuf, &msgidx, LOG_NOBLOCK))) */
|
|
|
|
|
/* function_to_process_log(msgbuf, msgcnt); */
|
|
|
|
|
/* */
|
|
|
|
|
int log_line(int linenumber)
|
2003-03-22 14:22:40 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
char *msgbuf[2],*tmpbuf = NULL;
|
|
|
|
|
int msgidx[2] = { -1, -1 };
|
|
|
|
|
int msgcnt[2];
|
|
|
|
|
int i;
|
2003-03-22 14:22:40 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
if(!linenumber++)
|
|
|
|
|
return logger_currmsg;
|
2003-03-22 14:32:40 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
/* Find the last two blocks in the log */
|
|
|
|
|
do {
|
|
|
|
|
msgidx[0] = msgidx[1];
|
|
|
|
|
msgbuf[0] = msgbuf[1];
|
|
|
|
|
msgcnt[0] = msgcnt[1];
|
|
|
|
|
} while((msgcnt[1] = log_read(&msgbuf[1], &msgidx[1], LOG_NOBLOCK)));
|
2003-06-01 11:46:25 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
for(i = 0; i < 2 && linenumber; i++)
|
|
|
|
|
if(msgidx[i] != -1)
|
|
|
|
|
{
|
|
|
|
|
for(; linenumber > 0; linenumber--)
|
|
|
|
|
{
|
2004-08-27 13:43:16 +00:00
|
|
|
if(!(tmpbuf = (void *)memrchr(msgbuf[i],'\n',msgcnt[i])))
|
2003-06-02 13:16:07 +00:00
|
|
|
break;
|
|
|
|
|
msgcnt[i] = tmpbuf - msgbuf[i];
|
|
|
|
|
}
|
|
|
|
|
if(!linenumber)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-06-01 11:46:25 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
while(i < 2 && tmpbuf && (*tmpbuf == '\r' || *tmpbuf == '\n'))
|
2003-03-22 14:32:40 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
tmpbuf++;
|
|
|
|
|
msgcnt[i]++;
|
2003-03-22 14:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
return i ? msgcnt[i] + msgidx[0] : msgcnt[i];
|
|
|
|
|
}
|
2003-03-22 14:22:40 +00:00
|
|
|
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
/* log_read - read system log */
|
|
|
|
|
/* parameters: */
|
|
|
|
|
/* buffer - pointer to bufferpointer */
|
|
|
|
|
/* the bufferpointer will be returned */
|
|
|
|
|
/* msgindex - an index used on multiple read requests */
|
|
|
|
|
/* a value of -1 ensures that reading starts at the */
|
|
|
|
|
/* oldest entry in the log */
|
|
|
|
|
/* block - LOG_NOBLOCK - non blocking request */
|
|
|
|
|
/* LOG_BLOCK - blocking request */
|
|
|
|
|
/* returns: */
|
|
|
|
|
/* number of bytes in buffer or zero */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
int log_read(char **buffer, int *msgindex, int block)
|
|
|
|
|
{
|
|
|
|
|
int bytes_returned;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
obtain_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-29 07:31:56 +00:00
|
|
|
if(*msgindex == logger_currmsg && block)
|
2003-06-29 06:18:18 +00:00
|
|
|
{
|
2003-06-29 07:31:56 +00:00
|
|
|
if(logger_active)
|
|
|
|
|
{
|
|
|
|
|
wait_condition(&logger_cond, &logger_lock);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
*msgindex = logger_currmsg;
|
|
|
|
|
*buffer = logger_buffer + logger_currmsg;
|
|
|
|
|
release_lock(&logger_lock);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2003-06-29 06:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
if(*msgindex != logger_currmsg)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
if(*msgindex < 0)
|
|
|
|
|
*msgindex = logger_wrapped ? logger_currmsg : 0;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
if(*msgindex < 0 || *msgindex >= logger_bufsize)
|
|
|
|
|
*msgindex = 0;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
*buffer = logger_buffer + *msgindex;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
if(*msgindex >= logger_currmsg)
|
|
|
|
|
{
|
|
|
|
|
bytes_returned = logger_bufsize - *msgindex;
|
|
|
|
|
*msgindex = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bytes_returned = logger_currmsg - *msgindex;
|
|
|
|
|
*msgindex = logger_currmsg;
|
|
|
|
|
}
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
2003-06-02 13:16:07 +00:00
|
|
|
else
|
|
|
|
|
bytes_returned = 0;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
release_lock(&logger_lock);
|
2003-06-01 11:46:25 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
return bytes_returned;
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-29 12:00:53 +00:00
|
|
|
static void logger_term(void *arg __attribute__ ((unused)) )
|
|
|
|
|
{
|
|
|
|
|
|
2003-06-30 07:06:33 +00:00
|
|
|
if(logger_active)
|
|
|
|
|
{
|
|
|
|
|
obtain_lock(&logger_lock);
|
2003-06-29 12:00:53 +00:00
|
|
|
|
2003-11-26 08:31:31 +00:00
|
|
|
/* Flush all pending logger o/p before redirecting?? */
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
|
2003-06-30 07:06:33 +00:00
|
|
|
/* Redirect all output to stderr */
|
|
|
|
|
dup2(STDERR_FILENO, STDOUT_FILENO);
|
2003-06-29 12:00:53 +00:00
|
|
|
|
2003-11-26 08:31:31 +00:00
|
|
|
/* Tell logger thread we want it to exit */
|
2003-06-30 07:06:33 +00:00
|
|
|
logger_active = 0;
|
2003-06-29 12:00:53 +00:00
|
|
|
|
2003-06-30 07:06:33 +00:00
|
|
|
/* Send the logger a message to wake it up */
|
2003-07-19 08:12:56 +00:00
|
|
|
fprintf(logger_syslog[LOG_WRITE], _("HHCLG014I logger thread terminating\n") );
|
2003-06-29 12:00:53 +00:00
|
|
|
|
2003-06-30 07:06:33 +00:00
|
|
|
/* Wait for the logger to terminate */
|
|
|
|
|
wait_condition(&logger_cond, &logger_lock);
|
2003-06-29 12:00:53 +00:00
|
|
|
|
2003-06-30 07:06:33 +00:00
|
|
|
release_lock(&logger_lock);
|
2003-06-30 09:28:49 +00:00
|
|
|
|
|
|
|
|
/* Wait for the logger to terminate */
|
2003-11-27 12:11:02 +00:00
|
|
|
VERIFY(join_thread(logger_tid,NULL) == 0);
|
2003-11-26 08:31:31 +00:00
|
|
|
|
|
|
|
|
/* Release its system resources */
|
2003-11-27 12:11:02 +00:00
|
|
|
VERIFY(detach_thread(logger_tid) == 0);
|
2003-06-30 07:06:33 +00:00
|
|
|
}
|
2003-06-29 12:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
static void logger_thread(void *arg)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
int bytes_read;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
|
|
|
|
UNREFERENCED(arg);
|
|
|
|
|
|
2003-08-19 21:00:41 +00:00
|
|
|
/* Set root mode in order to set priority */
|
|
|
|
|
SETMODE(ROOT);
|
|
|
|
|
|
|
|
|
|
/* Set device thread priority; ignore any errors */
|
|
|
|
|
setpriority(PRIO_PROCESS, 0, sysblk.devprio);
|
|
|
|
|
|
|
|
|
|
/* Back to user mode */
|
|
|
|
|
SETMODE(USER);
|
|
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
if(dup2(logger_syslogfd[LOG_WRITE],STDOUT_FILENO) == -1)
|
2003-06-02 13:16:07 +00:00
|
|
|
{
|
2003-07-19 08:12:56 +00:00
|
|
|
if(logger_hrdcpy)
|
|
|
|
|
fprintf(logger_hrdcpy, _("HHCLG001E Error redirecting stdout: %s\n"),
|
2003-06-02 13:16:07 +00:00
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
setvbuf (stdout, NULL, _IOLBF, 0);
|
2003-11-26 08:31:31 +00:00
|
|
|
|
2003-06-29 12:00:53 +00:00
|
|
|
/* call logger_term on system shutdown */
|
|
|
|
|
hdl_adsc(logger_term, NULL);
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
obtain_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-29 06:18:18 +00:00
|
|
|
logger_active = 1;
|
|
|
|
|
|
2003-03-20 19:26:38 +00:00
|
|
|
/* Signal initialization complete */
|
|
|
|
|
signal_condition(&logger_cond);
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
release_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-07-01 04:19:23 +00:00
|
|
|
/* ZZ FIXME: We must empty the read pipe before we terminate */
|
2003-11-26 08:31:31 +00:00
|
|
|
/* (Couldn't we just loop waiting for a 'select(,&readset,,,timeout)'
|
|
|
|
|
to return zero?? Or use the 'poll' function similarly?? - Fish) */
|
|
|
|
|
|
2003-06-29 06:18:18 +00:00
|
|
|
while(logger_active)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-07-19 08:12:56 +00:00
|
|
|
bytes_read = read(logger_syslogfd[LOG_READ],logger_buffer + logger_currmsg,
|
2004-02-28 11:31:15 +00:00
|
|
|
((logger_bufsize - logger_currmsg) > LOG_DEFSIZE ? LOG_DEFSIZE : logger_bufsize - logger_currmsg));
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
if(bytes_read == -1)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2004-10-07 22:59:24 +00:00
|
|
|
if (EINTR == errno)
|
|
|
|
|
continue;
|
2003-07-19 08:12:56 +00:00
|
|
|
if(logger_hrdcpy)
|
|
|
|
|
fprintf(logger_hrdcpy, _("HHCLG002E Error reading syslog pipe: %s\n"),
|
2003-06-02 13:16:07 +00:00
|
|
|
strerror(errno));
|
|
|
|
|
bytes_read = 0;
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
if(logger_hrdcpy && fwrite(logger_buffer + logger_currmsg,bytes_read,1,logger_hrdcpy) != 1)
|
|
|
|
|
fprintf(logger_hrdcpy, _("HHCLG003E Error writing hardcopy log: %s\n"),
|
2003-06-02 13:16:07 +00:00
|
|
|
strerror(errno));
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
logger_currmsg += bytes_read;
|
|
|
|
|
if(logger_currmsg >= logger_bufsize)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
|
|
|
|
logger_currmsg = 0;
|
|
|
|
|
logger_wrapped = 1;
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
obtain_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
broadcast_condition(&logger_cond);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
release_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
2003-06-29 06:18:18 +00:00
|
|
|
|
|
|
|
|
/* Logger is now terminating */
|
|
|
|
|
obtain_lock(&logger_lock);
|
|
|
|
|
|
|
|
|
|
/* Redirect all msgs to stderr */
|
2003-07-19 08:12:56 +00:00
|
|
|
logger_syslog[LOG_WRITE] = stderr;
|
|
|
|
|
logger_syslogfd[LOG_WRITE] = STDERR_FILENO;
|
2003-06-29 06:18:18 +00:00
|
|
|
|
|
|
|
|
/* Signal any waiting tasks */
|
|
|
|
|
broadcast_condition(&logger_cond);
|
|
|
|
|
|
|
|
|
|
release_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
void logger_init(void)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-11-26 08:31:31 +00:00
|
|
|
// initialize_detach_attr (&logger_attr);
|
|
|
|
|
initialize_join_attr(&logger_attr); // (JOINable)
|
2003-06-02 13:16:07 +00:00
|
|
|
initialize_condition (&logger_cond);
|
|
|
|
|
initialize_lock (&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
obtain_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
logger_syslog[LOG_WRITE] = stderr;
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
/* If standard error is redirected, then use standard error
|
|
|
|
|
as the log file. */
|
|
|
|
|
if(!isatty(STDOUT_FILENO) && !isatty(STDERR_FILENO))
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-11-26 08:31:31 +00:00
|
|
|
/* Ignore standard output to the extent that it is
|
|
|
|
|
treated as standard error */
|
2003-07-19 08:12:56 +00:00
|
|
|
logger_hrdcpyfd = dup(STDOUT_FILENO);
|
2003-07-17 17:01:18 +00:00
|
|
|
if(dup2(STDERR_FILENO,STDOUT_FILENO) == -1)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, _("HHCLG004E Error duplicating stderr: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
2003-06-02 13:16:07 +00:00
|
|
|
else
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
if(!isatty(STDOUT_FILENO))
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-07-19 08:12:56 +00:00
|
|
|
logger_hrdcpyfd = dup(STDOUT_FILENO);
|
2003-06-02 13:16:07 +00:00
|
|
|
if(dup2(STDERR_FILENO,STDOUT_FILENO) == -1)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr, _("HHCLG004E Error duplicating stderr: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
2003-06-02 13:16:07 +00:00
|
|
|
if(!isatty(STDERR_FILENO))
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-07-19 08:12:56 +00:00
|
|
|
logger_hrdcpyfd = dup(STDERR_FILENO);
|
2003-06-02 13:16:07 +00:00
|
|
|
if(dup2(STDOUT_FILENO,STDERR_FILENO) == -1)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
fprintf(stderr, _("HHCLG005E Error duplicating stdout: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
if(logger_hrdcpyfd == -1)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-07-19 08:12:56 +00:00
|
|
|
logger_hrdcpyfd = 0;
|
2003-06-02 13:16:07 +00:00
|
|
|
fprintf(stderr, _("HHCLG006E Duplicate error redirecting hardcopy log: %s\n"),
|
|
|
|
|
strerror(errno));
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
if(logger_hrdcpyfd)
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-07-19 08:12:56 +00:00
|
|
|
if(!(logger_hrdcpy = fdopen(logger_hrdcpyfd,"w")))
|
2003-06-02 13:16:07 +00:00
|
|
|
fprintf(stderr, _("HHCLG007S Hardcopy log fdopen failed: %s\n"),
|
|
|
|
|
strerror(errno));
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
if(logger_hrdcpy)
|
|
|
|
|
setvbuf(logger_hrdcpy, NULL, _IONBF, 0);
|
2003-06-01 11:46:25 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
logger_bufsize = LOG_DEFSIZE;
|
2003-06-01 11:46:25 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
if(!(logger_buffer = malloc(logger_bufsize)))
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
fprintf(stderr, _("HHCLG008S logbuffer malloc failed: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
if(pipe(logger_syslogfd))
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
fprintf(stderr, _("HHCLG009S Syslog message pipe creation failed: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1); /* Hercules running without syslog */
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
if(!(logger_syslog[LOG_WRITE] = fdopen(logger_syslogfd[LOG_WRITE],"w")))
|
2003-06-01 11:46:25 +00:00
|
|
|
{
|
2003-07-19 08:12:56 +00:00
|
|
|
logger_syslog[LOG_WRITE] = stderr;
|
2003-06-02 13:16:07 +00:00
|
|
|
fprintf(stderr, _("HHCLG010S Syslog write message pipe open failed: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
2003-06-01 11:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
#if 0
|
2003-07-19 08:12:56 +00:00
|
|
|
if(!(logger_syslog[LOG_READ] = fdopen(logger_syslogfd[LOG_READ],"r")))
|
2003-06-02 13:16:07 +00:00
|
|
|
{
|
|
|
|
|
fprintf(stderr, _("HHCLG011S Syslog read message pipe open failed: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
2003-06-02 13:16:07 +00:00
|
|
|
#endif
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-07-19 08:12:56 +00:00
|
|
|
setvbuf (logger_syslog[LOG_WRITE], NULL, _IOLBF, 0);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-08-19 21:00:41 +00:00
|
|
|
if (create_thread (&logger_tid, &logger_attr, logger_thread, NULL))
|
2003-03-20 19:26:38 +00:00
|
|
|
{
|
2003-06-02 13:16:07 +00:00
|
|
|
fprintf(stderr, _("HHCLG012E Cannot create logger thread: %s\n"),
|
|
|
|
|
strerror(errno));
|
|
|
|
|
exit(1);
|
2003-03-20 19:26:38 +00:00
|
|
|
}
|
|
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
wait_condition(&logger_cond, &logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
2003-06-02 13:16:07 +00:00
|
|
|
release_lock(&logger_lock);
|
2003-03-20 19:26:38 +00:00
|
|
|
|
|
|
|
|
}
|
2004-01-07 09:47:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void log_sethrdcpy(char *filename)
|
|
|
|
|
{
|
|
|
|
|
FILE *temp_hrdcpy = logger_hrdcpy;
|
|
|
|
|
FILE *new_hrdcpy;
|
|
|
|
|
int new_hrdcpyfd;
|
|
|
|
|
|
|
|
|
|
if(!filename)
|
|
|
|
|
{
|
|
|
|
|
if(!logger_hrdcpy)
|
|
|
|
|
{
|
2004-01-08 07:40:54 +00:00
|
|
|
logmsg(_("HHCLG014E log not active\n"));
|
2004-01-07 09:47:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
obtain_lock(&logger_lock);
|
|
|
|
|
logger_hrdcpy = 0;
|
2004-10-07 22:59:24 +00:00
|
|
|
logger_hrdcpyfd = 0;
|
2004-01-07 09:47:08 +00:00
|
|
|
release_lock(&logger_lock);
|
2004-01-08 07:40:54 +00:00
|
|
|
fprintf(temp_hrdcpy,_("HHCLG015I log closed\n"));
|
2004-01-07 09:47:08 +00:00
|
|
|
fclose(temp_hrdcpy);
|
2004-01-08 07:40:54 +00:00
|
|
|
logmsg(_("HHCLG015I log closed\n"));
|
2004-01-07 09:47:08 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
new_hrdcpyfd = open(filename,
|
2004-10-07 22:59:24 +00:00
|
|
|
O_WRONLY | O_CREAT | O_TRUNC /* O_SYNC */,
|
2004-01-07 09:47:08 +00:00
|
|
|
S_IRUSR | S_IWUSR | S_IRGRP);
|
|
|
|
|
if(new_hrdcpyfd < 0)
|
|
|
|
|
{
|
2004-01-08 07:40:54 +00:00
|
|
|
logmsg(_("HHCLG016E Error opening logfile %s: %s\n"),
|
2004-01-07 09:47:08 +00:00
|
|
|
filename,strerror(errno));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(!(new_hrdcpy = fdopen(new_hrdcpyfd,"w")))
|
|
|
|
|
{
|
2004-01-08 07:40:54 +00:00
|
|
|
logmsg(_("HHCLG017S log file fdopen failed for %s: %s\n"),
|
2004-01-07 09:47:08 +00:00
|
|
|
filename, strerror(errno));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
setvbuf(new_hrdcpy, NULL, _IONBF, 0);
|
|
|
|
|
|
|
|
|
|
obtain_lock(&logger_lock);
|
|
|
|
|
logger_hrdcpy = new_hrdcpy;
|
|
|
|
|
logger_hrdcpyfd = new_hrdcpyfd;
|
|
|
|
|
release_lock(&logger_lock);
|
|
|
|
|
|
2004-10-07 22:59:24 +00:00
|
|
|
if(temp_hrdcpy)
|
2004-01-07 09:47:08 +00:00
|
|
|
{
|
2004-01-08 07:40:54 +00:00
|
|
|
fprintf(temp_hrdcpy,_("HHCLG018I log switched to %s\n"),
|
2004-01-07 09:47:08 +00:00
|
|
|
filename);
|
|
|
|
|
fclose(temp_hrdcpy);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-17 04:27:01 +00:00
|
|
|
/* log_wakeup - Wakeup any blocked threads. Useful during shutdown. */
|
|
|
|
|
void log_wakeup(void *arg)
|
|
|
|
|
{
|
|
|
|
|
UNREFERENCED(arg);
|
|
|
|
|
|
|
|
|
|
obtain_lock(&logger_lock);
|
2004-01-07 09:47:08 +00:00
|
|
|
|
2004-01-17 04:27:01 +00:00
|
|
|
broadcast_condition(&logger_cond);
|
|
|
|
|
|
|
|
|
|
release_lock(&logger_lock);
|
|
|
|
|
}
|