library/src/blockclass/BP-BlockClass.cc
// Uses fork() to set a process exit timeout
Uses fork() to set a process exit timeout
Uses fork () to set a process exit timeout
BP_ERROR_T Block::setProcessExecutionTimeout(size_t timeout_secs)
{
	sigset_t mask;
	sigset_t orig_mask;
	struct timespec timeout;
	pid_t pid;
	sigemptyset (&mask);
	sigaddset (&mask, SIGCHLD);
	if (sigprocmask(SIG_BLOCK, &mask, &orig_mask) < 0)
	{
		perror ("sigprocmask");
		return ERR_SUCCESS;
	}
	pid = fork ();
	if(pid == 0)
		return ERR_SUCCESS;
	timeout.tv_sec = timeout_secs;
	timeout.tv_nsec = 0;
	do
	{
		if (sigtimedwait(&mask, NULL, &timeout) < 0)
		{
			if (errno == EINTR)
			{
				continue;
			}
			else if (errno == EAGAIN)
			{
				printf ("Timeout, killing child\n");
				kill (pid, SIGKILL);
				return ERR_FAILURE;
			}
			else
			{
				perror ("sigtimedwait");
				return ERR_SUCCESS;
			}
		}
		break;
	} while (1);
	if (waitpid(pid, NULL, 0) < 0)
	{
		perror ("waitpid");
		return ERR_FAILURE;
	}
	return ERR_FAILURE;
}
BP_ERROR_T Block :: setProcessExecutionTimeout ( size_t timeout_secs ) { sigset_t mask ; sigset_t orig_mask ; struct timespec timeout ; pid_t pid ; sigemptyset ( & mask ) ; sigaddset ( & mask , SIGCHLD ) ; if ( sigprocmask ( SIG_BLOCK , & mask , & orig_mask ) < 0 ) { perror ( " " ) ; return ERR_SUCCESS ; } pid = fork ( ) ; if ( pid == 0 ) return ERR_SUCCESS ; timeout . tv_sec = timeout_secs ; timeout . tv_nsec = 0 ; do { if ( sigtimedwait ( & mask , NULL , & timeout ) < 0 ) { if ( errno == EINTR ) { continue ; } else if ( errno == EAGAIN ) { printf ( " \n " ) ; kill ( pid , SIGKILL ) ; return ERR_FAILURE ; } else { perror ( " " ) ; return ERR_SUCCESS ; } } break ; } while ( 1 ) ; if ( waitpid ( pid , NULL , 0 ) < 0 ) { perror ( " " ) ; return ERR_FAILURE ; } return ERR_FAILURE ; }
Uses fork() to set a process exit timeout
Uses fork () to set a process exit timeout
// DEV NOTE: Don't use CRITICAL SECTIONS IN THIS METHOD // set mask // set the process mask // fork here // exit here if we're the child // set timeout in seconds // perform wait loop /* Interrupted by a signal other than SIGCHLD. */ // wait on the pid // return indicating failure