28 changed files with 1222 additions and 44 deletions
-
1Linux_Workspace.vpw
-
44Projects/MEKOROT/MEKOROT_Kernel.cpp
-
0Projects/argus/build
-
6Projects/starProcDaemon/Debug/default.conf
-
9Projects/starProcDaemon/build
-
304Projects/starProcDaemon/kernel.cpp
-
29Projects/starProcDaemon/kernel.h
-
141Projects/starProcDaemon/makefile
-
317Projects/starProcDaemon/starProcDaemon.cpp
-
31Projects/starProcDaemon/starProcDaemon.h
-
247Projects/starProcDaemon/starProcDaemon.vpj
-
21lib/rgoose/rgooseHardwareManager.cpp
-
1lib/rgoose/rgooseHardwareManager.h
-
37lib/rgoose/rgooseKernel.cpp
-
1lib/rgoose/rgooseKernel.h
-
2lib/rgoose/rgooseModule.h
-
18lib/rgoose/rgooseModuleEmbedVideo.cpp
-
2lib/rgoose/rgooseModuleEmbedVideo.h
-
28lib/rgoose/rgooseModuleFactory.cpp
-
1lib/rgoose/rgooseModuleFactory.h
-
2lib/rgoose/rgooseModuleFlyHunter.cpp
-
2lib/rgoose/rgooseModuleFlyHunter.h
-
2lib/rgoose/rgooseModuleKafka.cpp
-
2lib/rgoose/rgooseModuleKafka.h
-
10lib/rgoose/rgooseModuleOnvifObserver.cpp
-
2lib/rgoose/rgooseModuleOnvifObserver.h
-
4lib/rgoose/rgooseModuleSSDP.cpp
-
2lib/rgoose/rgooseModuleSSDP.h
@ -0,0 +1,6 @@ |
|||
KERNEL : |
|||
{ |
|||
TARGET_APP_FILE = "argus"; |
|||
TARGET_PID_FILE = "/srv/samba/dr_frucht/Projects/argus/Debug/server.pid"; |
|||
TARGET_APP_PATH = "/srv/samba/dr_frucht/Projects/argus/Debug"; |
|||
}; |
|||
@ -0,0 +1,9 @@ |
|||
#! /bin/sh |
|||
|
|||
|
|||
#make clean -e "CFG=Debug" |
|||
#make -j4 -e "CFG=Debug" |
|||
|
|||
|
|||
make clean -e "CFG=Release" |
|||
make -j4 -e "CFG=Release" |
|||
@ -0,0 +1,304 @@ |
|||
#include "kernel.h"
|
|||
|
|||
#define LOG( X ) m_pLog->Log( "KERNEL", this, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "KERNEL", this, _LOG_ERROR, X )
|
|||
|
|||
SP_KERNEL *SP_KERNEL::_instance = NULL; |
|||
|
|||
SP_KERNEL *SP_KERNEL::getInstance( bool ColdStart ){ |
|||
if( _instance == NULL ) { |
|||
_instance = new SP_KERNEL(); |
|||
}; |
|||
return _instance; |
|||
}; |
|||
|
|||
SP_KERNEL::SP_KERNEL(): basicThread(){ |
|||
m_pLog = basicLogCollection::getInstance(); |
|||
m_pSettings = basicSettingsProvider::getInstance()->getSubNode( NULL, (CSTR)"KERNEL" ); |
|||
m_TargetPID = (pid_t) 0; |
|||
}; |
|||
|
|||
SP_KERNEL::~SP_KERNEL(){ |
|||
|
|||
}; |
|||
|
|||
|
|||
// https://stackoverflow.com/questions/8166415/how-to-get-the-pid-of-a-process-in-linux-in-c
|
|||
|
|||
#include <sys/param.h>
|
|||
#include <sys/user.h>
|
|||
#include <sys/sysctl.h>
|
|||
#include <stdio.h>
|
|||
#include <stdlib.h>
|
|||
|
|||
|
|||
/************************************************************************
|
|||
* |
|||
* Returns the pid of the process name which is given as the function |
|||
* argument. |
|||
* In case no process found with the given name -1 will be returned. |
|||
* |
|||
************************************************************************* / |
|||
pid_t getProcessId(const char * csProcessName){ |
|||
struct kinfo_proc * sProcesses = NULL; |
|||
struct kinfo_proc * sNewProcesses = NULL; |
|||
pid_t iCurrentPid; |
|||
int aiNames[4]; |
|||
size_t iNamesLength; |
|||
int i, iRetCode, iNumProcs; |
|||
size_t iSize = 0; |
|||
|
|||
aiNames[0] = CTL_KERN; |
|||
aiNames[1] = KERN_PROC; |
|||
aiNames[2] = KERN_PROC_ALL; |
|||
aiNames[3] = 0; |
|||
|
|||
iNamesLength = 3; |
|||
iRetCode = sysctl( aiNames, iNamesLength, NULL, &iSize, NULL, 0 ); |
|||
|
|||
/*
|
|||
* Allocate memory and populate info in the processes structure |
|||
* / |
|||
|
|||
do { |
|||
iSize += iSize / 10; |
|||
sNewProcesses = (struct kinfo_proc *) realloc( sProcesses, iSize ); |
|||
if( sNewProcesses == 0 ){ |
|||
if( sProcesses ) free(sProcesses); |
|||
errx(1, "could not reallocate memory"); |
|||
}; |
|||
sProcesses = sNewProcesses; |
|||
iRetCode = sysctl(aiNames, iNamesLength, sProcesses, &iSize, NULL, 0); |
|||
} while ( iRetCode == -1 && errno == ENOMEM ); |
|||
|
|||
iNumProcs = iSize / sizeof(struct kinfo_proc); |
|||
/*
|
|||
* Search for the given process name and return its pid. |
|||
* / |
|||
|
|||
for (i = 0; i < iNumProcs; i++) { |
|||
iCurrentPid = sProcesses[i].kp_proc.p_pid; |
|||
if( strncmp(csProcessName, sProcesses[i].kp_proc.p_comm, MAXCOMLEN) == 0 ) { |
|||
free(sProcesses); |
|||
return iCurrentPid; |
|||
} |
|||
} |
|||
|
|||
/*
|
|||
* Clean up and return -1 because the given proc name was not found |
|||
* / |
|||
|
|||
free(sProcesses); |
|||
return (-1); |
|||
} /* end of getProcessId() * /
|
|||
|
|||
|
|||
int main(int argc, char **argv) |
|||
|
|||
{ |
|||
int pid = 0; |
|||
pid = getProcessId( argv[1] ); |
|||
if( pid < 0 ){ |
|||
printf("process [%s] not found in the system\n", argv[1]); |
|||
} else { |
|||
printf("pid of [%s] is %d\n", argv[1], pid); |
|||
} |
|||
} |
|||
*/ |
|||
void SP_KERNEL::setPID( pid_t NP ){ |
|||
if( NP ) { |
|||
m_TargetPID = NP; |
|||
} else LOG_ERROR("Wrong PID settings!"); |
|||
}; |
|||
|
|||
bool SP_KERNEL::startTargetApplication( void ){ |
|||
char tBuffer[PATH_MAX]; |
|||
FILE *tfd = NULL; |
|||
if( 0 > chdir( m_pTargetEnvPath ) ) { |
|||
LOG_ERROR("Can not change path to Target Path"); |
|||
return false; |
|||
}; |
|||
tfd = popen( m_pTargetAppFile, "r"); |
|||
if( tfd == NULL ) { |
|||
LOG_ERROR("Can not start Target Application!"); |
|||
LOG_ERROR("Exiting!"); |
|||
return false; |
|||
}; |
|||
while( !feof( tfd )) { |
|||
size_t rLen; |
|||
rLen = fread( tBuffer, 1, PATH_MAX, tfd ); |
|||
if( rLen ) { |
|||
tBuffer[rLen] = (char )0; |
|||
LOG( tBuffer ); |
|||
}; |
|||
}; |
|||
pclose( tfd ); |
|||
return true; |
|||
}; |
|||
|
|||
bool SP_KERNEL::create(void){ |
|||
char tBuffer[PATH_MAX]; |
|||
if( m_pSettings != NULL ) { |
|||
config_setting_t * pSetting; |
|||
int tVal; |
|||
const char * tBuf; |
|||
LOG("Getting Settings ..."); |
|||
if( !config_setting_lookup_string( m_pSettings, "TARGET_APP_PATH", &tBuf ) ){ |
|||
LOG("Target Application Path not defined - generating dummy!"); |
|||
sprintf( m_pTargetEnvPath, "TARGET_APP_DIR" ); |
|||
pSetting = config_setting_add( m_pSettings, "TARGET_APP_PATH", CONFIG_TYPE_STRING ); |
|||
config_setting_set_string( pSetting, m_pTargetEnvPath ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
basicSettingsProvider::getInstance()->validate(); |
|||
LOG_ERROR("Exiting!"); |
|||
return false; |
|||
} else { |
|||
sprintf( m_pTargetEnvPath, tBuf ); |
|||
sprintf( tBuffer, "Target Application Path From Settings: %s", tBuf ); |
|||
LOG( tBuffer ); |
|||
if( !fileExist ( m_pTargetEnvPath ) ) { |
|||
LOG_ERROR("Target Application Path Not Exists!"); |
|||
LOG_ERROR("Exiting!"); |
|||
return false; |
|||
}; |
|||
}; |
|||
if( !config_setting_lookup_string( m_pSettings, "TARGET_APP_FILE", &tBuf ) ){ |
|||
LOG("Target Application not defined - generating dummy!"); |
|||
sprintf( m_pTargetAppFile, "TARGET_APP_NAME" ); |
|||
pSetting = config_setting_add( m_pSettings, "TARGET_APP_FILE", CONFIG_TYPE_STRING ); |
|||
config_setting_set_string( pSetting, m_pTargetAppFile ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
basicSettingsProvider::getInstance()->validate(); |
|||
LOG_ERROR("Exiting!"); |
|||
return false; |
|||
} else { |
|||
sprintf( m_pTargetAppFile, "%s/%s", m_pTargetEnvPath, tBuf ); |
|||
sprintf( tBuffer, "Target Application Read From Settings: %s", tBuf ); |
|||
LOG( tBuffer ); |
|||
if( !fileExist ( m_pTargetAppFile ) ) { |
|||
LOG_ERROR("Target Application File Not Exists!"); |
|||
LOG_ERROR("Exiting!"); |
|||
return false; |
|||
}; |
|||
}; |
|||
if( !config_setting_lookup_string( m_pSettings, "TARGET_PID_FILE", &tBuf ) ){ |
|||
LOG("Target PID File not defined - generating dummy!"); |
|||
sprintf( m_pTargetPIDFile, "TARGET_FILE_PATH" ); |
|||
pSetting = config_setting_add( m_pSettings, "TARGET_PID_FILE", CONFIG_TYPE_STRING ); |
|||
config_setting_set_string( pSetting, m_pTargetPIDFile ); |
|||
basicSettingsProvider::getInstance()->compromise(); |
|||
basicSettingsProvider::getInstance()->validate(); |
|||
LOG_ERROR("Exiting!"); |
|||
return false; |
|||
} else { |
|||
sprintf( m_pTargetPIDFile, tBuf ); |
|||
sprintf( tBuffer, "Target PID File Read From Settings: %s", tBuf ); |
|||
LOG( tBuffer ); |
|||
if( !fileExist ( m_pTargetPIDFile ) ) { |
|||
LOG_ERROR("Target PID File Not Exists!"); |
|||
LOG_ERROR("Starting Target Application!"); |
|||
if( !startTargetApplication() ){ |
|||
LOG_ERROR("Can not start application!"); |
|||
return false; |
|||
}; |
|||
}; |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Failed Read Config Settings!"); |
|||
return false; |
|||
}; |
|||
FILE *fd = fopen( m_pTargetPIDFile, "r" ); |
|||
if( fd!= NULL ) { |
|||
char tCHA[64]; |
|||
size_t l = fread( tCHA, 1, 64, fd ); |
|||
fclose( fd ); |
|||
if( l > 0 ) { |
|||
tCHA[l] = (char)0; |
|||
m_TargetPID = atoi( tCHA ); |
|||
sprintf( tBuffer, "Target PID is: %d", m_TargetPID ); |
|||
LOG( tBuffer ); |
|||
}; |
|||
// check if app is alive!
|
|||
int RetVal = kill( m_TargetPID, 0 ); |
|||
if( RetVal == -1 ) { |
|||
LOG_ERROR("Target Application is DEAD!"); |
|||
switch( errno ) { |
|||
case EINVAL: |
|||
LOG_ERROR("Signal 0 is invalid!"); |
|||
return false; |
|||
break; |
|||
case EPERM: |
|||
LOG_ERROR("You Don't have permition!"); |
|||
return false; |
|||
break; |
|||
case ESRCH: |
|||
LOG_ERROR("Starting Target Application!"); |
|||
if( !startTargetApplication() ){ |
|||
LOG_ERROR("Can not start application!"); |
|||
return false; |
|||
}; |
|||
break; |
|||
}; |
|||
} else { |
|||
LOG("Application is WORKING"); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Can not read PID File!"); |
|||
return false; |
|||
}; |
|||
if( m_TargetPID ) { |
|||
return init(); |
|||
} else LOG_ERROR("Trying to start without PID is set!"); |
|||
return false; |
|||
}; |
|||
|
|||
void SP_KERNEL::WaitFinish( bool force ){ |
|||
waitThreadEnd( force ); |
|||
}; |
|||
|
|||
void SP_KERNEL::m_fThreadProc( void ){ |
|||
m_bThreadStatus = TH_WORKING; |
|||
while( m_bThreadStatus < TH_ENDED ) { |
|||
int RetVal = kill( m_TargetPID, 0 ); |
|||
if( RetVal == -1 ) { |
|||
switch( errno ) { |
|||
case EINVAL: |
|||
LOG_ERROR("Signal 0 is invalid!"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
break; |
|||
case EPERM: |
|||
LOG_ERROR("You Don't have permition!"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
break; |
|||
case ESRCH: |
|||
LOG_ERROR("Restarting Target Application!"); |
|||
if( !startTargetApplication() ){ |
|||
LOG_ERROR("Can not start application!"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
} else { |
|||
FILE *fd = fopen( m_pTargetPIDFile, "r" ); |
|||
if( fd != NULL ) { |
|||
char tCHA[256]; |
|||
size_t l = fread( tCHA, 1, 64, fd ); |
|||
fclose( fd ); |
|||
if( l > 0 ) { |
|||
tCHA[l] = (char)0; |
|||
m_TargetPID = atoi( tCHA ); |
|||
sprintf( tCHA, "New Target PID is: %d", m_TargetPID ); |
|||
LOG( tCHA ); |
|||
}; |
|||
} else { |
|||
LOG_ERROR("Can not read PID File!"); |
|||
m_bThreadStatus = TH_ENDED; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
continue; |
|||
}; |
|||
SLEEP( 333 ); // 1/3 of second
|
|||
}; |
|||
}; |
|||
|
|||
#undef LOG_ERROR
|
|||
#undef LOG
|
|||
@ -0,0 +1,29 @@ |
|||
#ifndef __START_PROC_KERNEL_HEADER__ |
|||
#define __START_PROC_KERNEL_HEADER__ |
|||
|
|||
#include "../../lib/components/base/basicThread.h" |
|||
#include "../../lib/components/base/basicSettingsProvider.h" |
|||
|
|||
class SP_KERNEL: public basicThread { |
|||
protected: |
|||
virtual void m_fThreadProc( void ); |
|||
public: |
|||
static SP_KERNEL * getInstance( bool ColdStart = true ); |
|||
bool create(void); |
|||
int getExitCause(){ return 0; }; |
|||
void WaitFinish( bool force ); |
|||
void setPID( pid_t NP ); |
|||
~SP_KERNEL(); |
|||
private: |
|||
static SP_KERNEL * _instance; |
|||
SP_KERNEL(); |
|||
basicLogCollection * m_pLog; |
|||
config_setting_t * m_pSettings; |
|||
char m_pTargetPIDFile[PATH_MAX]; |
|||
char m_pTargetAppFile[PATH_MAX]; |
|||
char m_pTargetEnvPath[PATH_MAX]; |
|||
pid_t m_TargetPID; |
|||
bool startTargetApplication( void ); |
|||
}; |
|||
|
|||
#endif |
|||
@ -0,0 +1,141 @@ |
|||
# SlickEdit generated file. Do not edit this file except in designated areas.
|
|||
|
|||
# Make command to use for dependencies
|
|||
MAKE=make |
|||
RM=rm |
|||
MKDIR=mkdir |
|||
|
|||
# -----Begin user-editable area-----
|
|||
|
|||
# -----End user-editable area-----
|
|||
|
|||
# If no configuration is specified, "Debug" will be used
|
|||
ifndef CFG |
|||
CFG=Debug |
|||
endif |
|||
|
|||
#
|
|||
# Configuration: Debug
|
|||
#
|
|||
ifeq "$(CFG)" "Debug" |
|||
OUTDIR=Debug |
|||
OUTFILE=$(OUTDIR)/starProcDaemon |
|||
CFG_INC= |
|||
CFG_LIB=-lpthread -lm -lconfig |
|||
CFG_OBJ= |
|||
COMMON_OBJ=$(OUTDIR)/basicFunctionality.o \
|
|||
$(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \
|
|||
$(OUTDIR)/basicMemoryOperation.o $(OUTDIR)/basicRing.o \
|
|||
$(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \
|
|||
$(OUTDIR)/basicThread.o $(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/objectConsoleLoggingService.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/starProcDaemon.o |
|||
OBJ=$(COMMON_OBJ) $(CFG_OBJ) |
|||
ALL_OBJ=$(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \
|
|||
$(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
|
|||
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
|
|||
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
|
|||
$(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/objectConsoleLoggingService.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/starProcDaemon.o \
|
|||
-lpthread -lm -lconfig |
|||
|
|||
COMPILE=g++ -c -O0 -g3 -ggdb -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< |
|||
LINK=g++ -O0 -g3 -ggdb -o "$(OUTFILE)" $(ALL_OBJ) |
|||
|
|||
# Pattern rules
|
|||
$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : %.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp |
|||
$(COMPILE) |
|||
|
|||
# Build rules
|
|||
all: $(OUTFILE) |
|||
|
|||
$(OUTFILE): $(OUTDIR) $(OBJ) |
|||
$(LINK) |
|||
|
|||
$(OUTDIR): |
|||
$(MKDIR) -p "$(OUTDIR)" |
|||
|
|||
# Rebuild this project
|
|||
rebuild: cleanall all |
|||
|
|||
# Clean this project
|
|||
clean: |
|||
$(RM) -f $(OUTFILE) |
|||
$(RM) -f $(OBJ) |
|||
|
|||
# Clean this project and all dependencies
|
|||
cleanall: clean |
|||
endif |
|||
|
|||
#
|
|||
# Configuration: Release
|
|||
#
|
|||
ifeq "$(CFG)" "Release" |
|||
OUTDIR=Release |
|||
OUTFILE=$(OUTDIR)/starProcDaemon |
|||
CFG_INC= |
|||
CFG_LIB=-lpthread -lm -lconfig |
|||
CFG_OBJ= |
|||
COMMON_OBJ=$(OUTDIR)/basicFunctionality.o \
|
|||
$(OUTDIR)/basicLogCollection.o $(OUTDIR)/basicLoggingService.o \
|
|||
$(OUTDIR)/basicMemoryOperation.o $(OUTDIR)/basicRing.o \
|
|||
$(OUTDIR)/basicSettings.o $(OUTDIR)/basicSettingsProvider.o \
|
|||
$(OUTDIR)/basicThread.o $(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/objectConsoleLoggingService.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/starProcDaemon.o |
|||
OBJ=$(COMMON_OBJ) $(CFG_OBJ) |
|||
ALL_OBJ=$(OUTDIR)/basicFunctionality.o $(OUTDIR)/basicLogCollection.o \
|
|||
$(OUTDIR)/basicLoggingService.o $(OUTDIR)/basicMemoryOperation.o \
|
|||
$(OUTDIR)/basicRing.o $(OUTDIR)/basicSettings.o \
|
|||
$(OUTDIR)/basicSettingsProvider.o $(OUTDIR)/basicThread.o \
|
|||
$(OUTDIR)/kernel.o $(OUTDIR)/md5.o \
|
|||
$(OUTDIR)/objectConsoleLoggingService.o \
|
|||
$(OUTDIR)/objectFileLoggingService.o $(OUTDIR)/starProcDaemon.o \
|
|||
-lpthread -lm -lconfig |
|||
|
|||
COMPILE=g++ -c -O3 -o "$(OUTDIR)/$(*F).o" $(CFG_INC) $< |
|||
LINK=g++ -O3 -o "$(OUTFILE)" $(ALL_OBJ) |
|||
|
|||
# Pattern rules
|
|||
$(OUTDIR)/%.o : ../../lib/alg/generic/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : %.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/components/base/%.cpp |
|||
$(COMPILE) |
|||
|
|||
$(OUTDIR)/%.o : ../../lib/components/object/%.cpp |
|||
$(COMPILE) |
|||
|
|||
# Build rules
|
|||
all: $(OUTFILE) |
|||
|
|||
$(OUTFILE): $(OUTDIR) $(OBJ) |
|||
$(LINK) |
|||
|
|||
$(OUTDIR): |
|||
$(MKDIR) -p "$(OUTDIR)" |
|||
|
|||
# Rebuild this project
|
|||
rebuild: cleanall all |
|||
|
|||
# Clean this project
|
|||
clean: |
|||
$(RM) -f $(OUTFILE) |
|||
$(RM) -f $(OBJ) |
|||
|
|||
# Clean this project and all dependencies
|
|||
cleanall: clean |
|||
endif |
|||
@ -0,0 +1,317 @@ |
|||
#include "starProcDaemon.h"
|
|||
|
|||
// Global Variables
|
|||
|
|||
CSTR gsCFG_ADDRESS; |
|||
uint16_t guCFG_PORT = DEFAULT_SERVER_PORT; |
|||
CSTR gsCFG_LICENSE; |
|||
CSTR gsCFG_DB_SERVER; |
|||
CSTR gsCFG_DB_NAME; |
|||
CSTR gsCFG_DB_USER; |
|||
CSTR gsCFG_DB_PASSWORD; |
|||
char gsCFG_PID_FILE[PATH_MAX]; //= (CSTR) DEFAULT_SERVER_PID_FILE;
|
|||
SOFTWARE_INFO gsSOFT_INFO; |
|||
bool gbCFG_MASTER_ROLE = true; |
|||
|
|||
bool gModule_GeoFence_Enabled = true; |
|||
bool gModule_SMS_Enabled = false; |
|||
bool gModule_Email_Enabled = false; |
|||
bool gSignal_Handler_Enabled = true; |
|||
|
|||
#define LOG( X ) m_pLog->Log( "main", 0, X )
|
|||
#define LOG_ERROR( X ) m_pLog->Log( "main", 0, _LOG_ERROR, X )
|
|||
|
|||
SP_KERNEL * Kernel = NULL; |
|||
basicLogCollection * m_pLog = NULL; |
|||
|
|||
void (*old_update_handler_2)(int); //SIGINT
|
|||
void (*old_kill_handler_3)(int); //SIGQUIT
|
|||
void (*old_kill_handler_9)(int); //SIGKILL
|
|||
void (*old_alarm_handler_14)(int); //SIGALRM
|
|||
void (*old_kill_handler_15)(int); //SIGTERM
|
|||
|
|||
|
|||
/*
|
|||
|
|||
FILE *f; |
|||
pid_t pid_child; |
|||
char proc_path[256]; |
|||
|
|||
f = fopen("/tmp/mydaemon.pid", "r"); |
|||
fscanf(f, "%d", &pid_child); |
|||
fclose(f); |
|||
sprintf(proc_path, "/proc/%d/exe", pid_child); |
|||
|
|||
while(1) { |
|||
if (access(proc_path, F_OK) == 0) { |
|||
printf("Program alive !\n"); |
|||
sleep(1); |
|||
} else { |
|||
printf("Program dead!\n"); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
|
|||
*/ |
|||
|
|||
void signal_SIGKILL_handler( int SIG ){ |
|||
if( Kernel!= NULL ){ |
|||
if( gSignal_Handler_Enabled ){ |
|||
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Service by Signal" ); |
|||
Kernel->setStatus( TH_ENDED ); // Closing all Connections;
|
|||
} else { |
|||
m_pLog->Log("SIG", 0, _LOG_DEBUG, "Shutdown Signal Handler Disabled" ); |
|||
}; |
|||
}; |
|||
}; |
|||
|
|||
//#include <sys/resource.h>
|
|||
|
|||
int main (int argc, char *argv[]){ |
|||
/*
|
|||
const rlim_t kStackSize = 16 * 1024 * 1024; // min stack size = 16 MB
|
|||
struct rlimit rl; |
|||
int result; |
|||
|
|||
result = getrlimit(RLIMIT_STACK, &rl); |
|||
if (result == 0){ |
|||
printf( "Stack Size: %d\n", rl.rlim_cur ); |
|||
if ( rl.rlim_cur < kStackSize ){ |
|||
printf( "Resize Stack to: %d\n", kStackSize ); |
|||
rl.rlim_cur = kStackSize; |
|||
result = setrlimit(RLIMIT_STACK, &rl); |
|||
if (result != 0){ |
|||
fprintf(stderr, "setrlimit returned result = %d\n", result); |
|||
return -1; |
|||
}; |
|||
}; |
|||
}; |
|||
*/ |
|||
|
|||
//MySQL_Connector * DBC = NULL;
|
|||
basicSettingsProvider * SETTINGS = NULL; |
|||
bool WBG = true; // Working Background
|
|||
bool SSE = true; // Server Statistics Engine
|
|||
bool NDC = true; // No Default Configuration
|
|||
bool COLD_START = true; |
|||
char FLE_NAME[PATH_MAX] = {0}; |
|||
char DVD_NAME[PATH_MAX] = {0}; |
|||
CSTR DCF_NAME; |
|||
CSTR SSP_NAME; |
|||
objectFileLoggingService * FLE = NULL; |
|||
objectConsoleLoggingService * CLE = NULL; |
|||
// default init
|
|||
DCF_NAME = (CSTR) DEFAULT_SERVER_CONFIG_PATH; |
|||
SSP_NAME = (CSTR) DEFAULT_SERVER_SOCKET_PATH; |
|||
|
|||
CSTR tB = get_current_dir_name(); |
|||
if( tB ) { |
|||
sprintf( DVD_NAME , "%s", tB ); |
|||
free( tB ); |
|||
} else { |
|||
printf( "Can Not Get CWD!\n"); |
|||
}; |
|||
sprintf( gsCFG_PID_FILE, "%s/%s", DVD_NAME, DEFAULT_SERVER_PID_FILE ); |
|||
sprintf( FLE_NAME , "%s/%s", DVD_NAME, DEFAULT_SERVER_LOG_FILE ); |
|||
gsSOFT_INFO.SW_BUILD_DATE = UNIX_TIMESTAMP; |
|||
gsSOFT_INFO.DATA_VALID = false; |
|||
m_pLog = basicLogCollection::getInstance( _LOG_LVL_TIME_PTR ); |
|||
gsSOFT_INFO.SW_MODE_FLAGS = 0 |
|||
#ifdef SKIP_TARGET_LOG
|
|||
| SW_INFO_NO_TARGET_LOG |
|||
#endif
|
|||
#ifdef HIBERNATE_ENABLE
|
|||
| SW_INFO_HIBERNATE_ENA |
|||
#endif
|
|||
#ifdef TGD
|
|||
| SW_INFO_TGD_MOTORS |
|||
#ifdef TGD_VERSION_2
|
|||
| SW_INFO_TGD_VER_2 |
|||
#endif
|
|||
#endif
|
|||
#ifdef ENCODER_8192
|
|||
| SW_INFO_EU_PROJECT |
|||
#endif
|
|||
#ifdef NO_BLACK_TARGETS
|
|||
| SW_INFO_NO_BLACK_TARGETS |
|||
#endif
|
|||
#ifndef NO_MOTORS
|
|||
| SW_INFO_MOTOR_CTRL_ENA |
|||
#endif
|
|||
#ifdef THREADED_FLIP
|
|||
| SW_INFO_THREAD_FLIP |
|||
#endif
|
|||
#ifndef PRU_SLAVE
|
|||
| SW_INFO_FLAG_MASTER |
|||
#endif
|
|||
#ifdef DEBUG
|
|||
| SW_INFO_DEBUG_MODE |
|||
#endif
|
|||
; |
|||
|
|||
|
|||
// Reading Config
|
|||
if( argc > 1 ){ |
|||
for( int i = 0; i < argc; i++ ){ |
|||
switch( argv[i][0] ){ |
|||
case '-': |
|||
case '\\': |
|||
case '/':{ |
|||
switch( argv[i][1] ){ |
|||
case 'h': case 'H': case 'v': case 'V': case '?':{ |
|||
printf( "Dr Frucht Systems R-Goose Server\n"); |
|||
printf( "Software version <%s>\n", VERSION_NUMBER ); |
|||
printf( " -h -H This Message\n" ); |
|||
printf( " -i -I Interactive Mode\n" ); |
|||
return 0; |
|||
break; |
|||
}; |
|||
case 'i': case 'I':{ |
|||
WBG = false; |
|||
CLE = new objectConsoleLoggingService(); |
|||
if( CLE != NULL ) { |
|||
m_pLog->addHandler( CLE ); |
|||
}; |
|||
break; |
|||
}; |
|||
case 'c': case 'C':{ |
|||
DCF_NAME = (CSTR) malloc( MAX_PATH_LEN ); |
|||
if( DCF_NAME != NULL ) { |
|||
sprintf( DCF_NAME, "%s", argv[i+1] ); |
|||
} else { |
|||
printf("ERROR!\n\n"); |
|||
return -1; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
break; |
|||
}; |
|||
}; |
|||
}; |
|||
}; |
|||
FLE = new objectFileLoggingService( FLE_NAME ); |
|||
if( FLE != NULL ) { |
|||
m_pLog->addHandler( FLE ); |
|||
}; |
|||
LOG("Starting Log Engne!"); |
|||
if ( fileExist( DCF_NAME ) ){ |
|||
SETTINGS = basicSettingsProvider::getInstance(DCF_NAME); |
|||
} else { |
|||
SETTINGS = basicSettingsProvider::getInstance(); |
|||
}; |
|||
if ( fileExist( gsCFG_PID_FILE ) ){ |
|||
COLD_START = false; |
|||
//check if process already running
|
|||
FILE *tFD = fopen( gsCFG_PID_FILE, "r" ); |
|||
if( tFD ) { |
|||
pid_t pid; |
|||
char tBuff[256]; |
|||
//fscanf( tFD, "%d\n", pid );
|
|||
fread( tBuff, 1, 255, tFD ); |
|||
pid = atoi( tBuff ); |
|||
printf("Old Process PID: %d\n", pid ); |
|||
if( kill( pid, 0 )==0 ){ |
|||
printf("Process Already Running --> exiting!\n"); |
|||
delete( FLE ); |
|||
fclose( tFD ); |
|||
exit(12); |
|||
} else { |
|||
printf("No Running Process --> Hot Restart Detected!\n"); |
|||
}; |
|||
fclose( tFD ); |
|||
}; |
|||
}; |
|||
// Demonizing or not
|
|||
if( WBG ){ |
|||
printf( "Dr Frucht Systems Start Daemon ver. %s\n", VERSION_NUMBER ); |
|||
printf( "Configuration Applied:\n"); |
|||
printf( " Service Established %s at %d\n", gsCFG_ADDRESS, guCFG_PORT ); |
|||
printf( " PID File: %s\n", gsCFG_PID_FILE ); |
|||
printf( " Log File: %s\n", FLE_NAME ); |
|||
printf( " License: %s\n", gsCFG_LICENSE ); |
|||
printf( " Database Server: %s Database: %s\n", gsCFG_DB_SERVER, gsCFG_DB_NAME ); |
|||
if( NDC ){ |
|||
printf( " No configuration file (%s) supplied.\n", DCF_NAME); |
|||
} else { |
|||
printf( " Configuration read from: %s\n", DCF_NAME ); |
|||
}; |
|||
|
|||
//Demonizing
|
|||
pid_t pid, sid; |
|||
sync(); |
|||
close( STDIN_FILENO ); |
|||
close( STDOUT_FILENO ); |
|||
close( STDERR_FILENO ); |
|||
|
|||
pid = fork(); |
|||
if( pid < 0 ){ |
|||
return pid; |
|||
}; |
|||
if( pid > 0 ){ |
|||
return 0; |
|||
}; |
|||
//umask(0);
|
|||
sid = setsid(); |
|||
if (sid < 0) { |
|||
return sid; |
|||
}; |
|||
|
|||
pid = fork(); |
|||
if( pid < 0 ){ |
|||
return pid; |
|||
}; |
|||
if( pid > 0 ){ |
|||
FILE *pPIDF = fopen( gsCFG_PID_FILE, "w+" ); |
|||
if( pPIDF ){ |
|||
fprintf( pPIDF, "%d\n", pid ); |
|||
fclose( pPIDF ); |
|||
} |
|||
return 0; |
|||
}; |
|||
}; |
|||
|
|||
uint8_t m_bKernelExitCode = 0; |
|||
|
|||
do{ |
|||
Kernel = SP_KERNEL::getInstance( COLD_START ); |
|||
if( Kernel == NULL ) { |
|||
// Aborting Work
|
|||
LOG_ERROR( "++++ Kernel failed to born ++++" ); |
|||
unlink( gsCFG_PID_FILE ); |
|||
LOG( "PID File Deleted" ); |
|||
delete( m_pLog ); |
|||
return -1; |
|||
}; |
|||
//Loop till some Restart action
|
|||
if( Kernel != NULL ){ |
|||
LOG( "++++ Server Started ++++" ); |
|||
if ( Kernel->create() == false ){ |
|||
LOG_ERROR("Kernel create failure!"); |
|||
} else { |
|||
//Install Signal Listeners
|
|||
old_kill_handler_15 = signal( 15, signal_SIGKILL_handler ); |
|||
old_kill_handler_9 = signal( 9, signal_SIGKILL_handler ); |
|||
// Waiting for Worker to Shut Down
|
|||
Kernel->WaitFinish( false ); |
|||
m_bKernelExitCode = Kernel->getExitCause(); |
|||
signal( 9, old_kill_handler_9 ); |
|||
signal( 15, old_kill_handler_15 ); |
|||
}; |
|||
delete( Kernel ); |
|||
LOG( "++++ Server Ended ++++" ); |
|||
}; |
|||
} while( m_bKernelExitCode > 0 ); |
|||
|
|||
//delete( NetworkManager );
|
|||
//LOG( "++++ CDC DEL ++++" );
|
|||
unlink( gsCFG_PID_FILE ); |
|||
LOG( "PID File Deleted" ); |
|||
if( FLE!= NULL ) delete( FLE ); |
|||
if( CLE!= NULL ) delete( CLE ); |
|||
delete( m_pLog ); |
|||
return(0); |
|||
} |
|||
|
|||
|
|||
@ -0,0 +1,31 @@ |
|||
|
|||
/******************************************************************* |
|||
* |
|||
* DESCRIPTION: starProcDaemon project main header file |
|||
* |
|||
* AUTHOR: Gagua |
|||
* |
|||
* HISTORY: |
|||
* |
|||
* DATE:2/13/2022 |
|||
* |
|||
*******************************************************************/ |
|||
#ifndef __START_PROC_MAIN_HEADER__ |
|||
#define __START_PROC_MAIN_HEADER__ |
|||
|
|||
/** include files **/ |
|||
|
|||
#include <stdlib.h> |
|||
#include <stdio.h> |
|||
#include <signal.h> |
|||
|
|||
#include "../../lib/components/base/basicSettings.h" |
|||
#include "../../lib/components/base/basicLogCollection.h" |
|||
#include "../../lib/components/base/basicSettingsProvider.h" |
|||
#include "../../lib/components/base/basicMemoryOperation.h" |
|||
#include "../../lib/components/object/objectFileLoggingService.h" |
|||
#include "../../lib/components/object/objectConsoleLoggingService.h" |
|||
#include "kernel.h" |
|||
|
|||
|
|||
#endif |
|||
@ -0,0 +1,247 @@ |
|||
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd"> |
|||
<Project |
|||
Version="10.0" |
|||
VendorName="SlickEdit" |
|||
TemplateName="GNU C/C++" |
|||
WorkingDir="." |
|||
BuildSystem="automakefile" |
|||
BuildMakeFile="makefile"> |
|||
<Config |
|||
Name="Debug" |
|||
Type="gnuc" |
|||
DebugCallbackName="gdb" |
|||
Version="1" |
|||
OutputFile="%bdstarProcDaemon" |
|||
CompilerConfigName="Latest Version" |
|||
Defines=""> |
|||
<Menu> |
|||
<Target |
|||
Name="Compile" |
|||
MenuCaption="&Compile" |
|||
Dialog="_gnuc_options_form Compile" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
OutputExts="*.o" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ -c %xup %defd -O0 -g3 -ggdb -o "%bd%n%oe" %i %f'/> |
|||
</Target> |
|||
<Target |
|||
Name="Link" |
|||
MenuCaption="&Link" |
|||
ShowOnMenu="Never" |
|||
Dialog="_gnuc_options_form Link" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ %xup -O0 -g3 -ggdb -o "%o" %objs'/> |
|||
</Target> |
|||
<Target |
|||
Name="Build" |
|||
MenuCaption="&Build" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Rebuild" |
|||
MenuCaption="&Rebuild" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Debug" |
|||
MenuCaption="&Debug" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveNone" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='vsdebugio -prog "%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="Execute" |
|||
MenuCaption="E&xecute" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='"%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="dash" |
|||
MenuCaption="-" |
|||
Deletable="0"> |
|||
<Exec/> |
|||
</Target> |
|||
<Target |
|||
Name="GNU C Options" |
|||
MenuCaption="GNU C &Options..." |
|||
ShowOnMenu="HideIfNoCmdLine" |
|||
Deletable="0" |
|||
SaveOption="SaveNone"> |
|||
<Exec |
|||
CmdLine="gnucoptions" |
|||
Type="Slick-C"/> |
|||
</Target> |
|||
</Menu> |
|||
<List Name="GNUC Options"> |
|||
<Item |
|||
Name="LinkerOutputType" |
|||
Value="Executable"/> |
|||
</List> |
|||
<Includes/> |
|||
<Libs PreObjects="0"> |
|||
<Lib File="-lpthread"/> |
|||
<Lib File="-lm"/> |
|||
<Lib File="-lconfig"/> |
|||
</Libs> |
|||
</Config> |
|||
<Config |
|||
Name="Release" |
|||
Type="gnuc" |
|||
DebugCallbackName="gdb" |
|||
Version="1" |
|||
OutputFile="%bdstarProcDaemon" |
|||
CompilerConfigName="Latest Version" |
|||
Defines=""> |
|||
<Menu> |
|||
<Target |
|||
Name="Compile" |
|||
MenuCaption="&Compile" |
|||
Dialog="_gnuc_options_form Compile" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
OutputExts="*.o" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ -c %xup %defd -O3 -o "%bd%n%oe" %i %f'/> |
|||
</Target> |
|||
<Target |
|||
Name="Link" |
|||
MenuCaption="&Link" |
|||
ShowOnMenu="Never" |
|||
Dialog="_gnuc_options_form Link" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveCurrent" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='g++ %xup -O3 -o "%o" %objs'/> |
|||
</Target> |
|||
<Target |
|||
Name="Build" |
|||
MenuCaption="&Build" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Rebuild" |
|||
MenuCaption="&Rebuild" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='make -f "makefile" rebuild CFG=%b'/> |
|||
</Target> |
|||
<Target |
|||
Name="Debug" |
|||
MenuCaption="&Debug" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveNone" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='vsdebugio -prog "%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="Execute" |
|||
MenuCaption="E&xecute" |
|||
Dialog="_gnuc_options_form Run/Debug" |
|||
BuildFirst="1" |
|||
CaptureOutputWith="ProcessBuffer" |
|||
Deletable="0" |
|||
SaveOption="SaveWorkspaceFiles" |
|||
RunFromDir="%rw"> |
|||
<Exec CmdLine='"%o"'/> |
|||
</Target> |
|||
<Target |
|||
Name="dash" |
|||
MenuCaption="-" |
|||
Deletable="0"> |
|||
<Exec/> |
|||
</Target> |
|||
<Target |
|||
Name="GNU C Options" |
|||
MenuCaption="GNU C &Options..." |
|||
ShowOnMenu="HideIfNoCmdLine" |
|||
Deletable="0" |
|||
SaveOption="SaveNone"> |
|||
<Exec |
|||
CmdLine="gnucoptions" |
|||
Type="Slick-C"/> |
|||
</Target> |
|||
</Menu> |
|||
<List Name="GNUC Options"> |
|||
<Item |
|||
Name="LinkerOutputType" |
|||
Value="Executable"/> |
|||
</List> |
|||
<Includes/> |
|||
<Libs PreObjects="0"> |
|||
<Lib File="-lpthread"/> |
|||
<Lib File="-lm"/> |
|||
<Lib File="-lconfig"/> |
|||
</Libs> |
|||
</Config> |
|||
<Files> |
|||
<Folder |
|||
Name="Source Files" |
|||
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d"> |
|||
<F N="../../lib/components/base/basicFunctionality.cpp"/> |
|||
<F N="../../lib/components/base/basicLogCollection.cpp"/> |
|||
<F N="../../lib/components/base/basicLoggingService.cpp"/> |
|||
<F N="../../lib/components/base/basicMemoryOperation.cpp"/> |
|||
<F N="../../lib/components/base/basicRing.cpp"/> |
|||
<F N="../../lib/components/base/basicSettings.cpp"/> |
|||
<F N="../../lib/components/base/basicSettingsProvider.cpp"/> |
|||
<F N="../../lib/components/base/basicThread.cpp"/> |
|||
<F N="kernel.cpp"/> |
|||
<F N="../../lib/alg/generic/md5.cpp"/> |
|||
<F N="../../lib/components/object/objectConsoleLoggingService.cpp"/> |
|||
<F N="../../lib/components/object/objectFileLoggingService.cpp"/> |
|||
<F N="starProcDaemon.cpp"/> |
|||
</Folder> |
|||
<Folder |
|||
Name="Header Files" |
|||
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if"> |
|||
<F N="kernel.h"/> |
|||
<F N="starProcDaemon.h"/> |
|||
</Folder> |
|||
<Folder |
|||
Name="Resource Files" |
|||
Filters="*.ico;*.cur;*.dlg"/> |
|||
<Folder |
|||
Name="Bitmaps" |
|||
Filters="*.bmp"/> |
|||
<Folder |
|||
Name="Other Files" |
|||
Filters=""> |
|||
<F |
|||
N="makefile" |
|||
Type="Makefile"/> |
|||
</Folder> |
|||
</Files> |
|||
</Project> |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue