Browse Source

Unicness to a Mojo process added

AGP
Evgeny Gagua 2 years ago
parent
commit
69acb356f9
  1. 9
      Projects/watchDogDaemon/kernel.cpp
  2. 18
      lib/App/mojo/mojoBackend.cpp
  3. 23
      lib/App/mojo/mojoKernel.cpp
  4. 56
      lib/components/base/basicFunctionality.cpp
  5. 3
      lib/components/base/basicFunctionality.h

9
Projects/watchDogDaemon/kernel.cpp

@ -239,7 +239,14 @@ void *SP_KERNEL::sw_proc( void *ptr ){
//sprintf( jB, "Server: I recieved [%d] %s from client!", retVal, tB );
//mR->master->m_pLog->Log( "K_T", mR->master, jB );
if( CPID ){
uint64_t nMS = atoll(tB);
int64_t nMS = atoll(tB);
//Stop WD and exit
if ( nMS < 0 ) {
shutdown( mR->client_socket, 2 );
close( mR->client_socket );
mR->client_socket = -1;
break;
};
//sprintf( jB, "Will Wait next [%d] milliseconds", nMS );
//mR->master->m_pLog->Log( "K_T", mR->master, jB );
tMS = cMS + nMS;

18
lib/App/mojo/mojoBackend.cpp

@ -158,10 +158,20 @@ int main( int argc, char *argv[] ){
#endif
;
if( !isProcessUniq( argv[0] ) ){
printf( "The Process [%s] Already is Runing\n", argv[0] );
return 33;
};
//if( !isProcessUniq( argv[0] ) ){
if( fileExist( gsCFG_PID_FILE ) ){
FILE * fd = fopen( gsCFG_PID_FILE, "r" );
if ( fd ) {
char Kaka[64];
readLine( fd, Kaka, 64 );
pid_t tPID = ( pid_t ) atol( Kaka );
if ( kill( tPID, 0 ) == 0 ) {
printf("Can not Start!\nThe Process [%s] Already is Runing[PID:%lld]\n", argv[0], tPID );
return 33;
};
};
};
//};
// Reading Config
if( argc > 1 ){

23
lib/App/mojo/mojoKernel.cpp

@ -115,6 +115,16 @@ mojoKernel::~mojoKernel(){
// LOG( "BopBop!" );
// SLEEP(1000);
//};
#ifdef LINUX_KERNEL_WATCHDOG
LOG("Disable WD!");
if( m_iWatchdogFd > -1 ) {
char tB[64];
sprintf( tB, "-1\n" );
//ToDo: Make Error Handling here!
write( m_iWatchdogFd, &tB, strlen( tB ) );
};
LOG("WatchDog turned Off!");
#endif
_instance = NULL;
};
@ -327,22 +337,9 @@ void mojoKernel::m_fThreadProc( void ){
#ifdef LINUX_KERNEL_WATCHDOG
if( m_iWatchdogFd > -1 ) {
char tB[64];
char ttB[128];
sprintf( tB, "2000\n" );
//int ret = xioctl( m_iWatchdogFd, WDIOC_KEEPALIVE, NULL );
//if( ret < 0 ){
// char tB[200];
// sprintf( tB, "Could not pat watchdog: %s\n", strerror(errno));
// LOG_ERROR( tB );
//};
//LOG("Write WD!");
//ToDo: Make Error Handling here!
write( m_iWatchdogFd, &tB, strlen( tB ) );
//LOG("Read WD!");
//read( m_iWatchdogFd, &tB, 64 );
//LOG("Done WD!");
//sprintf( ttB, "Client: I recieved %s from server!", tB );
//LOG( ttB );
};
#endif
m_bDebugMode = m_pDBC->getAppDebugMode();

56
lib/components/base/basicFunctionality.cpp

@ -933,12 +933,68 @@ ssize_t readLine(int fd, char *buffer, size_t n) {
return totRead;
};
ssize_t readLine( FILE *fd, char *buffer, size_t n) {
ssize_t numRead; /* # of bytes fetched by last read() */
size_t totRead; /* Total bytes read so far */
char *buf;
char ch;
if (n <= 0 || buffer == NULL) {
errno = EINVAL;
return -1;
}
buf = buffer; /* No pointer arithmetic on "void *" */
totRead = 0;
for (;;) {
numRead = fread(&ch, 1, 1, fd);
if (numRead == -1) {
if (errno == EINTR) /* Interrupted --> restart read() */
continue;
else
return -1; /* Some other error */
} else if (numRead == 0) { /* EOF */
if (totRead == 0) /* No bytes read; return 0 */
return 0;
else /* Some bytes read; add '\0' */
break;
} else { /* 'numRead' must be 1 if we get here */
if (totRead < n - 1) { /* Discard > (n - 1) bytes */
totRead++;
*buf++ = ch;
}
if (ch == '\n')
break;
}
}
*buf = '\0';
return totRead;
};
localIpAddresses g_vLocalIpAdressess;
bool g_bAdressesAreDiscovered = false;
#ifdef __linux__
bool isProcessUniq( CSTR pName ){
char tB[256];
FILE *fd;
sprintf( tB, "pidof %s", pName );
fd = popen( tB, "r" );
if ( fd ) {
int rs = readLine( fd, tB, 256 );
if ( rs > 2 ) {
fclose( fd );
return false;
};
fclose( fd );
};
return true;
};

3
lib/components/base/basicFunctionality.h

@ -69,7 +69,8 @@ CSTR strReplace( CSTR orig, CSTR rep, CSTR with );
int checkCmdExists( CSTR cmd );
ssize_t readLine(int fd, char *buffer, size_t n );
ssize_t readLine( int fd, char *buffer, size_t n );
ssize_t readLine( FILE *fd, char *buffer, size_t n);
//#define EPOCH_DIFF 11644473600LL
#define UNIX_TimeStamp_2_WINDOWS_FileTime_SHIFT 116444736000000000

Loading…
Cancel
Save