Exemplo n.º 1
0
int CDiscoveryApp::ConfigureNetwork(IPSet_Msg &ipSet)
{	
	char IP_ethInterf[32]={0};
	char Mask_ethInterf[32]={0};
	
	in_addr ip = { ipSet.m_unIP_ethInterf} ;
	in_addr mask = { ipSet.m_unMask_ethInterf} ;
	
	memset(&IP_ethInterf, 0,sizeof(IP_ethInterf));
	memset(&Mask_ethInterf, 0,sizeof(Mask_ethInterf));
	
	strcpy( IP_ethInterf, inet_ntoa(ip));
	strcpy( Mask_ethInterf, inet_ntoa(mask));
	
	LOG( "releasing dhcp" );
	system_to( 10, "killall -USR2 udhcpc" );
	
	SetIP(m_szEthInterf, IP_ethInterf);
	SetNetmask(m_szEthInterf, Mask_ethInterf);
	SetDefaulRoute(ipSet.m_unDefaultGateway);

	LOG( "dhcp renew" );
	system_to( 10, "killall -USR1 udhcpc" );

	return 1;
}
Exemplo n.º 2
0
int main (int argc, char** argv)
{
	if (argc<3)
	{	
		printf("Usage: %s lock_file cmd_line [timeout]", argv[0] );
		return 0;
	}

	g_stLog.OpenStdout();

	int nTimeout = 600;
	if (argc>=4)
	{	
		nTimeout = atoi(argv[3]);
	}
	CFileLock oLock;

	oLock.SetFile(argv[1]);

	oLock.Lock();
	int ret = system_to(nTimeout, argv[2]);	
	oLock.Unlock();

	return ret;
}
Exemplo n.º 3
0
int ExecSimpleBash2File( const char* p_pCmd, int p_nLen, const char* p_szFile )
{
	char	szBuff[1024];

	sprintf( szBuff, "echo -e '\n$%.*s' >>%s; %.*s 1>>%s 2>>%s",
		p_nLen, p_pCmd, p_szFile, p_nLen, p_pCmd, p_szFile, p_szFile );
//	LOG("ExecBash: %s", szBuff );
	return system_to( 600, szBuff ) == 0;
}
Exemplo n.º 4
0
///////////////////////////////////////////////////////////////////////////////
// Name:	CheckDelPidFiles
// Author:	Mihai Buha ([email protected])
// Description:	removes all the pidfiles specified, but not too frequently
// Parameters:	p_pszNames - input - null-terminated array of filenames
//		p_szMissNames - output - if not null, fill with names of
//			missing files. Take care to allocate enough memory for
//			"Watchdog: <all filenames in p_pszNames> " or else bad
//			things will happen.
// Returns:	true if all pidfiles existed or timeout not expired
//		false if some pidfile was missing (controlling app was dead -
//			did not create a file during latest 2 intervals)
///////////////////////////////////////////////////////////////////////////////
bool CheckDelPidFiles (const char** p_pszNames, char* p_szMissNames)
{
	static clock_t last_checked;
	static long n_SC_CLK_TCK;
	static bool last_existed = true;
	clock_t timestamp;
	bool status = true;
	bool exists = true;
	if(!n_SC_CLK_TCK) n_SC_CLK_TCK = sysconf( _SC_CLK_TCK);

	timestamp = GetClockTicks();
	if( timestamp < last_checked){ // large uptime overflowed the clock_t
		last_checked = timestamp;
	}
	if( timestamp - last_checked < PIDFILES_FACTOR * PIDFILES_TIMEOUT * n_SC_CLK_TCK){
		return status;
	}
	last_checked = timestamp;
	int i;
	for( i=0; p_pszNames[i]; ++i)
	{
		int nFileLen = GetFileLen(p_pszNames[i]);
		if ( nFileLen > 0)
		{	unlink( p_pszNames[i]);
			continue;
		}
		if (nFileLen == 0)
		{	LOG("CheckDelPidFiles: file %s len==0",  p_pszNames[i]);
			unlink( p_pszNames[i]);
		}

		LOG_ERR( "CheckDelPidFiles: pidfile %s missing!", p_pszNames[i]);
		if( exists && p_szMissNames){
			sprintf( p_szMissNames, "Watchdog: ");
		}
		exists = false;
		if( p_szMissNames){
			strcat( p_szMissNames, p_pszNames[i]);
			strcat( p_szMissNames, " ");
		}
		system_to( 60, NIVIS_TMP"take_system_snapshot.sh "ACTIVITY_DATA_PATH"snapshot_warning.txt &");

	}
	status = exists || last_existed;
	last_existed = exists;
	return status;
}
//////////////////////////////////////////////////////////////////////////////
/// @brief removes all the pidfiles specified, but not too frequently
/// @author	Mihai Buha ([email protected])
/// @param[in]	p_pszNames null-terminated array of filenames
/// @param[out]	p_szMissNames if not null, fill with names of
///			missing files. Take care to allocate enough memory for
///			"Watchdog: <all filenames in p_pszNames> " or else bad
///			things will happen.
/// @retval true  All pidfiles existed or timeout not expired
/// @retval false Some pidfile was missing (controlling app was dead -
///			did not create a file during latest 2 intervals)
//////////////////////////////////////////////////////////////////////////////
bool CWatchdogMngr::checkDelPidFiles (const char** p_pszNames, char* p_szMissNames)
{
	clock_t timestamp ;
	static clock_t sStartTime = GetClockTicks();
	static clock_t last_checked;
	static bool last_existed = true;
	bool status = true;
	bool exists = true;

	timestamp = GetClockTicks();
	if( timestamp < last_checked)
	{ // large uptime overflowed the clock_t
		last_checked = timestamp;
		sStartTime = timestamp;
	}
	if( (timestamp - last_checked < WTD_PID_VRFY_INTERVAL * sysconf(_SC_CLK_TCK)) 
		|| (timestamp - sStartTime < WTD_PID_VRFY_INTERVAL * sysconf(_SC_CLK_TCK))
		)
	{
		return true;
	}

	last_checked = timestamp;
	for( unsigned i=0; p_pszNames[i]; ++i)
	{
		int nFileLen = GetFileLen(p_pszNames[i]);

		if (nFileLen == 0)
		{	
			usleep(30*1000);//wait a little maybe in process of writing the pid file
			nFileLen = GetFileLen(p_pszNames[i]);
		}

		if ( nFileLen > 0)
		{	unlink( p_pszNames[i]);
			continue;
		}
		if (nFileLen == 0)
		{	
			ERR("checkDelPidFiles: pidfile[%s] len==0",  p_pszNames[i]);
			systemf_to( 20 ,"log2flash 'WTD: ERR:checkDelPidFiles: pidfile[%s] len==0' &",  p_pszNames[i]);
			unlink( p_pszNames[i]);			
		}

		LOG( "ERR:Missing [%s]", p_pszNames[i]);

		if ( exists )
		{
			exists = false;
		}

		if( p_szMissNames )
		{
			strcat( p_szMissNames, p_pszNames[i]);
			strcat( p_szMissNames, ",");
		}
	}
	// Take snapshot if any of the pidfiles is missing.
	if (! exists)
	{
		system_to( 60, NIVIS_TMP"take_system_snapshot.sh "ACTIVITY_DATA_PATH"snapshot_warning.txt &");
	}

	status = exists || last_existed;
	last_existed = exists;
	return status;
}