errdemon source (Re: Using /etc/cron instead of /etc/smgr)

Michael "Ford" Ditto ditto at cbmvax.UUCP
Mon Aug 8 12:56:58 AEST 1988


Here's my simple errdemon to be used on the Unix PC when the Status
Manager (/etc/smgr) is not being used.

Basically, any system message that would have popped up in a cute,
annoying little window (with the [!!] icon) will now be appended to
/usr/adm/errfile instead.  Unfortunately, this includes messages sent
via write(1) to a user logged in on a window, but this is AT&T/CT's
idea, not mine.

					-=] Ford [=-


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create the files:
#	errdemon.c
# This archive created: Sun Aug  7 22:55:00 1988
export PATH; PATH=/bin:$PATH
echo shar: extracting "'errdemon.c'" '(1495 characters)'
if test -f 'errdemon.c'
then
	echo shar: will not over-write existing file "'errdemon.c'"
else
sed 's/^X//' << \SHAR_EOF > 'errdemon.c'
X#include <stdio.h>
X#include <fcntl.h>
X#include <signal.h>
X
Xextern char *ctime();
X
X
XFILE *logfp;
X
X
Xvoid handle_sig(sig)
Xint sig;
X{
X    long clock;
X    time (&clock);
X    fprintf(logfp, "errdemon stopping due to signal %d on %s\n",
X	    sig, ctime(&clock));
X
X    exit(sig!=SIGTERM);
X}
X
X
Xmain(argc, argv)
Xint argc;
Xchar *argv[];
X{
X    char errbuf[256];
X    long clock;
X    int i, len, errfd;
X    char *errfile = "/usr/adm/errfile";
X
X    if (argc>1)
X	errfile = argv[1];
X
X    logfp = fopen(errfile, "a");
X    if (logfp == NULL)
X    {
X	sprintf(errbuf, "errdemon: can't open %s", errfile);
X	perror(errbuf);
X	return -1;
X    }
X
X    switch (fork())
X    {
X    case -1:
X	perror("errdemon: fork");
X	return -1;
X    case 0:
X	break;
X    default:
X	return 0;
X    }
X
X    setpgrp();
X    signal(SIGINT, handle_sig);
X    signal(SIGQUIT, handle_sig);
X    signal(SIGTERM, handle_sig);
X    signal(SIGHUP, handle_sig);
X
X    close(2);
X    while (dup(fileno(logfp)) != 2)
X	;
X    close(0);
X    close(1);
X
X    time(&clock);
X    fprintf(logfp, "\n\n%s: started on %s\n", argv[0], ctime(&clock));
X    fflush(logfp);
X
X    errfd = open("/dev/error", O_RDONLY);
X    if (errfd<0)
X    {
X	perror("errdemon: can't open /dev/error");
X	return -1;
X    }
X
X    while (1)
X    {
X	len = read(errfd, errbuf, sizeof errbuf);
X	if (len<0)
X	{
X	    perror("errdemon: error reading /dev/error");
X	    return -2;
X	}
X
X	time(&clock);
X	fprintf(logfp, "%.24s: pid %5d: %.*s\n",
X		ctime(&clock), *(long *)errbuf, len-4, errbuf+4);
X	fflush(logfp);
X    }
X}
SHAR_EOF
if test 1495 -ne "`wc -c < 'errdemon.c'`"
then
	echo shar: error transmitting "'errdemon.c'" '(should have been 1495 characters)'
fi
fi # end of overwriting check
#	End of shell archive
exit 0
-- 
					-=] Ford [=-

	.		.		(In Real Life: Mike Ditto)
.	    :	       ,		ford at kenobi.cts.com
This space under construction,		...!ucsd!elgar!ford
pardon our dust.			ditto at cbmvax.commodore.com



More information about the Unix-pc.general mailing list