continue code separation into different folders
This commit is contained in:
10
daemon/Makefile.am
Normal file
10
daemon/Makefile.am
Normal file
@ -0,0 +1,10 @@
|
||||
include_HEADERS = $(top_srcdir)/yasnd.h
|
||||
|
||||
yasnd_LDADD = ${libconfuse_LIBS}
|
||||
yasnd_LDADD += $(top_srcdir)/lib/libyasnd.la
|
||||
sbin_PROGRAMS = yasnd
|
||||
yasnd_SOURCES = yasnd.c yasnd-ipc.c
|
||||
yasnd_CPPFLAGS = -I$(top_srcdir)
|
||||
|
||||
distclean-local:
|
||||
rm -f Makefile.in &>/dev/null
|
145
daemon/yasnd-ipc.c
Normal file
145
daemon/yasnd-ipc.c
Normal file
@ -0,0 +1,145 @@
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/msg.h>
|
||||
|
||||
#include "yasnd.h"
|
||||
|
||||
pid_t ipc_clone_pid;
|
||||
pid_t ipc_sms_read_clone_pid=-1; // pid of thread, that checks for new incoming SMS
|
||||
int qid=-1; // IPC queue id
|
||||
|
||||
int open_queue()
|
||||
{
|
||||
key_t keyval=ftok(".",'m');
|
||||
int qid;
|
||||
if((qid = msgget( keyval, IPC_CREAT | 0660 )) == -1)
|
||||
{
|
||||
log_event("Error opening/creating IPC message queue");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return qid;
|
||||
}
|
||||
|
||||
int send_message(int qid, mymsgbuf* qbuf)
|
||||
{
|
||||
int result;
|
||||
/* The length is essentially the size of the structure minus sizeof(mtype) */
|
||||
int length = sizeof(mymsgbuf) - sizeof(long);
|
||||
|
||||
if((result = msgsnd( qid, qbuf, length, 0)) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int read_message(int qid, mymsgbuf* qbuf, long type)
|
||||
{
|
||||
int result;
|
||||
int length = sizeof(mymsgbuf) - sizeof(long);
|
||||
if((result = msgrcv( qid, qbuf, length, type, 0)) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int remove_queue( int qid )
|
||||
{
|
||||
if( msgctl(qid, IPC_RMID, 0) == -1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ipc_queue_loop()
|
||||
{
|
||||
// set default signal handlers
|
||||
signal(SIGTERM,SIG_DFL);
|
||||
signal(SIGHUP,SIG_DFL);
|
||||
//
|
||||
mymsgbuf qbuf;
|
||||
while(1)
|
||||
{
|
||||
int result=read_message(qid, &qbuf, 0);
|
||||
if (result==-1)
|
||||
{
|
||||
log_event("Error: finishing IPC loop process...");
|
||||
return 1;
|
||||
}
|
||||
char dbg_txt[150];
|
||||
sprintf(dbg_txt,"Read IPC message - Type: %ld Text: %s", qbuf.mtype, qbuf.mtext);
|
||||
log_debug(dbg_txt,DEBUG_ALL);
|
||||
if (qbuf.mtype==SMS_RECEIVE_TYPE && sms_enable)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
log_event("Error: can not fork child :(");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// If pid == 0, then we are in the child
|
||||
if (pid == 0) {
|
||||
gammu_read_sms();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
// wait for SMS reading thread
|
||||
// STUB: need to react on status, returned by thread
|
||||
waitpid(pid,NULL,0);
|
||||
}
|
||||
if (qbuf.mtype==SMS_SEND_TYPE && sms_enable)
|
||||
{
|
||||
log_debug(qbuf.mtext,DEBUG_BASE);
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
log_event("Error: can not fork child :(");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// If pid == 0, then we are in the child
|
||||
if (pid == 0) {
|
||||
gammu_send_sms(qbuf.mtext);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
// wait for SMS sending thread
|
||||
// STUB: need to react on status, returned by thread
|
||||
waitpid(pid,NULL,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ipc_sms_reading_loop()
|
||||
{
|
||||
// set default signal handlers
|
||||
signal(SIGTERM,SIG_DFL);
|
||||
signal(SIGHUP,SIG_DFL);
|
||||
//
|
||||
while(1)
|
||||
{
|
||||
sleep(30); /* wait 30 seconds */
|
||||
mymsgbuf qbuf;
|
||||
qbuf.mtype=SMS_RECEIVE_TYPE;
|
||||
qbuf.mtext[0]=(char)0;
|
||||
send_message(qid,&qbuf);
|
||||
}
|
||||
}
|
||||
|
||||
void ipc_init()
|
||||
{
|
||||
qid = open_queue();
|
||||
unsigned char ipc_child_stack[16384];
|
||||
ipc_clone_pid=clone(ipc_queue_loop,ipc_child_stack+8192,CLONE_VM,NULL);
|
||||
// start loop, that handles new incoming SMS
|
||||
unsigned char sms_child_stack[16384];
|
||||
ipc_sms_read_clone_pid=clone(ipc_sms_reading_loop,sms_child_stack+8192,CLONE_VM,NULL);
|
||||
//
|
||||
}
|
||||
|
||||
void ipc_free()
|
||||
{
|
||||
kill(ipc_clone_pid,SIGTERM);
|
||||
waitpid(ipc_clone_pid,NULL,__WCLONE);
|
||||
kill(ipc_sms_read_clone_pid,SIGTERM);
|
||||
waitpid(ipc_sms_read_clone_pid,NULL,__WCLONE);
|
||||
remove_queue(qid);
|
||||
}
|
477
daemon/yasnd.c
Normal file
477
daemon/yasnd.c
Normal file
@ -0,0 +1,477 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/io.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <syslog.h>
|
||||
#include <getopt.h>
|
||||
#include <confuse.h>
|
||||
|
||||
#include "yasnd.h"
|
||||
|
||||
cfg_t *cfg; // pointer to configuration structure
|
||||
char pidfile[]="/var/run/yasnd.pid"; // pidfile path
|
||||
host_decl* hosts=NULL; // structure with hosts' definitions
|
||||
int hosts_count=0; // count of hosts
|
||||
int debug_flag=0;
|
||||
bool sms_enable=false; // use SMS messages for control and reports?
|
||||
char* phone_device=NULL; // phone device for gammu, for example: "/dev/ttyACM0"
|
||||
char* phone_model=NULL; // gammu phone model, for example: "at"
|
||||
char* phone_connection=NULL; // gammu phone connection type, for example: "at"
|
||||
char* recipient_number=NULL; // recipient of sms alerts
|
||||
bool lpt_enable=false; // control usage of LPT port to reset target devices
|
||||
int lpt_port=0x378; // LPT port in hex(0x378 is usually LPT1)
|
||||
bool loop_locked=false; // flag for locking main loop while config re-reading
|
||||
int failures_first=0; // count of failures while hosts checking, that triggers SMS sending
|
||||
int failures_second=0; // count of failures while hosts checking, that triggers host's reset
|
||||
int failures_third=0; // count of failures while hosts checking, that clean failure statistics
|
||||
pid_t mainloop_clone_pid; // pid of clone process, that containt main loop
|
||||
|
||||
void log_debug(const char *message,int verbosity)
|
||||
{
|
||||
if (debug_flag>=verbosity)
|
||||
syslog(LOG_INFO,"%s",message);
|
||||
}
|
||||
|
||||
void log_event(const char *message)
|
||||
{
|
||||
syslog(LOG_INFO,"%s",message);
|
||||
}
|
||||
|
||||
void* allocate_memory(int bytes)
|
||||
{
|
||||
void* result=malloc(bytes);
|
||||
if (result==NULL)
|
||||
{
|
||||
log_event("Error: malloc failed");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn off all LPT port pins.
|
||||
This is needed to unlock LPT control circuit, when
|
||||
management computer is just booted
|
||||
*/
|
||||
void lpt_init()
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Unlocking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Unlock circuit
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on first LPT port pin and turn off others.
|
||||
This is needed to lock LPT control circuit, when
|
||||
management computer is rebooted
|
||||
*/
|
||||
void lpt_lock_cond(bool ignore_options)
|
||||
{
|
||||
if (lpt_enable || ignore_options)
|
||||
{
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: Locking the circuit fails due to LPT port access error");
|
||||
// disable LPT port usage
|
||||
lpt_enable=false;
|
||||
return;
|
||||
}
|
||||
// Lock circuit
|
||||
outb (1, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
// Previous function, but without ignoring lpt_enable option
|
||||
void lpt_lock()
|
||||
{
|
||||
return lpt_lock_cond(false);
|
||||
}
|
||||
|
||||
// Function, that checks that defined host entry is valid
|
||||
int cb_validate_host(cfg_t *cfg, cfg_opt_t *opt)
|
||||
{
|
||||
return 0; // success
|
||||
}
|
||||
|
||||
void pidfile_init()
|
||||
{
|
||||
int pidfile_d=open(pidfile,O_RDWR|O_CREAT,0640);
|
||||
/* Can not open/create pidfile? */
|
||||
if (pidfile_d<0)
|
||||
{
|
||||
log_event("Error: can not open/create pid file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* Can not lock pidfile? */
|
||||
if (lockf(pidfile_d,F_TLOCK,0)<0)
|
||||
{
|
||||
log_event("Error: can not lock pid file, maybe another yasnd instance still running?");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* First daemon instance continues */
|
||||
char pidstr[20];
|
||||
sprintf(pidstr,"%d\n",getpid());
|
||||
/* Record pid to pidfile and hold it */
|
||||
write(pidfile_d,pidstr,strlen(pidstr));
|
||||
}
|
||||
|
||||
void init()
|
||||
{
|
||||
static cfg_opt_t host_opts[] = {
|
||||
CFG_STR("hostname", 0, CFGF_NONE),
|
||||
CFG_INT("lpt_pin", 0, CFGF_NONE),
|
||||
CFG_END()
|
||||
};
|
||||
// Initialize config parsing library
|
||||
cfg_opt_t opts[] = {
|
||||
CFG_SEC("host", host_opts, CFGF_MULTI | CFGF_TITLE),
|
||||
CFG_SIMPLE_INT("debug", &debug_flag),
|
||||
CFG_SIMPLE_INT("failures_first", &failures_first),
|
||||
CFG_SIMPLE_INT("failures_second", &failures_second),
|
||||
CFG_SIMPLE_INT("failures_third", &failures_third),
|
||||
CFG_SIMPLE_BOOL("lpt_enable", &lpt_enable),
|
||||
CFG_SIMPLE_INT("lpt_port", &lpt_port),
|
||||
CFG_SIMPLE_BOOL("sms_enable", &sms_enable),
|
||||
CFG_SIMPLE_STR("phone_device", &phone_device),
|
||||
CFG_SIMPLE_STR("phone_model", &phone_connection),
|
||||
CFG_SIMPLE_STR("phone_connection", &phone_model),
|
||||
CFG_SIMPLE_STR("sms_recipient", &recipient_number),
|
||||
CFG_END()
|
||||
};
|
||||
cfg = cfg_init(opts, CFGF_NONE);
|
||||
// set a validating callback function for host sections
|
||||
cfg_set_validate_func(cfg, "host", &cb_validate_host);
|
||||
// check if config file is valid and parse it
|
||||
if (cfg_parse(cfg, "/etc/yasnd.conf") == CFG_PARSE_ERROR)
|
||||
{
|
||||
log_event("Error parsing config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// failures thresholds must be explicitly defined in config
|
||||
if (failures_first==0 || failures_second==0 || failures_third==0)
|
||||
{
|
||||
log_event("Error: all failures threshold parameters must be defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// if SMS is enabled, all of phone parameters must be explicitly defined
|
||||
if (sms_enable)
|
||||
{
|
||||
if (phone_model==NULL)
|
||||
{
|
||||
log_event("Error: phone model is not defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (phone_connection==NULL)
|
||||
{
|
||||
log_event("Error: phone connection type is not defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (phone_device==NULL)
|
||||
{
|
||||
log_event("Error: phone device is not defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (recipient_number==NULL)
|
||||
{
|
||||
log_event("Error: no recipient for sms alerts defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
// hosts' array must not be empty
|
||||
hosts_count=cfg_size(cfg,"host");
|
||||
if (hosts_count==0)
|
||||
{
|
||||
log_event("Error: no hosts to check defined in config file");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// allocate memory for hosts array...
|
||||
hosts=allocate_memory(hosts_count*sizeof(host_decl));
|
||||
// ...and fill it with config file content
|
||||
for (int i=0;i<hosts_count;i++)
|
||||
{
|
||||
cfg_t* host = cfg_getnsec(cfg, "host", i);
|
||||
hosts[i].hostname=cfg_getstr(host,"hostname");
|
||||
hosts[i].lpt_pin=cfg_getint(host,"lpt_pin");
|
||||
hosts[i].fail_count=0;
|
||||
hosts[i].alert_sent=false;
|
||||
hosts[i].reaction_obtained=false;
|
||||
}
|
||||
// initialize gammu structures
|
||||
if (sms_enable)
|
||||
gammu_init();
|
||||
// initialize LPT control circuit
|
||||
lpt_init();
|
||||
}
|
||||
|
||||
void check_host(int num,host_decl* host)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
log_event("Error: can not fork child :(");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// If pid == 0, then we are in the child
|
||||
if (pid == 0) {
|
||||
// Set default signal handlers
|
||||
signal(SIGTERM, SIG_DFL);
|
||||
signal(SIGHUP, SIG_DFL);
|
||||
//
|
||||
char tmp[50];
|
||||
sprintf(tmp, "Pinging host %s", host->hostname);
|
||||
log_debug(tmp,DEBUG_BASE);
|
||||
execl("/bin/ping","/bin/ping","-c 1","-n",host->hostname,(char*) 0);
|
||||
// STUB: check result of exec call
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
// Save child's pid
|
||||
host->helper_pid=pid;
|
||||
}
|
||||
|
||||
/*
|
||||
Function, that turn on only one LPT port pin, defined by it argument, wait a second,
|
||||
and turn off all pins. That is enough to reset specified host.
|
||||
*/
|
||||
void reset_pin(int pin_num)
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
if (pin_num==0)
|
||||
return; // there is no LPT control for target host
|
||||
if (pin_num<2 || pin_num>8)
|
||||
{
|
||||
log_event("Error: incorrent LPT pin number");
|
||||
return;
|
||||
}
|
||||
int pins = 1<<(pin_num-1);
|
||||
if (ioperm (lpt_port, 3, 1))
|
||||
{
|
||||
log_event("Error: LPT port access error");
|
||||
return;
|
||||
}
|
||||
// Reset host
|
||||
outb (pins, lpt_port);
|
||||
sleep(1);
|
||||
outb (0, lpt_port);
|
||||
}
|
||||
}
|
||||
|
||||
int loop_function()
|
||||
{
|
||||
// set default signal handlers
|
||||
signal(SIGTERM,SIG_DFL);
|
||||
signal(SIGHUP,SIG_DFL);
|
||||
//
|
||||
for (int i=0;i<hosts_count;i++)
|
||||
{
|
||||
check_host(i,&hosts[i]);
|
||||
}
|
||||
for (int i=0;i<hosts_count;i++)
|
||||
{
|
||||
int pid_status;
|
||||
int result = waitpid(hosts[i].helper_pid, &pid_status, 0);
|
||||
if (result > 0)
|
||||
{
|
||||
if (WIFEXITED(pid_status))
|
||||
{
|
||||
char tmp[50];
|
||||
sprintf(tmp, "Finished child %d with result %d", result, WEXITSTATUS(pid_status));
|
||||
log_debug(tmp,DEBUG_ALL);
|
||||
// if host is alive - reset failure counter
|
||||
// otherwise - increment it
|
||||
if (WEXITSTATUS(pid_status) == 0)
|
||||
{
|
||||
hosts[i].fail_count=0;
|
||||
hosts[i].alert_sent=false;
|
||||
hosts[i].reaction_obtained=false;
|
||||
}
|
||||
else
|
||||
hosts[i].fail_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i=0;i<hosts_count;i++)
|
||||
{
|
||||
mymsgbuf qbuf;
|
||||
if (hosts[i].fail_count>failures_second && hosts[i].alert_sent && !hosts[i].reaction_obtained)
|
||||
{
|
||||
if (lpt_enable)
|
||||
{
|
||||
qbuf.mtype=SMS_SEND_TYPE;
|
||||
sprintf(qbuf.mtext,"Host %s does not answer and no reaction on this. Trying to reset it(LPT pin %d)",hosts[i].hostname,hosts[i].lpt_pin);
|
||||
reset_pin(hosts[i].lpt_pin);
|
||||
hosts[i].reaction_obtained=true;
|
||||
// send message with SMS text to IPC queue
|
||||
send_message(qid,&qbuf);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (hosts[i].fail_count>failures_first && !hosts[i].alert_sent)
|
||||
{
|
||||
qbuf.mtype=SMS_SEND_TYPE;
|
||||
sprintf(qbuf.mtext,"Host %s does not answer(LPT pin %d)",hosts[i].hostname,hosts[i].lpt_pin);
|
||||
// set alert flag to prevent sending more than 1 message
|
||||
// for unreachable host
|
||||
hosts[i].alert_sent=true;
|
||||
// send message with SMS text to IPC queue
|
||||
send_message(qid,&qbuf);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void signal_handler(int signum)
|
||||
{
|
||||
void free_resources()
|
||||
{
|
||||
// lock Main Loop
|
||||
loop_locked=true;
|
||||
// kill Main Loop clone process
|
||||
kill(mainloop_clone_pid,SIGTERM);
|
||||
waitpid(mainloop_clone_pid,NULL,__WCLONE);
|
||||
// Stop IPC loop and remove IPC queue
|
||||
ipc_free();
|
||||
// free config structure
|
||||
cfg_free(cfg);
|
||||
// free gammu structure
|
||||
gammu_free();
|
||||
// free hosts structures memory
|
||||
if (hosts!=NULL)
|
||||
free(hosts);
|
||||
// remove pid file
|
||||
remove(pidfile);
|
||||
}
|
||||
|
||||
if (signum==SIGHUP)
|
||||
{
|
||||
log_event("SIGHUP captured, daemon re-read config");
|
||||
// free all resources
|
||||
free_resources();
|
||||
// Init IPC loop again
|
||||
ipc_init();
|
||||
// run init again
|
||||
init();
|
||||
// sleep 5 seconds and unlock Main Loop
|
||||
sleep(5);
|
||||
loop_locked=false;
|
||||
return;
|
||||
}
|
||||
if (signum==SIGTERM)
|
||||
{
|
||||
log_event("SIGTERM captured, daemon stopping");
|
||||
// free resources
|
||||
free_resources();
|
||||
// block LPT control circuit
|
||||
lpt_lock();
|
||||
// close log decriptor
|
||||
closelog();
|
||||
//
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
void arg_parse(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
struct option option_string[] =
|
||||
{
|
||||
{"init", no_argument, NULL, 'i'},
|
||||
};
|
||||
while ((c = getopt_long(argc, argv,"i", option_string, NULL)) != 0)
|
||||
{
|
||||
switch(c)
|
||||
{
|
||||
case 'i':
|
||||
lpt_lock_cond(true);
|
||||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// Parse command line arguments
|
||||
arg_parse(argc,argv);
|
||||
|
||||
/* Our process ID and Session ID */
|
||||
pid_t pid, sid;
|
||||
|
||||
/* Fork off the parent process */
|
||||
pid = fork();
|
||||
if (pid < 0) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* If we got a good PID, then we can exit the parent process. */
|
||||
if (pid > 0) {
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/* Change the file mode mask */
|
||||
umask(0);
|
||||
|
||||
/* Open any logs here */
|
||||
openlog("yasnd", LOG_PID|LOG_CONS, LOG_USER);
|
||||
|
||||
/* Create a new SID for the child process */
|
||||
sid = setsid();
|
||||
if (sid < 0) {
|
||||
/* Log the failure */
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Change the current working directory */
|
||||
if ((chdir("/")) < 0) {
|
||||
/* Log the failure */
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Close out the standard file descriptors */
|
||||
close(STDIN_FILENO);
|
||||
close(STDOUT_FILENO);
|
||||
close(STDERR_FILENO);
|
||||
|
||||
// create pid file and write current process pid
|
||||
pidfile_init();
|
||||
|
||||
// initialize IPC queue and create process
|
||||
// that will watch for new messages in it
|
||||
ipc_init();
|
||||
|
||||
// Init apropriate structures
|
||||
init();
|
||||
|
||||
// Set signal handlers
|
||||
signal(SIGTERM, signal_handler);
|
||||
signal(SIGHUP, signal_handler);
|
||||
|
||||
/* The Main Loop */
|
||||
while (1) {
|
||||
if (!loop_locked)
|
||||
{
|
||||
unsigned char child_stack[16384];
|
||||
mainloop_clone_pid=clone(loop_function,child_stack+8192,CLONE_VM,NULL);
|
||||
sleep(60); /* wait 60 seconds */
|
||||
// wait for clone process to prevent zombie
|
||||
waitpid(mainloop_clone_pid,NULL,__WCLONE);
|
||||
// log_event("Exiting");
|
||||
// exit(EXIT_SUCCESS);
|
||||
}
|
||||
else
|
||||
{
|
||||
// if loop is locked, just wait 1 second and start it again
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
Reference in New Issue
Block a user