edge_stream_iterator(std::istream& s) : m_stream(&s) { m_read(); }
 edge_stream_iterator& operator++() { 
   m_read(); 
   return *this;
 }
示例#3
0
int
monitor_get_pfkey_snap(u_int8_t **sadb, u_int32_t *sadbsize, u_int8_t **spd,
    u_int32_t *spdsize)
{
	u_int32_t	v;
	ssize_t		rbytes;

	v = MONITOR_GETSNAP;
	if (m_write(m_state.s, &v, sizeof v) < 1)
		return -1;

	/* Read SADB data. */
	*sadb = *spd = NULL;
	*spdsize = 0;
	if (m_read(m_state.s, sadbsize, sizeof *sadbsize) < 1)
		return -1;
	if (*sadbsize) {
		*sadb = (u_int8_t *)malloc(*sadbsize);
		if (!*sadb) {
			log_err("monitor_get_pfkey_snap: malloc()");
			monitor_drain_input();
			return -1;
		}
		rbytes = m_read(m_state.s, *sadb, *sadbsize);
		if (rbytes < 1) {
			memset(*sadb, 0, *sadbsize);
			free(*sadb);
			return -1;
		}
	}

	/* Read SPD data */
	if (m_read(m_state.s, spdsize, sizeof *spdsize) < 1) {
		if (*sadbsize) {
			memset(*sadb, 0, *sadbsize);
			free(*sadb);
		}
		return -1;
	}
	if (*spdsize) {
		*spd = (u_int8_t *)malloc(*spdsize);
		if (!*spd) {
			log_err("monitor_get_pfkey_snap: malloc()");
			monitor_drain_input();
			if (*sadbsize) {
				memset(*sadb, 0, *sadbsize);
				free(*sadb);
			}
			return -1;
		}
		rbytes = m_read(m_state.s, *spd, *spdsize);
		if (rbytes < 1) {
			memset(*spd, 0, *spdsize);
			free(*spd);
			if (*sadbsize) {
				memset(*sadb, 0, *sadbsize);
				free(*sadb);
			}
			return -1;
		}
	}

	log_msg(2, "monitor_get_pfkey_snap: got %u bytes SADB, %u bytes SPD",
	    *sadbsize, *spdsize);
	return 0;
}
 edge_stream_iterator operator++(int)  {
   edge_stream_iterator tmp = *this;
   m_read();
   return tmp;
 }
示例#5
0
/* We only use privsep to get in-kernel SADB and SPD snapshots via sysctl */
void
monitor_loop(void)
{
	u_int32_t	 v, vn;
	ssize_t		 r;
	fd_set		 rfds;
	int		 ret;
	struct timeval	*tvp, tv;

	FD_ZERO(&rfds);
	tvp = NULL;
	vn = 0;

	for (;;) {
		ret = 0;
		v = 0;

		if (sigchld) {
			pid_t	pid;
			int	status;
			do {
				pid = waitpid(m_state.pid, &status, WNOHANG);
			} while (pid == -1 && errno == EINTR);

			if (pid == m_state.pid &&
			    (WIFEXITED(status) || WIFSIGNALED(status)))
				break;
		}

		FD_SET(m_state.s, &rfds);
		if (select(m_state.s + 1, &rfds, NULL, NULL, tvp) == -1) {
			if (errno == EINTR || errno == EAGAIN)
				continue;
			log_err(0, "monitor_loop: select() ");
			break;
		}

		/* Wait for next task */
		if (FD_ISSET(m_state.s, &rfds)) {
			if ((r = m_read(m_state.s, &v, sizeof v)) < 1) {
				if (r == -1)
					log_err(0, "monitor_loop: read() ");
				break;
			}
		}

		/* Retry after timeout */
		if (v == 0 && tvp != NULL) {
			v = vn;
			tvp = NULL;
			vn = 0;
		}

		switch (v) {
		case MONITOR_GETSNAP:
			/* Get the data. */
			m_priv_pfkey_snap(m_state.s);
			break;
		case MONITOR_CARPINC:
			carp_demote(CARP_INC, 1);
			break;
		case MONITOR_CARPDEC:
			carp_demote(CARP_DEC, 1);
			break;
		case MONITOR_CONTROL_ACTIVATE:
			ret = m_priv_control_activate();
			break;
		case MONITOR_CONTROL_PASSIVATE:
			ret = m_priv_control_passivate();
			break;
		}

		if (ret == -1) {
			/* Trigger retry after timeout */
			tv.tv_sec = MONITOR_RETRY_TIMEOUT;
			tv.tv_usec = 0;
			tvp = &tv;
			vn = v;
		}
	}

	monitor_carpundemote(NULL);

	if (!sigchld)
		log_msg(0, "monitor_loop: priv process exiting abnormally");
	exit(0);
}
示例#6
0
	Enumeration_input_iterator operator++(int)
	{
		Enumeration_input_iterator tmp = *this;
		m_read();
		return tmp;
	}
