Exemple #1
0
void data_stack_init(void)
{
	if (data_stack_frame > 0) {
		/* already initialized (we did auto-initialization in
		   t_malloc/t_push) */
		return;
	}
	data_stack_frame = 1;

	outofmem_area.block.size = outofmem_area.block.left =
		sizeof(outofmem_area) - sizeof(outofmem_area.block);

	current_block = mem_block_alloc(INITIAL_STACK_SIZE);
	current_block->left = current_block->size;
	current_block->next = NULL;

	current_frame_block = NULL;
	unused_frame_blocks = NULL;
	frame_pos = BLOCK_FRAME_COUNT-1;

	last_buffer_block = NULL;
	last_buffer_size = 0;

	(void)t_push();
}
Exemple #2
0
static void io_loop_handle_timeouts_real(struct ioloop *ioloop)
{
	struct priorityq_item *item;
	struct timeval tv, tv_call;
	unsigned int t_id;

	if (gettimeofday(&ioloop_timeval, NULL) < 0)
		i_fatal("gettimeofday(): %m");

	/* Don't bother comparing usecs. */
	if (unlikely(ioloop_time > ioloop_timeval.tv_sec)) {
		/* time moved backwards */
		io_loops_timeouts_update(-(long)(ioloop_time -
						 ioloop_timeval.tv_sec));
		ioloop->time_moved_callback(ioloop_time,
					    ioloop_timeval.tv_sec);
		/* the callback may have slept, so check the time again. */
		if (gettimeofday(&ioloop_timeval, NULL) < 0)
			i_fatal("gettimeofday(): %m");
	} else if (unlikely(ioloop_timeval.tv_sec >
			    ioloop->next_max_time)) {
		io_loops_timeouts_update(ioloop_timeval.tv_sec -
					ioloop->next_max_time);
		/* time moved forwards */
		ioloop->time_moved_callback(ioloop->next_max_time,
					    ioloop_timeval.tv_sec);
	}

	ioloop_time = ioloop_timeval.tv_sec;
	tv_call = ioloop_timeval;

	while ((item = priorityq_peek(ioloop->timeouts)) != NULL) {
		struct timeout *timeout = (struct timeout *)item;

		/* use tv_call to make sure we don't get to infinite loop in
		   case callbacks update ioloop_timeval. */
		if (timeout_get_wait_time(timeout, &tv, &tv_call) > 0)
			break;

		/* update timeout's next_run and reposition it in the queue */
		timeout_reset_timeval(timeout, &tv_call);

		if (timeout->log != NULL) {
			ioloop->cur_log = timeout->log;
			io_loop_log_ref(ioloop->cur_log);
			i_set_failure_prefix(timeout->log->prefix);
		}
                t_id = t_push();
		timeout->callback(timeout->context);
		if (t_pop() != t_id) {
			i_panic("Leaked a t_pop() call in timeout handler %p",
				(void *)timeout->callback);
		}
		if (ioloop->cur_log != NULL) {
			io_loop_log_unref(&ioloop->cur_log);
			i_set_failure_prefix(ioloop->default_log_prefix);
		}
	}
}
Exemple #3
0
/*
 ****************************************************************
 *	Escrita na Conexão					*
 ****************************************************************
 */
int
tcp_write (int fd, void *buf, int size)
{
	if (size <= 0)
	{
		t_push (fd);
		return (0);
	}

	return (t_snd (fd, buf, size, T_PUSH));

}	/* end tcp_write */
Exemple #4
0
unsigned int t_push(void)
{
        struct stack_frame_block *frame_block;

	frame_pos++;
	if (frame_pos == BLOCK_FRAME_COUNT) {
		/* frame block full */
		if (data_stack_frame == 0) {
			/* kludgy, but allow this before initialization */
			frame_pos = 0;
			data_stack_init();
			return t_push();
		}

		frame_pos = 0;
		if (unused_frame_blocks == NULL) {
			/* allocate new block */
#ifndef USE_GC
			frame_block = calloc(sizeof(*frame_block), 1);
#else
			frame_block = GC_malloc(sizeof(*frame_block));
#endif
			if (frame_block == NULL) {
				i_fatal_status(FATAL_OUTOFMEM,
					       "t_push(): Out of memory");
			}
		} else {
			/* use existing unused frame_block */
			frame_block = unused_frame_blocks;
			unused_frame_blocks = unused_frame_blocks->prev;
		}

		frame_block->prev = current_frame_block;
		current_frame_block = frame_block;
	}
	data_stack_last_buffer_reset(FALSE);

	/* mark our current position */
	current_frame_block->block[frame_pos] = current_block;
	current_frame_block->block_space_used[frame_pos] = current_block->left;
        current_frame_block->last_alloc_size[frame_pos] = 0;

        return data_stack_frame++;
}
Exemple #5
0
/*
 ****************************************************************
 *	Copia um arquivo para o cliente				*
 ****************************************************************
 */
