Ejemplo n.º 1
0
int logfile_del(char *filename)
{
	logfile_t *log;
	int i;

	log = NULL;
	for (i = 0; i < nlogfiles; i++) {
		log = &logfiles[i];
		if (!strcmp(log->filename, filename)) break;
		log = NULL;
	}

	if (log == NULL) return(-1);
		
	if (log->fp) {
		flushlog(log, timer_get_timestamp());
		fclose(log->fp);
	}

	if (log->last_msg) free(log->last_msg);
	if (log->filename) free(log->filename);

	if (nlogfiles == 1) {
		free(logfiles);
		logfiles = NULL;
	} else {		
		memmove(logfiles + i, logfiles + i + 1, (nlogfiles - i - 1) * sizeof(logfile_t));
		logfiles = realloc(logfiles, (nlogfiles - 1) * sizeof(logfile_t));
	}

	nlogfiles--;

	return(0);
}
Ejemplo n.º 2
0
static void truncboardlog(int signo)
{
    int i;
    flushlog(-1);
    
    for (i = 0; i < sizeof(logconfig) / sizeof(struct taglogconfig); i++) {
		if (strcmp(logconfig[i].filename,"boardusage.log"))
			continue;
        if (logconfig[i].fd>=0) {
        	close(logconfig[i].fd);
        	f_mv(logconfig[i].filename,"boardusage.log.0");
        }
        if (logconfig[i].filename) {
            /*logconfig[i].fd = open(logconfig[i].filename, O_WRONLY);
            if (logconfig[i].fd < 0)
                logconfig[i].fd = creat(logconfig[i].filename, 0644);*/
            logconfig[i].fd = open(logconfig[i].filename, O_RDWR | O_CREAT, 0644);
            if (logconfig[i].fd < 0)
                bbslog("3error","can't open log file:%s.%s",logconfig[i].filename,strerror(errno));
        }
        if (logconfig[i].buf==NULL)
            logconfig[i].buf = malloc(logconfig[i].bufsize);
    }
    truncboard=true;
}
Ejemplo n.º 3
0
/* Flush the logfiles to disk
 */
