remove pidfile only when parent process died

This commit is contained in:
Edward Emelianov 2021-10-28 16:40:42 +03:00
parent 01e5b454e2
commit 6aec61d4a4
2 changed files with 7 additions and 4 deletions

View File

@ -31,11 +31,14 @@
#include "processmotors.h" #include "processmotors.h"
glob_pars *GP; // non-static: to use in outhern functions glob_pars *GP; // non-static: to use in outhern functions
static pid_t childpid;
void signals(int signo){ void signals(int signo){
//restore_tty(); //restore_tty();
if(childpid){ // unlink PID-file only from father
unlink(GP->pidfile); unlink(GP->pidfile);
LOGERR("Exit with status %d", signo); LOGERR("Exit with status %d", signo);
}
exit(signo); exit(signo);
} }
@ -81,7 +84,7 @@ int main(int argc, char **argv){
check4running(self, GP->pidfile); check4running(self, GP->pidfile);
FREE(self); FREE(self);
while(1){ // guard for dead processes while(1){ // guard for dead processes
pid_t childpid = fork(); childpid = fork();
if(childpid){ if(childpid){
LOGDBG("Create child with PID %d", childpid); LOGDBG("Create child with PID %d", childpid);
DBG("Created child with PID %d\n", childpid); DBG("Created child with PID %d\n", childpid);

View File

@ -104,7 +104,7 @@ static void *server(void *asock){
} }
int nfd = 1; int nfd = 1;
// max amount of opened fd (+1 for server socket) // max amount of opened fd (+1 for server socket)
#define MAX_FDS (3) #define MAX_FDS (11)
struct pollfd poll_set[MAX_FDS]; struct pollfd poll_set[MAX_FDS];
memset(poll_set, 0, sizeof(poll_set)); memset(poll_set, 0, sizeof(poll_set));
poll_set[0].fd = sock; poll_set[0].fd = sock;