Beispiel #1
0
int main(int argc, char *argv[])
{
	memset(&me, 0, sizeof(me));
	strcpy(me.name, "me.name.");

	rb_lib_init(NULL, NULL, NULL, 0, 1024, DNODE_HEAP_SIZE, FD_HEAP_SIZE);
	rb_linebuf_init(LINEBUF_HEAP_SIZE);

	plan_lazy();

	from_empty1();
	basic_append1();
	append_empty1();

	exact_fit_from_empty1();
	too_long_from_empty1();

	exact_fit_basic_append1();
	too_long_basic_append1();

	exact_fit_empty1();

	truncate_existing1();
	truncate_existing2();
	no_buffer();

	return 0;
}
Beispiel #2
0
/* setup all the stuff a new child needs */
rb_helper *
rb_helper_child(rb_helper_cb * read_cb, rb_helper_cb * error_cb, log_cb * ilog,
		restart_cb * irestart, die_cb * idie, size_t lb_heap_size,
		size_t dh_size, size_t fd_heap_size)
{
	rb_helper *helper;
	int maxfd, x = 0;
	int ifd, ofd;
	char *tifd, *tofd, *tmaxfd;

	tifd = getenv("IFD");
	tofd = getenv("OFD");
	tmaxfd = getenv("MAXFD");

	if(tifd == NULL || tofd == NULL || tmaxfd == NULL)
		return NULL;

	helper = rb_malloc(sizeof(rb_helper));
	ifd = (int)strtol(tifd, NULL, 10);
	ofd = (int)strtol(tofd, NULL, 10);
	maxfd = (int)strtol(tmaxfd, NULL, 10);

#ifndef _WIN32
	for(x = 0; x < maxfd; x++)
	{
		if(x != ifd && x != ofd)
			close(x);
	}
	x = open("/dev/null", O_RDWR);
	if(ifd != 0 && ofd != 0)
		dup2(x, 0);
	if(ifd != 1 && ofd != 1)
		dup2(x, 1);
	if(ifd != 2 && ofd != 2)
		dup2(x, 2);
	if(x > 2)		/* don't undo what we just did */
		close(x);
#else
	(void) x;	/* shut gcc up */
#endif

	rb_lib_init(ilog, irestart, idie, 0, maxfd, dh_size, fd_heap_size);
	rb_linebuf_init(lb_heap_size);
	rb_linebuf_newbuf(&helper->sendq);
	rb_linebuf_newbuf(&helper->recvq);

	helper->ifd = rb_open(ifd, RB_FD_PIPE, "incoming connection");
	helper->ofd = rb_open(ofd, RB_FD_PIPE, "outgoing connection");
	rb_set_nb(helper->ifd);
	rb_set_nb(helper->ofd);

	helper->read_cb = read_cb;
	helper->error_cb = error_cb;
	return helper;
}