Exemplo n.º 1
0
void
excludepattern(char *p)
{
	Reprog *re;

	if((re = glob2regexp(p)) == nil)
		sysfatal("bad glob pattern %s", p);

	pattern = vtrealloc(pattern, (npattern+1)*sizeof pattern[0]);
	pattern[npattern].re = re;
	pattern[npattern].include = 0;
	npattern++;
}
Exemplo n.º 2
0
void
loadexcludefile(char *file)
{
	Biobuf *b;
	char *p, *q;
	int n, inc;
	Reprog *re;

	if((b = Bopen(file, OREAD)) == nil)
		sysfatal("open %s: %r", file);
	for(n=1; (p=Brdstr(b, '\n', 1)) != nil; free(p), n++){
		q = p+strlen(p);
		while(q > p && isspace((uint8_t)*(q-1)))
			*--q = 0;
		switch(p[0]){
		case '\0':
		case '#':
			continue;
		}

		inc = 0;
		if(strncmp(p, "include ", 8) == 0){
			inc = 1;
		}else if(strncmp(p, "exclude ", 8) == 0){
			inc = 0;
		}else
			sysfatal("%s:%d: line does not begin with include or exclude", file, n);

		if(strchr(p+8, ' '))
			fprint(2, "%s:%d: warning: space in pattern\n", file, n);

		if((re = glob2regexp(p+8)) == nil)
			sysfatal("%s:%d: bad glob pattern", file, n);

		pattern = vtrealloc(pattern, (npattern+1)*sizeof pattern[0]);
		pattern[npattern].re = re;
		pattern[npattern].include = inc;
		npattern++;
	}
	Bterm(b);
}
Exemplo n.º 3
0
/*
 * allocate space for the clump and write it,
 * updating the arena directory
ZZZ question: should this distinguish between an arena
filling up and real errors writing the clump?
 */
