Change netdaemon to poll & work with libusefull_macros, add weatherdaemon

This commit is contained in:
Edward Emelianov
2021-01-02 20:04:20 +03:00
parent dff0f9e43f
commit 0028ba8a4b
45 changed files with 1835 additions and 168 deletions

View File

@@ -18,19 +18,21 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*/
#include "usefull_macros.h"
#include <signal.h>
#include <stdio.h>
#include <sys/wait.h> // wait
#include <sys/prctl.h> //prctl
#include <usefull_macros.h>
#include "cmdlnopts.h"
#include "socket.h"
#include "term.h"
glob_pars *GP;
void signals(int signo){
restore_console();
restore_tty();
LOG("exit with status %d", signo);
if(ttydescr) close_tty(&ttydescr);
LOGERR("exit with status %d", signo);
exit(signo);
}
@@ -44,12 +46,18 @@ int main(int argc, char **argv){
GP = parse_args(argc, argv);
if(GP->terminal){
if(!GP->device) ERRX(_("Point serial device name"));
try_connect(GP->device);
if(!try_connect(GP->device, GP->tty_speed))
ERRX("Can't connect to device");
run_terminal();
signals(0); // never reached!
}
if(GP->logfile)
Cl_createlog(GP->logfile);
if(GP->logfile){
sl_loglevel lvl = LOGLEVEL_ERR;
for(; GP->verb && lvl < LOGLEVEL_ANY; --GP->verb) ++lvl;
DBG("Loglevel: %d", lvl);
if(!OPENLOG(GP->logfile, lvl, 1)) ERRX("Can't open log file");
LOGERR("Started");
}
#ifndef EBUG
if(daemon(1, 0)){
ERR("daemon()");
@@ -57,10 +65,11 @@ int main(int argc, char **argv){
while(1){ // guard for dead processes
pid_t childpid = fork();
if(childpid){
LOG("create child with PID %d\n", childpid);
LOGDBG("create child with PID %d\n", childpid);
DBG("Created child with PID %d\n", childpid);
wait(NULL);
WARNX("Child %d died\n", childpid);
LOGWARN("Child %d died\n", childpid);
sleep(1);
}else{
prctl(PR_SET_PDEATHSIG, SIGTERM); // send SIGTERM to child when parent dies
@@ -69,7 +78,8 @@ int main(int argc, char **argv){
}
#endif
if(GP->device) try_connect(GP->device);
if(GP->device) if(!try_connect(GP->device, GP->tty_speed))
ERRX("Can't connect to device");;
/*
* INSERT CODE HERE
* connection check & device validation