コード例 #1
0
ファイル: timeout.c プロジェクト: Palantir555/ecos-mars-zx3
// ------------------------------------------------------------------------
// HANDLER THREAD ENTRY ROUTINE
// This waits on the DSR to tell it to run:
static void
alarm_thread(cyg_addrword_t param)
{
    // This is from the logical ethernet dev; it calls those delivery
    // functions who need attention.
    extern void eth_drv_run_deliveries( void );

    // This is from the logical ethernet dev; it tickles somehow
    // all ethernet devices in case one is wedged.
    extern void eth_drv_tickle_devices( void );

    while ( 1 ) {
        int spl;
        int x;
#ifdef CYGPKG_NET_FAST_THREAD_TICKLE_DEVS
        cyg_tick_count_t later = cyg_current_time();
        later += CYGNUM_NET_FAST_THREAD_TICKLE_DEVS_DELAY;
        x = cyg_flag_timed_wait(
            &alarm_flag,
            -1,
            CYG_FLAG_WAITMODE_OR | CYG_FLAG_WAITMODE_CLR,
            later );
#else
        x = cyg_flag_wait(
            &alarm_flag,
            -1,
            CYG_FLAG_WAITMODE_OR | CYG_FLAG_WAITMODE_CLR );

        CYG_ASSERT( 3 & x, "Lost my bits" );
#endif // CYGPKG_NET_FAST_THREAD_TICKLE_DEVS
        CYG_ASSERT( !((~3) & x), "Extra bits" );

        spl = cyg_splinternal();

        CYG_ASSERT( 0 == spl, "spl nonzero" );

        if ( 2 & x )
            eth_drv_run_deliveries();
#ifdef CYGPKG_NET_FAST_THREAD_TICKLE_DEVS
        // This is in the else clause for "do we deliver" because the
        // network stack might have continuous timing events anyway - so
        // the timeout would not occur, x would be 1 every time.
        else // Tickle the devices...
            eth_drv_tickle_devices();
#endif // CYGPKG_NET_FAST_THREAD_TICKLE_DEVS

        if ( 1 & x )
            do_timeout();

        cyg_splx(spl);
    }
}
コード例 #2
0
ファイル: sender.cpp プロジェクト: LocutusOfBorg/poedit
  void do_send()
  {
    std::ostringstream os;
    os << "Message " << message_count_++;
    message_ = os.str();

    socket_.async_send_to(
        boost::asio::buffer(message_), endpoint_,
        [this](boost::system::error_code ec, std::size_t /*length*/)
        {
          if (!ec && message_count_ < max_message_count)
            do_timeout();
        });
  }
