/*
 * This program shrinks down and keeps only usefull stuff
 * in /usr/rje/sque/log.It should be run before the RJE
 * system gets started. See /sys/source/current/start.hasp2.c for its use
 * and also see /usr/hasp/.makefile for its installation.   J.B.B.
 */

#define SIZEQ 200
#define QUELOG "/usr/rje/sque/log"
#define QUELOG2 "/usr/rje/sque/log2"
#include <sys/types.h>
#include <sys/stat.h>

char buf[SIZEQ];
int i,j;
struct	stat	statb;

main() {
	if ((i=open(QUELOG, 0))<0)
		exit(1);
	lseek(i,(long)(0),2);
	if (lseek(i,(long)(-SIZEQ),1) < 0)
		exit(0);
	do {
		read(i,buf,2);
		if (buf[0] == ':' && buf[1] == ':') {
			lseek(i,(long)(SIZEQ),1);
			break;
		}
	} 
	while (lseek(i,(long)(-(SIZEQ + 2)),1) >= 0);
	lseek(i,(long)(-2),1);
	j = creat(QUELOG2,0644);
	while(read(i,buf,SIZEQ) == SIZEQ)
		write(j,buf,SIZEQ);
	close(j); 
	close(i);
	stat(QUELOG,&statb);
	unlink(QUELOG);
	link(QUELOG2,QUELOG);
	unlink(QUELOG2);
	chown(QUELOG, statb.st_uid, statb.st_gid);
}