uint64_t
writeaclump(Arena *arena, Clump *c, uint8_t *clbuf)
{
	DBlock *b;
	uint64_t a, aa;
	uint32_t clump, n, nn, m, off, blocksize;
	int ok;

	n = c->info.size + ClumpSize + U32Size;
	qlock(&arena->lock);
	aa = arena->memstats.used;
	if(arena->memstats.sealed
	|| aa + n + U32Size + arenadirsize(arena, arena->memstats.clumps + 1) > arena->size){
		if(!arena->memstats.sealed){
			logerr(EOk, "seal memstats %s", arena->name);
			arena->memstats.sealed = 1;
			wbarena(arena);
		}
		qunlock(&arena->lock);
		return TWID64;
	}
	if(packclump(c, &clbuf[0], arena->clumpmagic) < 0){
		qunlock(&arena->lock);
		return TWID64;
	}

	/*
	 * write the data out one block at a time
	 */
	blocksize = arena->blocksize;
	a = arena->base + aa;
	off = a & (blocksize - 1);
	a -= off;
	nn = 0;
	for(;;){
		b = getdblock(arena->part, a, off != 0 ? ORDWR : OWRITE);
		if(b == nil){
			qunlock(&arena->lock);
			return TWID64;
		}
		dirtydblock(b, DirtyArena);
		m = blocksize - off;
		if(m > n - nn)
			m = n - nn;
		memmove(&b->data[off], &clbuf[nn], m);
		ok = 0;
		putdblock(b);
		if(ok < 0){
			qunlock(&arena->lock);
			return TWID64;
		}
		nn += m;
		if(nn == n)
			break;
		off = 0;
		a += blocksize;
	}

	arena->memstats.used += c->info.size + ClumpSize;
	arena->memstats.uncsize += c->info.uncsize;
	if(c->info.size < c->info.uncsize)
		arena->memstats.cclumps++;

	clump = arena->memstats.clumps;
	if(clump % ArenaCIGSize == 0){
		if(arena->cig == nil){
			loadcig(arena);
			if(arena->cig == nil)
				goto NoCIG;
		}
		/* add aa as start of next cig */
		if(clump/ArenaCIGSize != arena->ncig){
			fprint(2, "bad arena cig computation %s: writing clump %d but %d cigs\n",
				arena->name, clump, arena->ncig);
			arena->ncig = -1;
			vtfree(arena->cig);
			arena->cig = nil;
			goto NoCIG;
		}
		arena->cig = vtrealloc(arena->cig, (arena->ncig+1)*sizeof arena->cig[0]);
		arena->cig[arena->ncig++].offset = aa;
	}
NoCIG:
	arena->memstats.clumps++;

	if(arena->memstats.clumps == 0)
		sysfatal("clumps wrapped");
	arena->wtime = now();
	if(arena->ctime == 0)
		arena->ctime = arena->wtime;

	writeclumpinfo(arena, clump, &c->info);
	wbarena(arena);

	qunlock(&arena->lock);

	return aa;
}
Exemplo n.º 4
0
void
sbupdate(Shabuf *sb, uchar *p, vlong offset, int len)
{
	int n, x;
	vlong o;

	if(sb->rollback && !sb->hist){
		sb->r0 = offset;
		sb->nhist = 1;
		sb->hist = vtmalloc(sb->nhist*sizeof *sb->hist);
		memset(sb->hist, 0, sizeof sb->hist[0]);
	}
	if(sb->r0 == 0)
		sb->r0 = offset;

	if(sb->offset < offset || sb->offset >= offset+len){
		if(0) print("sbupdate %p %#llux+%d but offset=%#llux\n",
			p, offset, len, sb->offset);
		return;
	}
	x = sb->offset - offset;
	if(0) print("sbupdate %p %#llux+%d skip %d\n",
		sb, offset, len, x);
	if(x){
		p += x;
		offset += x;
		len -= x;
	}
	assert(sb->offset == offset);
	
	if(sb->fd > 0)
		pwrite(sb->fd, p, len, offset - sb->r0);

	if(!sb->rollback){
		sha1(p, len, nil, &sb->state);
		sb->offset += len;
		return;
	}
	
	/* save state every 4M so we can roll back quickly */
	o = offset - sb->r0;
	while(len > 0){
		n = 4*M - o%(4*M);
		if(n > len)
			n = len;
		sha1(p, n, nil, &sb->state);
		sb->offset += n;
		o += n;
		p += n;
		len -= n;
		if(o%(4*M) == 0){
			x = o/(4*M);
			if(x >= sb->nhist){
				if(x != sb->nhist)
					print("oops! x=%d nhist=%d\n", x, sb->nhist);
				sb->nhist += 32;
				sb->hist = vtrealloc(sb->hist, sb->nhist*sizeof *sb->hist);
			}
			sb->hist[x] = sb->state;
		}
	}		
}
Exemplo n.º 5
0
int
rdconf(char *file, Conf *conf)
{
	char *s, *line, *flds[10];
	int i, ok;
	IFile f;
	
	if(readifile(&f, file) < 0)
		return -1;
	memset(conf, 0, sizeof *conf);
	ok = -1;
	line = nil;
	for(;;){
		s = ifileline(&f);
		if(s == nil){
			ok = 0;
			break;
		}
		line = estrdup(s);
		i = getfields(s, flds, nelem(flds), 1, " \t\r");
		if(i <= 0 || strcmp(flds[0], "mgr") != 0) {
			/* do nothing */
		}else if(i == 4 && strcmp(flds[1], "mirror") == 0) {
			if(conf->nmirror%64 == 0)
				conf->mirror = vtrealloc(conf->mirror, (conf->nmirror+64)*sizeof(conf->mirror[0]));
			conf->mirror[conf->nmirror].src = vtstrdup(flds[2]);
			conf->mirror[conf->nmirror].dst = vtstrdup(flds[3]);
			conf->nmirror++;
		}else if(i == 3 && strcmp(flds[1], "mirrorfreq") == 0) {
			conf->mirrorfreq = atoi(flds[2]);
		}else if(i == 3 && strcmp(flds[1], "verify") == 0) {
			if(conf->nverify%64 == 0)
				conf->verify = vtrealloc(conf->verify, (conf->nverify+64)*sizeof(conf->verify[0]));
			conf->verify[conf->nverify++] = vtstrdup(flds[2]);	
		}else if(i == 3 && strcmp(flds[1], "verifyfreq") == 0) {
			conf->verifyfreq = atoi(flds[2]);
		}else if(i == 3 && strcmp(flds[1], "httpaddr") == 0){
			if(conf->httpaddr){
				seterr(EAdmin, "duplicate httpaddr lines in configuration file %s", file);
				break;
			}
			conf->httpaddr = estrdup(flds[2]);
		}else if(i == 3 && strcmp(flds[1], "webroot") == 0){
			if(conf->webroot){
				seterr(EAdmin, "duplicate webroot lines in configuration file %s", file);
				break;
			}
			conf->webroot = estrdup(flds[2]);
		}else if(i == 3 && strcmp(flds[1], "smtp") == 0) {
			if(conf->smtp){
				seterr(EAdmin, "duplicate smtp lines in configuration file %s", file);
				break;
			}
			conf->smtp = estrdup(flds[2]);
		}else if(i == 3 && strcmp(flds[1], "mailfrom") == 0) {
			if(conf->mailfrom){
				seterr(EAdmin, "duplicate mailfrom lines in configuration file %s", file);
				break;
			}
			conf->mailfrom = estrdup(flds[2]);
		}else if(i == 3 && strcmp(flds[1], "mailto") == 0) {
			if(conf->mailto){
				seterr(EAdmin, "duplicate mailto lines in configuration file %s", file);
				break;
			}
			conf->mailto = estrdup(flds[2]);
		}else{
			seterr(EAdmin, "illegal line '%s' in configuration file %s", line, file);
			break;
		}
		free(line);
		line = nil;
	}
	free(line);
	freeifile(&f);
	return ok;
}