コード例 #3
0
static void handle_timeout(isrv_state_t *state, int (*do_timeout)(void **))
{
	int n, peer;
	peer = PEER_COUNT-1;
	/* peer 0 is not checked */
	while (peer > 0) {
		DPRINTF("peer %d: time diff %d", peer,
				(int)(CURTIME - TIMEO_TBL[peer]));
		if ((CURTIME - TIMEO_TBL[peer]) >= TIMEOUT) {
			DPRINTF("peer %d: do_timeout()", peer);
			n = do_timeout(&PARAM_TBL[peer]);
			if (n)
				remove_peer(state, peer);
		}
		peer--;
	}
}
コード例 #4
0
ファイル: local.c プロジェクト: micia/dma
static int
create_mbox(const char *name)
{
	struct sigaction sa, osa;
	pid_t child, waitchild;
	int status;
	int i;
	long maxfd;
	int e;
	int r = -1;

	/*
	 * We need to enable SIGCHLD temporarily so that waitpid works.
	 */
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = SIG_DFL;
	sigaction(SIGCHLD, &sa, &osa);

	do_timeout(100, 0);

	child = fork();
	switch (child) {
	case 0:
		/* child */
		maxfd = sysconf(_SC_OPEN_MAX);
		if (maxfd == -1)
			maxfd = FOPEN_MAX;	/* what can we do... */

		for (i = 3; i <= maxfd; ++i)
			close(i);

		execl(LIBEXEC_PATH "/dma-mbox-create", "dma-mbox-create", name, NULL);
		syslog(LOG_ERR, "cannot execute "LIBEXEC_PATH"/dma-mbox-create: %m");
		exit(1);

	default:
		/* parent */
		waitchild = waitpid(child, &status, 0);

		e = errno;

		do_timeout(0, 0);

		if (waitchild == -1 && e == EINTR) {
			syslog(LOG_ERR, "hung child while creating mbox `%s': %m", name);
			break;
		}

		if (waitchild == -1) {
			syslog(LOG_ERR, "child disappeared while creating mbox `%s': %m", name);
			break;
		}

		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
			syslog(LOG_ERR, "error creating mbox `%s'", name);
			break;
		}

		/* success */
		r = 0;
		break;

	case -1:
		/* error */
		syslog(LOG_ERR, "error creating mbox");
		break;
	}

	sigaction(SIGCHLD, &osa, NULL);

	return (r);
}
コード例 #5
0
ファイル: local.c プロジェクト: micia/dma
int
deliver_local(struct qitem *it)
{
	char fn[PATH_MAX+1];
	char line[1000];
	const char *sender;
	const char *newline = "\n";
	size_t linelen;
	int tries = 0;
	int mbox;
	int error;
	int hadnl = 0;
	off_t mboxlen;
	time_t now = time(NULL);

	error = snprintf(fn, sizeof(fn), "%s/%s", _PATH_MAILDIR, it->addr);
	if (error < 0 || (size_t)error >= sizeof(fn)) {
		syslog(LOG_NOTICE, "local delivery deferred: %m");
		return (1);
	}

retry:
	/* wait for a maximum of 100s to get the lock to the file */
	do_timeout(100, 0);

	/* don't use O_CREAT here, because we might be running as the wrong user. */
	mbox = open_locked(fn, O_WRONLY|O_APPEND);
	if (mbox < 0) {
		int e = errno;

		do_timeout(0, 0);

		switch (e) {
		case EACCES:
		case ENOENT:
			/*
			 * The file does not exist or we can't access it.
			 * Call dma-mbox-create to create it and fix permissions.
			 */
			if (tries > 0 || create_mbox(it->addr) != 0) {
				syslog(LOG_ERR, "local delivery deferred: can not create `%s'", fn);
				return (1);
			}
			++tries;
			goto retry;

		case EINTR:
			syslog(LOG_NOTICE, "local delivery deferred: can not lock `%s'", fn);
			break;

		default:
			syslog(LOG_NOTICE, "local delivery deferred: can not open `%s': %m", fn);
			break;
		}
		return (1);
	}
	do_timeout(0, 0);

	mboxlen = lseek(mbox, 0, SEEK_END);

	/* New mails start with \nFrom ...., unless we're at the beginning of the mbox */
	if (mboxlen == 0)
		newline = "";

	/* If we're bouncing a message, claim it comes from MAILER-DAEMON */
	sender = it->sender;
	if (strcmp(sender, "") == 0)
		sender = "MAILER-DAEMON";

	if (fseek(it->mailf, 0, SEEK_SET) != 0) {
		syslog(LOG_NOTICE, "local delivery deferred: can not seek: %m");
		goto out;
	}

	error = snprintf(line, sizeof(line), "%sFrom %s\t%s", newline, sender, ctime(&now));
	if (error < 0 || (size_t)error >= sizeof(line)) {
		syslog(LOG_NOTICE, "local delivery deferred: can not write header: %m");
		goto out;
	}
	if (write(mbox, line, error) != error)
		goto wrerror;

	while (fgets(line, sizeof(line), it->mailf)) {
		linelen = strlen(line);
		if (linelen == 0 || line[linelen - 1] != '\n') {
			syslog(LOG_CRIT, "local delivery failed: corrupted queue file");
			snprintf(errmsg, sizeof(errmsg), "corrupted queue file");
			error = -1;
			goto chop;
		}

		/*
		 * mboxro processing:
		 * - escape lines that start with "From " with a > sign.
		 * - be reversable by escaping lines that contain an arbitrary
		 *   number of > signs, followed by "From ", i.e. />*From / in regexp.
		 * - strict mbox processing only requires escaping after empty lines,
		 *   yet most MUAs seem to relax this requirement and will treat any
		 *   line starting with "From " as the beginning of a new mail.
		 */
		if ((!MBOX_STRICT || hadnl) &&
		    strncmp(&line[strspn(line, ">")], "From ", 5) == 0) {
			const char *gt = ">";

			if (write(mbox, gt, 1) != 1)
				goto wrerror;
			hadnl = 0;
		} else if (strcmp(line, "\n") == 0) {
			hadnl = 1;
		} else {
			hadnl = 0;
		}
		if ((size_t)write(mbox, line, linelen) != linelen)
			goto wrerror;
	}
	
	if (ferror(it->mailf)) {
		syslog(LOG_ERR, "local delivery failed: I/O error while reading: %m");
		error = 1;
		goto chop;
	}
	
	close(mbox);
	return (0);

wrerror:
	syslog(LOG_ERR, "local delivery failed: write error: %m");
	error = 1;
chop:
	if (ftruncate(mbox, mboxlen) != 0)
		syslog(LOG_WARNING, "error recovering mbox `%s': %m", fn);
out:
	close(mbox);
	return (error);
}
コード例 #6
0
ファイル: chisel.cpp プロジェクト: Erethon/sysdig
bool sinsp_chisel::run(sinsp_evt* evt)
{
#ifdef HAS_LUA_CHISELS
	string line;

	ASSERT(m_ls);

	//
	// If this is the first event, put the event pointer on the stack.
	// We assume that the event pointer will never change.
	//
	if(m_lua_is_first_evt)
	{
		first_event_inits(evt);
	}

	//
	// If there is a timeout callback, see if it's time to call it
	//
	do_timeout(evt);

	//
	// If there is a filter, run it
	//
	if(m_lua_cinfo->m_filter != NULL)
	{
		if(!m_lua_cinfo->m_filter->run(evt))
		{
			return false;
		}
	}

	//
	// If the script has the on_event callback, call it
	//
	if(m_lua_has_handle_evt)
	{
		lua_getglobal(m_ls, "on_event");
			
		if(lua_pcall(m_ls, 0, 1, 0) != 0) 
		{
			throw sinsp_exception(m_filename + " chisel error: " + lua_tostring(m_ls, -1));
		}
	
		int oeres = lua_toboolean(m_ls, -1);
		lua_pop(m_ls, 1);

		if(m_lua_cinfo->m_end_capture == true)
		{
			throw sinsp_capture_interrupt_exception();
		}

		if(oeres == false)
		{
			return false;
		}
	}

	//
	// If the script has a formatter, run it
	//
	if(m_lua_cinfo->m_formatter != NULL)
	{
		if(m_lua_cinfo->m_formatter->tostring(evt, &line))
		{
			cout << line << endl;
		}
	}

	return true;
#endif
}
コード例 #7
0
ファイル: chisel.cpp プロジェクト: draios/sysdig
bool sinsp_chisel::run(sinsp_evt* evt)
{
#ifdef HAS_LUA_CHISELS
	string line;

	ASSERT(m_ls);

	//
	// Make the event available to the API
	//
	lua_pushlightuserdata(m_ls, evt);
	lua_setglobal(m_ls, "sievt");

	//
	// If there is a timeout callback, see if it's time to call it
	//
	do_timeout(evt);

	//
	// If there is a filter, run it
	//
	if(m_lua_cinfo->m_filter != NULL)
	{
		if(!m_lua_cinfo->m_filter->run(evt))
		{
			return false;
		}
	}

	//
	// If the script has the on_event callback, call it
	//
	if(m_lua_has_handle_evt)
	{
		lua_getglobal(m_ls, "on_event");

		if(lua_pcall(m_ls, 0, 1, 0) != 0)
		{
			throw sinsp_exception(m_filename + " chisel error: " + lua_tostring(m_ls, -1));
		}

		int oeres = lua_toboolean(m_ls, -1);
		lua_pop(m_ls, 1);

		if(m_lua_cinfo->m_end_capture == true)
		{
			throw sinsp_capture_interrupt_exception();
		}

		if(oeres == false)
		{
			return false;
		}
	}

	//
	// If the script has a formatter, run it
	//
	if(m_lua_cinfo->m_formatter != NULL)
	{
		if(m_lua_cinfo->m_formatter->tostring(evt, &line))
		{
			cout << line << endl;
		}
	}

	return true;
#endif
}
コード例 #8
0
ファイル: udps.c プロジェクト: dlebedev/udpsocksify
void *cleaning_connections(void* unused) {
    do_timeout();
    pthread_exit(NULL);
}
コード例 #9
0
ファイル: chisel.cpp プロジェクト: SpiderX/sysdig
bool sinsp_chisel::run(sinsp_evt* evt)
{
	uint32_t j;
	string line;

	if(!m_ls)
	{
		for(j = 0; j < m_subchisels.size(); j++)
		{
			//
			// Output the line
			//
			if(m_subchisels[j]->m_filter != NULL)
			{
				if(!m_subchisels[j]->m_filter->run(evt))
				{
					continue;
				}
			}

			if(m_subchisels[j]->m_formatter->tostring(evt, &line))
			{
				cout << line << endl;
			}
		}

		return true;
	}
	else
	{
#ifdef HAS_LUA_CHISELS
		//
		// If this is the first event, put the event pointer on the stack.
		// We assume that the event pointer will never change.
		//
		if(m_lua_is_first_evt)
		{
			lua_pushlightuserdata(m_ls, evt);
			lua_setglobal(m_ls, "sievt");

			uint64_t ts = evt->get_ts();
			if(m_lua_cinfo->m_callback_interval != 0)
			{
				m_lua_last_interval_sample_time = ts - ts % m_lua_cinfo->m_callback_interval;
			}

			m_lua_is_first_evt = false;
		}

		//
		// If there is a timeout callback, see if it's time to call it
		//
		do_timeout(evt);

		//
		// If there is a filter, run it
		//
		if(m_lua_cinfo->m_filter != NULL)
		{
			if(!m_lua_cinfo->m_filter->run(evt))
			{
				return false;
			}
		}

		//
		// If the script has the on_event callback, call it
		//
		if(m_lua_has_handle_evt)
		{
			lua_getglobal(m_ls, "on_event");
			
			if(lua_pcall(m_ls, 0, 1, 0) != 0) 
			{
				throw sinsp_exception(m_filename + " chisel error: " + lua_tostring(m_ls, -1));
			}
	
			int oeres = lua_toboolean(m_ls, -1);
			lua_pop(m_ls, 1);

			if(oeres == false)
			{
				return false;
			}
		}

		//
		// If the script has a formatter, run it
		//
		if(m_lua_cinfo->m_formatter != NULL)
		{
			if(m_lua_cinfo->m_formatter->tostring(evt, &line))
			{
				cout << line << endl;
			}
		}

		return true;
#endif
	}
}