void
copy_to (const char *file_nm)
{
	off_t		n;
	int		fd = -1;
	STAT		s;
#ifdef	LITTLE_ENDIAN
	STAT		big_s;
#endif	LITTLE_ENDIAN
	char		*rmsg;

	/*
	 *	Obtém o estado do arquivo
	 */
	if (lstat (file_nm, &s) < 0)
	{
		t_snd_msg (-1, strerror (errno));
		return;
	}

	if (S_ISREG (s.st_mode) && (fd = inopen (s.st_dev, s.st_ino)) < 0)
	{
		t_snd_msg (-1, strerror (errno));
		return;
	}

	/*
	 *	Transmite o nome e estado do arquivo
	 */
	t_snd_msg_no_push (0, NOSTR);

#ifdef	LITTLE_ENDIAN
	stat_endian_cv (&big_s, &s);

	if (t_snd (tcp_fd, &big_s, sizeof (STAT), T_PUSH) < 0)
		error (NOSTR);
#else
	if (t_snd (tcp_fd, &s, sizeof (STAT), T_PUSH) < 0)
		error (NOSTR);
#endif	LITTLE_ENDIAN

	/*
	 *	Se for um elo simbólico, envia também o conteúdo
	 */
	if (S_ISLNK (s.st_mode))
	{
		char		*local_symlink_nm;

		n = s.st_size + 1; local_symlink_nm  = alloca (n);

		if (readlink (file_nm, local_symlink_nm, n) < 0)
			error ("$*Não consegui obter o conteúdo do elo \"%s\"", file_nm);

		if (t_snd (tcp_fd, local_symlink_nm, n, 0) < 0)
			error (NOSTR);

		t_push (tcp_fd);
	}

	/*
	 *	Espera confirmação de criação do arquivo na estação remota
	 */
	if (t_rcv_msg (&rmsg) < 0)
	{
		if (fd > 0)
			close (fd);
		return;
	}

	/*
	 *	Se não for regular, não precisa de enviar o conteúdo
	 */
	if (!S_ISREG (s.st_mode))
		return;

	/*
	 *	Transmite os segmentos
	 */
	if (Cflag && s.st_size >= MIN_COMPRESS_SZ)
	{
		reduce (fd, snd_rcv_buf);
	}
	else
	{
		for
		(	/* vazio */;
			(n = read (fd, snd_rcv_buf, BLSZ)) > 0;
			/* vazio */
		)
		{
			if (t_snd (tcp_fd, snd_rcv_buf, n, 0) < 0)
				error (NOSTR);

		}	/* loop pelo segmentos */
	
		if (n < 0)
			error ("$*Erro de leitura do arquivo \"%s\"", file_nm);
	}

	t_push (tcp_fd);

	close (fd);

}	/* end file_copy */
Exemple #6
0
void
conv(register FILE *fp)
{
	register int c, k;
	int m, n, n1, m1;
	char str[4096], buf[4096];

	while ((c = getc(fp)) != EOF) {
		switch (c) {
		case '\n':	/* when input is text */
		case ' ':
		case 0:		/* occasional noise creeps in */
			break;
		case '{':	/* push down current environment */
			t_push();
			break;
		case '}':
			t_pop();
			break;
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			/* two motion digits plus a character */
			hmot((c-'0')*10 + getc(fp)-'0');
			put1(getc(fp));
			break;
		case 'c':	/* single ascii character */
			put1(getc(fp));
			break;
		case 'C':
			sget(str, sizeof str, fp);
			put1s(str);
			break;
		case 't':	/* straight text */
			fgets(buf, sizeof(buf), fp);
			t_text(buf);
			break;
		case 'D':	/* draw function */
			fgets(buf, sizeof(buf), fp);
			switch (buf[0]) {
			case 'l':	/* draw a line */
				sscanf(buf+1, "%d %d", &n, &m);
				drawline(n, m, ".");
				break;
			case 'c':	/* circle */
				sscanf(buf+1, "%d", &n);
				drawcirc(n);
				break;
			case 'e':	/* ellipse */
				sscanf(buf+1, "%d %d", &m, &n);
				drawellip(m, n);
				break;
			case 'a':	/* arc */
				sscanf(buf+1, "%d %d %d %d", &n, &m, &n1, &m1);
				drawarc(n, m, n1, m1);
				break;
			case '~':	/* wiggly line */
				drawwig(buf+1);
				break;
			default:
				error(FATAL, "unknown drawing function %s\n", buf);
				break;
			}
			break;
		case 's':
			fscanf(fp, "%d", &n);
			if (n == -23) {
				float	f;
				fscanf(fp, "%f", &f);
				setsize(f);
			} else
				setsize(t_size(n));/* ignore fractional sizes */
			break;
		case 'f':
			sget(str, sizeof str, fp);
			setfont(t_font(str));
			break;
		case 'H':	/* absolute horizontal motion */
			/* fscanf(fp, "%d", &n); */
			while ((c = getc(fp)) == ' ')
				;
			k = 0;
			do {
				k = 10 * k + c - '0';
			} while (isdigit(c = getc(fp)));
			ungetc(c, fp);
			hgoto(k);
			break;
		case 'h':	/* relative horizontal motion */
			/* fscanf(fp, "%d", &n); */
			while ((c = getc(fp)) == ' ')
				;
			k = 0;
			do {
				k = 10 * k + c - '0';
			} while (isdigit(c = getc(fp)));
			ungetc(c, fp);
			hmot(k);
			break;
		case 'w':	/* word space */
			putc(' ', stdout);
			break;
		case 'V':
			fscanf(fp, "%d", &n);
			vgoto(n);
			break;
		case 'v':
			fscanf(fp, "%d", &n);
			vmot(n);
			break;
		case 'p':	/* new page */
			fscanf(fp, "%d", &n);
			t_page(n);
			break;
		case 'n':	/* end of line */
			while (getc(fp) != '\n')
				;
			t_newline();
			break;
		case '#':	/* comment */
			while (getc(fp) != '\n')
				;
			break;
		case 'x':	/* device control */
			devcntrl(fp);
			break;
		default:
			error(!FATAL, "unknown input character %o %c\n", c, c);
			done();
		}
	}
}