mirror of
https://github.com/eddyem/small_tel.git
synced 2026-03-22 09:41:00 +03:00
force to new usefull_macros lib
This commit is contained in:
@@ -27,38 +27,30 @@
|
||||
#include "socket.h"
|
||||
#include "term.h"
|
||||
|
||||
glob_pars *GP;
|
||||
|
||||
void signals(int signo){
|
||||
restore_console();
|
||||
stop_tty();
|
||||
LOGERR("exit with status %d", signo);
|
||||
exit(signo);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
initial_setup();
|
||||
signal(SIGTERM, signals); // kill (-15) - quit
|
||||
signal(SIGHUP, SIG_IGN); // hup - ignore
|
||||
signal(SIGINT, signals); // ctrl+C - quit
|
||||
signal(SIGQUIT, signals); // ctrl+\ - quit
|
||||
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
|
||||
#ifndef EBUG
|
||||
sl_init();
|
||||
char *self = strdup(argv[0]);
|
||||
#endif
|
||||
GP = parse_args(argc, argv);
|
||||
glob_pars *GP = parse_args(argc, argv);
|
||||
sl_check4running(self, GP->pidfile);
|
||||
if(GP->logfile){
|
||||
sl_loglevel lvl = LOGLEVEL_ERR;
|
||||
sl_loglevel_e 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()");
|
||||
}
|
||||
check4running(self, GP->pidfile);
|
||||
signal(SIGTERM, signals); // kill (-15) - quit
|
||||
signal(SIGHUP, SIG_IGN); // hup - ignore
|
||||
signal(SIGINT, signals); // ctrl+C - quit
|
||||
signal(SIGQUIT, signals); // ctrl+\ - quit
|
||||
signal(SIGTSTP, SIG_IGN); // ignore ctrl+Z
|
||||
while(1){ // guard for dead processes
|
||||
pid_t childpid = fork();
|
||||
if(childpid){
|
||||
@@ -75,14 +67,16 @@ int main(int argc, char **argv){
|
||||
}
|
||||
#endif
|
||||
|
||||
if(GP->device) if(!try_connect(GP->device, GP->tty_speed)){
|
||||
LOGERR("Can't connect to device");
|
||||
ERRX("Can't connect to device");
|
||||
}
|
||||
if(!GP->device && !GP->emul){
|
||||
LOGERR("Need serial device name or emulation flag");
|
||||
ERRX("Need serial device name or emulation flag");
|
||||
}
|
||||
|
||||
if(!try_connect(GP->device, GP->tty_speed, GP->emul)){
|
||||
LOGERR("Can't connect to device");
|
||||
ERRX("Can't connect to device");
|
||||
}
|
||||
|
||||
daemonize(GP->port);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user