<commit_before>/* 
  This file implements the Starter class, used by the startd to keep
  track of a resource's starter process.  

  Written 10/6/97 by <NAME> <<EMAIL>>
*/

#include "startd.h"
static char *_FileName_ = __FILE__;


Starter::Starter()
{
	s_pid = -1;
	s_name = NULL;
}


Starter::~Starter()
{
	free( s_name );
}


void
Starter::setname( char* name )
{
	if( s_name ) {
		free( s_name );
	}
	s_name = strdup( name );
}


int
Starter::kill( int signo )
{
	dprintf( D_FULLDEBUG, "In Starter::kill() with pid %d, signo %d\n", 
			 s_pid, signo);

	return this->reallykill( signo, 0 );
}


int
Starter::killpg( int signo )
{
	dprintf( D_FULLDEBUG, "In Starter::killpg() with pid %d, signo %d\n", 
			 s_pid, signo);
	return this->reallykill( signo, 1 );
}


int
Starter::reallykill( int signo, int pg )
{
	struct stat st;
	int 		ret = 0;
	priv_state	priv;

	if ( s_pid <= 0 ) {
		dprintf( D_ALWAYS, "Invalid pid (%d) in Starter::kill(), returning.\n",  
				 s_pid );
		return -1;
	}

	for (errno = 0; (ret = stat(s_name, &st)) < 0; errno = 0) {
		if (errno == ETIMEDOUT)
			continue;
		EXCEPT( "Starter::kill(%d): cannot stat <%s> - errno = %d\n",
				signo, s_name, errno);
	}

	priv = set_root_priv();

	if (signo != SIGSTOP && signo != SIGCONT) {
		if( pg ) {
			ret = ::kill( -(s_pid), SIGCONT );
		} else {
			ret = ::kill( (s_pid), SIGCONT );
		}
	}
	if( pg ) {
		ret = ::kill( -(s_pid), signo );
	} else {
		ret = ::kill( (s_pid), signo );
	}

	set_priv(priv);

	if( ret < 0 ) {
		dprintf( D_ALWAYS, "Error sending signal to starter, errno = %d\n", 
				 errno );
		return -1;
	}
}


int 
Starter::spawn( start_info_t* info )
{
	s_pid = exec_starter( s_name, info->ji_hname, 
						  info->ji_sock1,
						  info->ji_sock2 );

	if( s_pid < 0 ) {
		dprintf( D_ALWAYS, "ERROR: exec_starter returned %d\n", s_pid );
		s_pid = -1;
	} else {

	}
	return s_pid;
}


void
Starter::exited()
{
	s_pid = -1;
	free( s_name );
	s_name = NULL;

	cleanup_execute_dir();
}


int
exec_starter(char* starter, char* hostname, int main_sock, int err_sock)
{
	int i;
	int pid;
	int n_fds = getdtablesize();
	int omask;
	ELEM tmp;
	sigset_t set;

	/*
	  omask = sigblock(sigmask(SIGTSTP));
	  */
#if defined(Solaris)
	if (sigprocmask(SIG_SETMASK,0,&set)  == -1)
		{EXCEPT("Error in reading procmask, errno = %d\n", errno);}
	for (i=0; i < MAXSIG; i++) block_signal(i);
#else
	omask = sigblock(-1);
#endif
	if ((pid = fork()) < 0) {
		EXCEPT( "fork" );
	}

	if (pid) {	/* The parent */
		/*
		  (void)sigblock(omask);
		  */
#if defined(Solaris)
		if ( sigprocmask(SIG_SETMASK, &set, 0)  == -1 )
			{EXCEPT("Error in setting procmask, errno = %d\n", errno);}
#else
		(void)sigsetmask(omask);
#endif<commit_msg>Cleaned up a few things that -Wall found, and some minor changes for Condor Coding Style(tm).<commit_after>/* 
  This file implements the Starter class, used by the startd to keep
  track of a resource's starter process.  

  Written 10/6/97 by <NAME> <<EMAIL>>
*/

#include "startd.h"
static char *_FileName_ = __FILE__;


Starter::Starter()
{
	s_pid = -1;
	s_name = NULL;
}


Starter::~Starter()
{
	free( s_name );
}


void
Starter::setname( char* name )
{
	if( s_name ) {
		free( s_name );
	}
	s_name = strdup( name );
}


int
Starter::kill( int signo )
{
	dprintf( D_FULLDEBUG, "In Starter::kill() with pid %d, signo %d\n", 
			 s_pid, signo);

	return this->reallykill( signo, 0 );
}


int
Starter::killpg( int signo )
{
	dprintf( D_FULLDEBUG, "In Starter::killpg() with pid %d, signo %d\n", 
			 s_pid, signo);
	return this->reallykill( signo, 1 );
}


int
Starter::reallykill( int signo, int pg )
{
	struct stat st;
	int 		ret = 0;
	priv_state	priv;

	if ( s_pid <= 0 ) {
		dprintf( D_ALWAYS, "Invalid pid (%d) in Starter::kill(), returning.\n",  
				 s_pid );
		return -1;
	}

	for (errno = 0; (ret = stat(s_name, &st)) < 0; errno = 0) {
		if (errno == ETIMEDOUT)
			continue;
		EXCEPT( "Starter::kill(%d): cannot stat <%s> - errno = %d\n",
				signo, s_name, errno);
	}

	priv = set_root_priv();

	if (signo != SIGSTOP && signo != SIGCONT) {
		if( pg ) {
			ret = ::kill( -(s_pid), SIGCONT );
		} else {
			ret = ::kill( (s_pid), SIGCONT );
		}
	}
	if( pg ) {
		ret = ::kill( -(s_pid), signo );
	} else {
		ret = ::kill( (s_pid), signo );
	}

	set_priv(priv);

	if( ret < 0 ) {
		dprintf( D_ALWAYS, "Error sending signal to starter, errno = %d\n", 
				 errno );
		return -1;
	}
	return ret;
}


int 
Starter::spawn( start_info_t* info )
{
	s_pid = exec_starter( s_name, info->ji_hname, 
						  info->ji_sock1,
						  info->ji_sock2 );

	if( s_pid < 0 ) {
		dprintf( D_ALWAYS, "ERROR: exec_starter returned %d\n", s_pid );
		s_pid = -1;
	} else {

	}
	return s_pid;
}


void
Starter::exited()
{
	s_pid = -1;
	free( s_name );
	s_name = NULL;

	cleanup_execute_dir();
}


int
exec_starter(char* starter, char* hostname, int main_sock, int err_sock)
{
	int i;
	int pid;
	int n_fds = getdtablesize();

#if defined(Solaris)
	sigset_t set;
	if( sigprocmask(SIG_SETMASK,0,&set)  == -1 ) {
		EXCEPT("Error in reading procmask, errno = %d\n", errno);
	}
	for (i=0; i < MAXSIG; i++) {
		block_signal(i);
	}
#else
	int omask = sigblock(-1);
#endif

	if( (pid = fork()) < 0 ) {
		EXCEPT( "fork" );
	}

	if (pid) {	/* The parent */
		/*
		  (void)sigblock(omask);
		  */
#if defined(Solaris)
		if ( sigprocmask(SIG_SETMASK, &set, 0)  == -1 )
			{EXCEPT("Error in setting procmask, errno = %d\n", errno);}
#else
		(void)sigsetmask(omask);
#endif
{'fraction_non_alphanumeric': 0.17327459618208516, 'fraction_numerical': 0.010279001468428781, 'mean_word_length': 3.1818879508825786, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3805687', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2299, 'n_words': 595}