Re: [Svxlink-devel] debugging a new problem
Brought to you by:
sm0svx
From: Rob J. <pe...@am...> - 2015-05-19 16:04:05
|
Rob Janssen wrote: > > It would also be possible to start a child process to handle other end of the pipes. I.e. make a pipe to a > child process, connect FD 1 and 2 to it just as done now for the loopback, let the child process > to the timestamping and let it exit only when it reads EOF on its input pipe. Then, when the parent > (svxlink or remotetrx) panics, writes something and exits, the child can still cleanly write it in the > file and exit as well. This would probably be the solution that requires the least amount of change. Or maybe even better: let the parent process do the logging and the child process do the actual functionality. (no need to exec, just a fork of the same program as early as possible during startup) Then the parent process can have another functionality: restart the child when it crashes. Probably with some limit counter to make sure it does not restart in an endless loop when something is really wrong. Then, when there is the occasional crash it will be logged in the logfile but the operation is not interrupted. I used a simple program that does only that, at the time a bug in the Voter caused our repeater to crash several times per day. It was very simple: /* restart program when signal6 or signal11 occurs */ #include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> #include <sys/wait.h> int main (int argc, char *argv[]) { int exitstatus; time_t t; char buf[80]; argv++; argc--; do { switch (fork()) { case -1: perror("fork"); exit(-1); case 0: execvp(argv[0],argv); perror("execv"); exit(-1); default: wait(&exitstatus); time(&t); strftime(buf,sizeof(buf),"%F %T",localtime(&t)); fprintf(stderr,"%s %s exited with status %d signal %d\n", buf,argv[0], WEXITSTATUS(exitstatus),WTERMSIG(exitstatus)); break; } } while (WTERMSIG(exitstatus) == 6 || WTERMSIG(exitstatus) == 11); exit (WEXITSTATUS(exitstatus)); } In this case it does not need to do the execvp but can just call the main loop there. Rob |