void flushlogs()
{
	char *ts;
	int i;

	ts = timer_get_timestamp();
	for (i = 0; i < nlogfiles; i++) {
		flushlog(&logfiles[i], ts);
	}
}
Ejemplo n.º 4
0
int main()
{
    int msqid, i;
    struct bbs_msgbuf *msg;

    struct sigaction act;

    umask(027);

    chdir(BBSHOME);
    setuid(BBSUID);
    setreuid(BBSUID, BBSUID);
    setgid(BBSGID);
    setregid(BBSGID, BBSGID);
    if (dodaemon("bbslogd", true, true)) {
        bbslog("3error", "bbslogd had already been started!");
        return 0;
    }
    atexit(flushBBSlog_exit);
    bzero(&act, sizeof(act));
    act.sa_handler = flushlog;
    sigaction(SIGTERM, &act, NULL);
    sigaction(SIGABRT, &act, NULL);
    sigaction(SIGHUP, &act, NULL);
    act.sa_handler = flushBBSlog_time;
    sigaction(SIGALRM, &act, NULL);
    act.sa_handler = trunclog;
    sigaction(SIGUSR1, &act, NULL);
    act.sa_handler = truncboardlog;
    sigaction(SIGUSR2, &act, NULL);
    alarm(60*10); /*十分钟flush一次*/

    msqid = init_bbslog();
    if (msqid < 0)
        return -1;

    gb_trunclog=false;
    truncboard=false;
    openbbslog(1);
    while (1) {
        if ((msg = rcvlog(msqid)) != NULL)
            writelog(msg);
        if (gb_trunclog)
        	do_trunclog();
		else if(truncboard)
			do_truncboardlog();
    }
    flushlog(-1);
    for (i = 0; i < sizeof(logconfig) / sizeof(struct taglogconfig); i++) {
        free(logconfig[i].buf);
    }
}
Ejemplo n.º 5
0
static void trunclog(int signo)
{
    int i;
    flushlog(-1);

    /* see libBBS/log.c:logconf[] */
    static const char *dirty_rotate[] = {"error.log", "connect.log", "msg.log",
       "trace.chatd", "trace"};
    for (i = 0; i < sizeof(dirty_rotate) / sizeof(dirty_rotate[0]); i++) {
        char buf[MAXPATH];
        int j;

        if (!dashf(dirty_rotate[i]))
            continue;

        j=0;
        while (1) {
            sprintf(buf,"%s.%d", dirty_rotate[i],j);
            if (!dashf(buf))
               break;
            j++;
        }
        f_mv(dirty_rotate[i],buf);
    }
    
    for (i = 0; i < sizeof(logconfig) / sizeof(struct taglogconfig); i++) {
        struct taglogconfig *pconf;

		if (! strcmp(logconfig[i].filename,"boardusage.log"))
			continue;
        pconf = &logconfig[i];
        if (pconf->fd>=0) {
        	char buf[MAXPATH];
        	int j;
        	close(pconf->fd);
		j=0;
        	while (1) {
        	    sprintf(buf,"%s.%d",pconf->filename,j);
        	    if (!dashf(buf))
        	    	break;
		    j++;
        	}
        	f_mv(pconf->filename,buf);
        }
    }
    openbbslog(0);
    gb_trunclog=true;
}
Ejemplo n.º 6
0
static void flushBBSlog_time(int signo)
{
    flushlog(-1);
    alarm(60*10); /*十分钟flush一次*/
}
Ejemplo n.º 7
0
static void flushBBSlog_exit()
{
    flushlog(-1);
}
Ejemplo n.º 8
0
int main(int argc, char **argv)
{
	bool walk = false, randsize = false, verbose = false, csum = false, rtest = false, wtest = false;
	int fd1, fd2 = 0, direct = 0, nbytes = 4096, j, o;
	unsigned long size, i, offset = 0, done = 0, unique = 0, benchmark = 0;
	void *buf1 = NULL, *buf2 = NULL;
	struct pagestuff *pages, *p;
	unsigned char c[16];
	time_t last_printed = 0;
	extern char *optarg;

	RC4_KEY writedata;
	RC4_set_key(&writedata, 16, bcache_magic);

	while ((o = getopt(argc, argv, "dnwvscwlb:")) != EOF)
		switch (o) {
		case 'd':
			direct = O_DIRECT;
			break;
		case 'n':
			walk = true;
			break;
		case 'v':
			verbose = true;
			break;
		case 's':
			randsize = true;
			break;
		case 'c':
			csum = true;
			break;
		case 'w':
			wtest = true;
			break;
		case 'r':
			rtest = true;
			break;
		case 'l':
			klog = true;
			break;
		case 'b':
			benchmark = atol(optarg);
			break;
		default:
			usage();
		}

	argv += optind;
	argc -= optind;

	if (!rtest && !wtest)
		rtest = true;

	if (argc < 1) {
		printf("Please enter a device to test\n");
		exit(EXIT_FAILURE);
	}

	if (!csum && !benchmark && argc < 2) {
		printf("Please enter a device to compare against\n");
		exit(EXIT_FAILURE);
	}

	fd1 = open(argv[0], (wtest ? O_RDWR : O_RDONLY)|direct);
	if (!csum && !benchmark)
		fd2 = open(argv[1], (wtest ? O_RDWR : O_RDONLY)|direct);

	if (fd1 == -1 || fd2 == -1) {
		perror("Error opening device");
		exit(EXIT_FAILURE);
	}

	size = getblocks(fd1);
	if (!csum && !benchmark)
		size = MIN(size, getblocks(fd2));

	size = size / 8 - 16;
	pages = calloc(size + 16, sizeof(*pages));
	printf("size %li\n", size);

	if (posix_memalign(&buf1, 4096, 4096 * 16) ||
	    posix_memalign(&buf2, 4096, 4096 * 16)) {
		printf("Could not allocate buffers\n");
		exit(EXIT_FAILURE);
	}
	//setvbuf(stdout, NULL, _IONBF, 0);

	for (i = 0; !benchmark || i < benchmark; i++) {
		bool writing = (wtest && (i & 1)) || !rtest;
		nbytes = randsize ? drand48() * 16 + 1 : 1;
		nbytes <<= 12;

		offset >>= 12;
		offset += walk ? normal() * 20 : random();
		offset %= size;
		offset <<= 12;

		if (!(i % 200))
			flushlog();

		if (!verbose) {
			time_t now = time(NULL);
			if (now - last_printed >= 2) {
				last_printed = now;
				goto print;
			}
		} else
print:			printf("Loop %6li offset %9li sectors %3i, %6lu mb done, %6lu mb unique\n",
			       i, offset >> 9, nbytes >> 9, done >> 11, unique >> 11);

		done += nbytes >> 9;

		if (!writing)
			Pread(fd1, buf1, nbytes, offset);
		if (!writing && !csum && !benchmark)
			Pread(fd2, buf2, nbytes, offset);

		for (j = 0; j < nbytes; j += 4096) {
			p = &pages[(offset + j) / 4096];

			if (writing)
				RC4(&writedata, 4096, zero, buf1 + j);

			if (csum) {
				MD4(buf1 + j, 4096, &c[0]);

				if (writing ||
				    (!p->readcount && !p->writecount)) {
					memcpy(&p->oldcsum[0], &p->csum[0], 16);
					memcpy(&p->csum[0], c, 16);
				} else if (memcmp(&p->csum[0], c, 16))
					goto bad;
			} else if (!writing && !benchmark &&
				   memcmp(buf1 + j,
					  buf2 + j,
					  4096))
				goto bad;

			if (!p->writecount && !p->readcount)
				unique += 8;

			writing ? p->writecount++ : p->readcount++;
		}
		if (writing)
			Pwrite(fd1, buf1, nbytes, offset);
		if (writing && !csum && !benchmark)
			Pwrite(fd2, buf2, nbytes, offset);
	}
	printf("Loop %6li offset %9li sectors %3i, %6lu mb done, %6lu mb unique\n",
	       i, offset >> 9, nbytes >> 9, done >> 11, unique >> 11);
	exit(EXIT_SUCCESS);
err:
	perror("IO error");
	flushlog();
	exit(EXIT_FAILURE);
bad:
	printf("Bad read! loop %li offset %li readcount %i writecount %i\n",
	       i, (offset + j) >> 9, p->readcount, p->writecount);

	if (!memcmp(&p->oldcsum[0], c, 16))
		printf("Matches previous csum\n");

	flushlog();
	exit(EXIT_FAILURE);
}
Ejemplo n.º 9
0
/**
 * exitlog: flush log and exit.  sigint/sigterm handler.
 *
 * @param ignore ignored
 */
static void exitlog(int ignore) {

    flushlog(ignore);
    exit(0);
}