示例#1
0
文件: a-lib.c 项目: kjanz1899/ren-c
//
//  RL_Escape: C
// 
// Signal that code evaluation needs to be interrupted.
// 
// Returns:
//     nothing
// Arguments:
//     reserved - must be set to zero.
// Notes:
//     This function set's a signal that is checked during evaluation
//     and will cause the interpreter to begin processing an escape
//     trap. Note that control must be passed back to REBOL for the
//     signal to be recognized and handled.
//
RL_API void RL_Escape(REBINT reserved)
{
    // How should HALT vs. BREAKPOINT be decided?  When does a Ctrl-C want
    // to quit entirely vs. begin an interactive debugging session?
    //
    // !!! For now default to halting, but use SIG_INTERRUPT when a decision
    // is made about how to debug break.
    //
    SET_SIGNAL(SIG_HALT);
}
示例#2
0
void Yodar_4028B::EndHandleThread()
{
	m_bRun = FALSE;
	if(m_handleThread != 0)
	{
		LOCK_MUTEX(&m_handleMutex);
		SET_SIGNAL(m_handleCond);
		UNLOCK_MUTEX(&m_handleMutex);
		WAIT_THREAD_EXIT(m_handleThread);
		m_handleThread = 0;
	}
}
示例#3
0
void Yodar_4028B::AddData(int nComId, void *pBuf, int nLen)
{
	int nCopyLen = nLen > (MAX_DATA_LENGTH - 1) ? (MAX_DATA_LENGTH - 1) : nLen;
	memcpy((char *) m_data[m_nWriteIndex].data, pBuf, nCopyLen);
	m_data[m_nWriteIndex].len = nCopyLen;
	m_data[m_nWriteIndex].index = nComId;
	
	m_nWriteIndex++;
	m_nWriteIndex = m_nWriteIndex >= MAX_DATA_COUNT  ? 0 : m_nWriteIndex;
	
	LOCK_MUTEX(&m_handleMutex);
	SET_SIGNAL(m_handleCond);
	UNLOCK_MUTEX(&m_handleMutex);
}
示例#4
0
文件: t-gob.c 项目: xqlab/r3
*/  REBGOB *Make_Gob(void)
/*
**      Allocate a new GOB.
**
***********************************************************************/
{
    REBGOB *gob = Make_Node(GOB_POOL);
    CLEAR(gob, sizeof(REBGOB));
    GOB_W(gob) = 100;
    GOB_H(gob) = 100;
    USE_GOB(gob);
    if ((GC_Ballast -= Mem_Pools[GOB_POOL].wide) <= 0) SET_SIGNAL(SIG_RECYCLE);
    return gob;
}
示例#5
0
文件: a-lib.c 项目: asampal/ren-c
*/	RL_API void RL_Escape(REBINT reserved)
/*
**	Signal that code evaluation needs to be interrupted.
**
**	Returns:
**		nothing
**	Arguments:
**		reserved - must be set to zero.
**	Notes:
**		This function set's a signal that is checked during evaluation
**		and will cause the interpreter to begin processing an escape
**		trap. Note that control must be passed back to REBOL for the
**		signal to be recognized and handled.
**
***********************************************************************/
{
	SET_SIGNAL(SIG_ESCAPE);
}
示例#6
0
文件: signals.c 项目: shurizzle/bbot
int
get_signal (message * msg, ircserver * srv)
{
    if (IS_NUM (cmd[0]) && IS_NUM (cmd[1]) && IS_NUM (cmd[2]))
        return atoi (cmd);
    SET_OWN_SIGNAL (JOIN_OWN, msg->source->nick);
    SET_OWN_SIGNAL (KILL_OWN, prm[0]);
    SET_OWN_SIGNAL (KICK_OWN, prm[1]);
    SET_SIGNAL (PING);
    SET_SIGNAL (JOIN);
    SET_SIGNAL (KILL);
    SET_SIGNAL (MODE);
    SET_SIGNAL (KICK);
    SET_SIGNAL (ERROR);
    SET_SIGNAL (NOTICE);
    SET_OTH_SIGNAL (QUERY, IS ("PRIVMSG") && AMI (prm[0]));
    SET_OTH_SIGNAL (MESSAGE, IS ("PRIVMSG"));
    return 0;
}
示例#7
0
void daemonize() { /* {{{ */
    int pid;
    int i;
    int lfp;
    char pidstr[15];
    struct sigaction sa;

    if(1 == getppid()) return; /* already a daemon */

    /* Fork */
    pid = fork();
    switch(pid) {
        case -1 : exit(EXIT_FAILURE);
        case 0: break; /* child */
        default: _exit(EXIT_SUCCESS);
    }
    /* Obtain a new process group */
    setsid();

    /* Fork again (ignore sigup) */
    signal(SIGHUP,SIG_IGN);
    pid = fork();
    switch(pid) {
        case -1 : exit(EXIT_FAILURE);
        case 0: break; /* child */
        default: _exit(EXIT_SUCCESS);
    }

    /* Descriptors : close all and reopen standard ones on /dev/null */
    for (i=getdtablesize();i>=0;--i) close(i);
    if (open("/dev/null",O_RDONLY) == -1) {
        L (LOGLEVEL_CRITICAL, "failed to reopen stdin while daemonizing (errno=%d)",errno);
        exit(EXIT_FAILURE);
    }
    if (open("/dev/null",O_WRONLY) == -1) {
        L (LOGLEVEL_CRITICAL, "failed to reopen stdout while daemonizing (errno=%d)",errno);
        exit(EXIT_FAILURE);
    }
    if (open("/dev/null",O_RDWR) == -1) {
        L (LOGLEVEL_CRITICAL, "failed to reopen stderr while daemonizing (errno=%d)",errno);
        exit(EXIT_FAILURE);
    }

    /* Set working directory and umask */
    chdir(global_config.daemon__working_dir);
    umask(global_config.daemon__umask);

    lfp=open(PACKAGE_NAME ".pid",O_RDWR|O_CREAT,0640);
    if (lfp < 0) {
        L (LOGLEVEL_CRITICAL, "Could not open '%s/" PACKAGE_NAME ".pid'. Either this file is locked or " PACKAGE_NAME " is already running ? (%d)",global_config.daemon__working_dir,errno);
        exit(EXIT_FAILURE);
    }
    if (lockf(lfp,F_TLOCK,0) < 0) {
        L (LOGLEVEL_CRITICAL, "Could not lock '%s/" PACKAGE_NAME ".pid'. (%d)",global_config.daemon__working_dir,errno);
        exit(EXIT_FAILURE);

    }
    /* first instance continues */
    sprintf(pidstr,"%d\n",getpid());
    write(lfp,pidstr,strlen(pidstr)); /* record pid to lockfile */

#define SET_SIGNAL_IGN(s) do {\
   sa.sa_handler=SIG_IGN; \
   sigemptyset(&sa.sa_mask); \
   sa.sa_flags = 0; \
   sigaction(s,&sa, NULL); \
} while(0)

