mirror of
https://github.com/eddyem/small_tel.git
synced 2026-03-20 08:41:03 +03:00
Add some usefull functions from lib SOFA
This commit is contained in:
@@ -20,8 +20,9 @@
|
||||
*/
|
||||
#include "usefull_macros.h"
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h> // wait
|
||||
#include <sys/wait.h> // wait
|
||||
#include <sys/prctl.h> //prctl
|
||||
#include <time.h> // time
|
||||
#include "cmdlnopts.h"
|
||||
#include "socket.h"
|
||||
|
||||
@@ -29,10 +30,13 @@
|
||||
|
||||
glob_pars *GP;
|
||||
|
||||
pid_t childpid = 0;
|
||||
|
||||
void signals(int signo){
|
||||
restore_console();
|
||||
restore_tty();
|
||||
putlog("exit with status %d", signo);
|
||||
if(childpid){ // parent process
|
||||
restore_tty();
|
||||
putlog("exit with status %d", signo);
|
||||
}
|
||||
exit(signo);
|
||||
}
|
||||
|
||||
@@ -56,13 +60,16 @@ int main(int argc, char **argv){
|
||||
if(daemon(1, 0)){
|
||||
ERR("daemon()");
|
||||
}
|
||||
time_t lastd = 0;
|
||||
while(1){ // guard for dead processes
|
||||
pid_t childpid = fork();
|
||||
childpid = fork();
|
||||
if(childpid){
|
||||
putlog("create child with PID %d\n", childpid);
|
||||
DBG("Created child with PID %d\n", childpid);
|
||||
wait(NULL);
|
||||
putlog("child %d died\n", childpid);
|
||||
time_t t = time(NULL);
|
||||
if(t - lastd > 600) // at least 10 minutes of work
|
||||
putlog("child %d died\n", childpid);
|
||||
lastd = t;
|
||||
WARNX("Child %d died\n", childpid);
|
||||
sleep(1);
|
||||
}else{
|
||||
@@ -74,9 +81,9 @@ int main(int argc, char **argv){
|
||||
|
||||
if(GP->device) try_connect(GP->device);
|
||||
if(ping()){
|
||||
putlog("Can't write command PING");
|
||||
ERRX(_("Can't write command PING"));
|
||||
}
|
||||
putlog("Child %d connected to %s", getpid(), GP->device);
|
||||
daemonize(GP->port);
|
||||
signals(0); // newer reached
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user