示例#7
0
	Enumeration_input_iterator& operator++()
	{
		m_read();
		return *this;
	}
示例#8
0
	Enumeration_input_iterator(enumeration_type& e) : m_enumeration(&e)
	{
		m_read();
	}
示例#9
0
static choose_handler_t choose_board_handler(choose_t *cp, int ch)
{
	choose_board_t *cbrd = cp->data;
	board_data_t *ptr;
	char ans[2];
	bool modify_mode = false;

	switch (ch) {
		case '*':
			if (cbrd->brds[cp->cur].flag & BOARD_CUSTOM_FLAG)
				return DONOTHING;
			ptr = cbrd->brds + cp->cur;
			show_board_info(ptr->name);
			return FULLUPDATE;
		case 'C':
			return tui_goodbrd_copy(cp);
		case 'c':
			cbrd->newflag = !cbrd->newflag;
			return PARTUPDATE;
		case 'L':
			m_read();
			cp->valid = false;
			modify_mode = true;
			break;
		case 'M':
			m_new();
			cp->valid = false;
			modify_mode = true;
			break;
		case 'u':
			modify_user_mode(QUERY);
			t_query();
			modify_mode = true;
			break;
		case 'H':
			getdata(t_lines - 1, 0, "您选择? (1) 本日十大  (2) 系统热点 [1]",
					ans, 2, DOECHO, YEA);
			if (ans[0] == '2')
				show_help("etc/hotspot");
			else
				show_help("0Announce/bbslist/day");
			break;
		case 'l':
			msg_more();
			modify_mode = true;
			break;
		case 'P':
			return tui_goodbrd_paste(cp);
		case '!':
			save_zapbuf(cbrd);
			free(cbrd->brds);
			free(cbrd->gbrds);
			Goodbye();
			return -1;
		case 'h':
			show_help("help/boardreadhelp");
			break;
		case '/':
			// TODO: search.
			break;
		case 's':
			if (currentuser.flags[0] & BRDSORT_FLAG) {
				currentuser.flags[0] ^= BRDSORT_FLAG;
				currentuser.flags[0] |= BRDSORT_ONLINE;
				cbrd->cmp = board_cmp_online;
			} else if (currentuser.flags[0] & BRDSORT_ONLINE) {
				currentuser.flags[0] ^= BRDSORT_ONLINE;
				cbrd->cmp = board_cmp_default;
			} else {
				currentuser.flags[0] |= BRDSORT_FLAG;
				cbrd->cmp = board_cmp_flag;
			}
			qsort(cbrd->brds, cbrd->num, sizeof(*cbrd->brds), cbrd->cmp);
			substitut_record(PASSFILE, &currentuser,
					sizeof(currentuser), usernum);
			return PARTUPDATE;
		case 'y':
			if (cbrd->gnum)
				return DONOTHING;
			cbrd->yank = !cbrd->yank;
			cp->valid = false;
			return PARTUPDATE;
		case 'z':
			if (cbrd->gnum)
				return DONOTHING;
			if (HAS_PERM(PERM_LOGIN)
					&& !(cbrd->brds[cp->cur].flag & BOARD_NOZAP_FLAG)) {
				ptr = cbrd->brds + cp->cur;
				ptr->zap = !ptr->zap;
				ptr->total = -1;
				cbrd->zapbuf[ptr->pos] = (ptr->zap ? 0 : login_start_time);
			}
			cp->valid = false;
			return PARTUPDATE;
		case 'a':
			return tui_goodbrd_add(cp);
		case 'A':
			return tui_goodbrd_mkdir(cp);
		case 'T':
			return tui_goodbrd_rename(cp);
		case 'd':
			return tui_goodbrd_rm(cp);
		case '\r':
		case '\n':
		case KEY_RIGHT:
			if (cbrd->num > 0)
				choose_board_read(cp);
			cp->valid = false;
			modify_mode = true;
			break;
		case 'S':
			if (!HAS_PERM(PERM_TALK))
				return DONOTHING;
			s_msg();
			modify_mode = true;
			break;
		case 'o':
			if (!HAS_PERM(PERM_LOGIN))
				return DONOTHING;
			online_users_show_override();
			modify_mode = true;
			break;
		default:
			return DONOTHING;
	}
	if (modify_mode)
		modify_user_mode(cbrd->newflag ? READNEW : READBRD);
	return FULLUPDATE;
}