summaryrefslogtreecommitdiffstats
path: root/watch.c
diff options
context:
space:
mode:
authorAndreas Eversberg2008-09-21 08:57:51 +0200
committerAndreas Eversberg2008-09-21 08:57:51 +0200
commit26c7e0d22ead805ce333ea4248c7311c1eda5de0 (patch)
treee69331f6a522c3d5a8522a21d07932024d974cce /watch.c
parentfixed some layer 2 link issues (diff)
downloadlcr-26c7e0d22ead805ce333ea4248c7311c1eda5de0.tar.gz
lcr-26c7e0d22ead805ce333ea4248c7311c1eda5de0.tar.xz
lcr-26c7e0d22ead805ce333ea4248c7311c1eda5de0.zip
Finished autoconf.
-> Commments are welcome. deleted: Makefile modified: Makefile.am new file: Makefile.in modified: README new file: aclocal.m4 modified: action_vbox.cpp modified: alawulaw.h modified: autogen.sh new file: config.h.in new file: configure modified: configure.ac modified: default/interface.conf modified: default/options.conf modified: dss1.cpp modified: dss1.h modified: extension.c modified: genext.c modified: interface.c modified: interface.h modified: mISDN.cpp modified: mISDN.h modified: main.h new file: mkinstalldirs modified: options.c modified: options.h modified: port.cpp modified: route.c modified: todo.txt modified: tones.c modified: vbox.cpp deleted: watch.c
Diffstat (limited to 'watch.c')
-rw-r--r--watch.c147
1 files changed, 0 insertions, 147 deletions
diff --git a/watch.c b/watch.c
deleted file mode 100644
index e44062e..0000000
--- a/watch.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*****************************************************************************\
-** **
-** Linux-Call-Router **
-** **
-**---------------------------------------------------------------------------**
-** Copyright: Andreas Eversberg **
-** **
-** LCR Watchdog **
-** **
-\*****************************************************************************/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <time.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include "save.h"
-
-time_t now;
-#define GET_NOW() \
- { \
- now = time(&now); \
- }
-
-int quit = 0;
-
-void sighandler(int sigset)
-{
- if (sigset == SIGHUP)
- return;
- if (sigset == SIGPIPE)
- return;
- printf("Signal received: %d\n", sigset);
- quit = 1;
-}
-
-
-int main(int argc, char *argv[])
-{
- int debug = 0;
- int ret;
- char command[256], file[64] = "pbx";
-
- printf("** PBX-Watch ***\n\n");
-
- /* show options */
- if (argc <= 1)
- {
- usage:
- printf("\n");
- printf("Usage: pbxwatch (run | debug) [fork]\n");
- printf("run = Starts PBX4Linux (pbx) and restart it on every crash.\n");
- printf("debug = Starts PBX4Linux using debugger an restarts it on every crash.\n");
- printf(" Log files and back trace are moved into a seperate directory.\n");
- printf("fork = Option to make pbxwatch running as daemon.\n");
- printf("\n");
- return(0);
- }
-
- if (!(strcasecmp(argv[1],"run")))
- debug = 0;
- else
- if (!(strcasecmp(argv[1],"debug")))
- debug = 1;
- else
- goto usage;
-
- /* do fork */
- if (argc > 2)
- if (!(strcasecmp(argv[2],"fork")))
- {
- /* do daemon fork */
- pid_t pid;
-
- pid = fork();
-
- if (pid < 0)
- {
- fprintf(stderr, "Cannot fork!\n");
- exit(EXIT_FAILURE);
- }
- if (pid != 0)
- {
- printf("PBX-Watch: Starting daemon.\n");
- exit(0);
- }
- usleep(200000);
- printf("\n");
- }
-
- /* signal handlers */
- signal(SIGINT,sighandler);
- signal(SIGHUP,sighandler);
- signal(SIGTERM,sighandler);
- signal(SIGPIPE,sighandler);
-
- while(42)
- {
- /* RUN */
- printf("*** RUNNING PBX4LINUX ***\n");
- if (debug)
- {
- /* write debugger batch list */
- SPRINT(command, "echo > /tmp/pbxwatch.batch -e \"handle SIGPIPE nostop\\\\nfile %s\\\\nrun start\\\\nbt\\\\n\"", file);
- system(command);
- SPRINT(command, "gdb --quiet --batch -x \"/tmp/pbxwatch.batch\" 2>&1 | tee %s/crashreport", INSTALL_DATA);
- printf("*** DEBUGGER STARTED ***\n");
- ret = system(command);
- printf("*** DEBUGGER FINISHED ***\n");
- } else
- {
- SCPY(command, file);
- ret = system(command);
- if (ret != 11)
- {
- printf("*** PBX4LINUX exitted with return code %d ***\n", ret);
- break;
- }
- printf("*** PBX4LINUX CRASHED ***\n");
- }
-
- /* LOG */
- printf("*** WRITING LOG ***\n");
- GET_NOW();
- SPRINT(command, "mkdir \"%s/%d\" && mv \"%s/crashreport\" \"%s/%d\" && cp -a \"%s/debug*.log\" \"%s/%d\"\n", INSTALL_DATA, now, INSTALL_DATA, INSTALL_DATA, now, INSTALL_DATA, INSTALL_DATA, now);
- system(command);
-
- /* DELAY */
- printf("*** SLEEPING 10 SECONDS UNTIL RESTART ***\n");
- sleep(10);
- if (quit)
- break;
- }
-
- signal(SIGINT,SIG_DFL);
- signal(SIGHUP,SIG_DFL);
- signal(SIGTERM,SIG_DFL);
- signal(SIGPIPE,SIG_DFL);
-
- return(0);
-}
-
-