#define SET_SIGNAL(s,sh) do {\
   memset (&sa, 0, sizeof (sa)); \
   sa.sa_sigaction=sh; \
   sigemptyset(&sa.sa_mask); \
   sa.sa_flags = SA_SIGINFO; \
   sigaction(s,&sa, NULL); \
} while(0)

    SET_SIGNAL_IGN(SIGCHLD); /* ignore child */
    SET_SIGNAL_IGN(SIGTSTP); /* ignore tty signals */
    SET_SIGNAL_IGN(SIGTTOU);
    SET_SIGNAL_IGN(SIGTTIN);
    SET_SIGNAL(SIGQUIT,signal_handler_for_watchdog_stop); /* catch hangup signal */
    SET_SIGNAL(SIGINT,signal_handler_for_watchdog_stop); /* catch hangup signal */
    SET_SIGNAL(SIGHUP,signal_handler_for_watchdog_stop); /* catch hangup signal */
    SET_SIGNAL(SIGTERM,signal_handler_for_watchdog_stop); /* catch kill signal */
    } /* }}} daemonize */
示例#8
0
文件: p-event.c 项目: mbk/ren-c
*/	static REB_R Event_Actor(struct Reb_Call *call_, REBSER *port, REBCNT action)
/*
**		Internal port handler for events.
**
***********************************************************************/
{
	REBVAL *spec;
	REBVAL *state;
	REB_R result;
	REBVAL *arg;
	REBVAL save_port;

	Validate_Port(port, action);

	arg = D_ARG(2);
	*D_OUT = *D_ARG(1);

	// Validate and fetch relevant PORT fields:
	state = BLK_SKIP(port, STD_PORT_STATE);
	spec  = BLK_SKIP(port, STD_PORT_SPEC);
	if (!IS_OBJECT(spec)) Trap1_DEAD_END(RE_INVALID_SPEC, spec);

	// Get or setup internal state data:
	if (!IS_BLOCK(state)) Set_Block(state, Make_Block(EVENTS_CHUNK - 1));

	switch (action) {

	case A_UPDATE:
		return R_NONE;

	// Normal block actions done on events:
	case A_POKE:
		if (!IS_EVENT(D_ARG(3))) Trap_Arg_DEAD_END(D_ARG(3));
		goto act_blk;
	case A_INSERT:
	case A_APPEND:
	//case A_PATH:		// not allowed: port/foo is port object field access
	//case A_PATH_SET:	// not allowed: above
		if (!IS_EVENT(arg)) Trap_Arg_DEAD_END(arg);
	case A_PICK:
act_blk:
		save_port = *D_ARG(1); // save for return
		*D_ARG(1) = *state;
		result = T_Block(call_, action);
		SET_SIGNAL(SIG_EVENT_PORT);
		if (action == A_INSERT || action == A_APPEND || action == A_REMOVE) {
			*D_OUT = save_port;
			break;
		}
		return result; // return condition

	case A_CLEAR:
		VAL_TAIL(state) = 0;
		VAL_BLK_TERM(state);
		CLR_SIGNAL(SIG_EVENT_PORT);
		break;

	case A_LENGTHQ:
		SET_INTEGER(D_OUT, VAL_TAIL(state));
		break;

	case A_OPEN:
		if (!req) { //!!!
			req = OS_MAKE_DEVREQ(RDI_EVENT);
			if (req) {
				SET_OPEN(req);
				OS_DO_DEVICE(req, RDC_CONNECT);		// stays queued
			}
		}
		break;

	case A_CLOSE:
		OS_ABORT_DEVICE(req);
		OS_DO_DEVICE(req, RDC_CLOSE);
		// free req!!!
		SET_CLOSED(req);
		req = 0;
		break;

	case A_FIND: // add it

	default:
		Trap_Action_DEAD_END(REB_PORT, action);
	}

	return R_OUT;
}
示例#9
0
CSignal::TSignalMask CSignal::Reset(void)
{
    TSignalMask old = s_SignalMask;
    s_SignalMask = 0;

    SET_SIGNAL(SIGHUP,  SIG_DFL);
    SET_SIGNAL(SIGINT,  SIG_DFL);
    SET_SIGNAL(SIGBREAK,SIG_DFL);
    SET_SIGNAL(SIGILL,  SIG_DFL);
    SET_SIGNAL(SIGFPE,  SIG_DFL);
    SET_SIGNAL(SIGABRT, SIG_DFL);
    SET_SIGNAL(SIGSEGV, SIG_DFL);
    SET_SIGNAL(SIGPIPE, SIG_DFL);
    SET_SIGNAL(SIGTERM, SIG_DFL);
    SET_SIGNAL(SIGUSR1, SIG_DFL);
    SET_SIGNAL(SIGUSR2, SIG_DFL);

    return old;
}
示例#10
0
void intr_plat_i2c(uint8_t level) {
//PINA = 0x10;
	(void)level;
	SET_SIGNAL(PLAT_I2C);
}
示例#11
0
void intr_plat_button(uint8_t level) {
//PINA = 0x20;
	(void)level;
	SET_SIGNAL(PLAT_BUTTON);
}