From ca5d5ce59553f5f6902a78ae8c4fe200775f9627 Mon Sep 17 00:00:00 2001 From: Michael Jerris Date: Fri, 19 Jan 2007 12:59:49 +0000 Subject: [PATCH] =?UTF-8?q?added=20no=20fork=20mode=20to=20the=20executabl?= =?UTF-8?q?e=20so=20it=20can=20be=20used=20w/=20sipx=20watchdog=20service.?= =?UTF-8?q?=20=20This=20mode=20is=20not=20available=20on=20windows=20as=20?= =?UTF-8?q?we=20do=20not=20fork=20on=20windows=20regardless.=20=20Thanks?= =?UTF-8?q?=20to=20Pawe=C5=82=20Pier=C5=9Bcionek=20for=20the=20contributio?= =?UTF-8?q?n.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3999 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/switch.c b/src/switch.c index 4a584c05ad..9aa32131d1 100644 --- a/src/switch.c +++ b/src/switch.c @@ -25,6 +25,7 @@ * * Anthony Minessale II * Michael Jerris + * Pawel Pierscionek * * * switch.c -- Main @@ -194,7 +195,10 @@ int main(int argc, char *argv[]) { char pid_path[256] = ""; // full path to the pid file const char *err = NULL; // error value for return from freeswitch initialization - int bg = 0; // TRUE if we are running in background mode +#ifndef WIN32 + int nf = 0; // TRUE if we are running in nofork mode +#endif + int nc = 0; // TRUE if we are running in noconsole mode int vg = 0; // TRUE if we are running in vg mode FILE *f; // file handle to the pid file pid_t pid = 0; // @@ -254,6 +258,11 @@ int main(int argc, char *argv[]) exit(0); } } +#else + + if (argv[x] && !strcmp(argv[x], "-nf")) { + nf++; + } #endif if (argv[x] && !strcmp(argv[x], "-hp")) { set_high_priority(); @@ -264,8 +273,8 @@ int main(int argc, char *argv[]) } if (argv[x] && !strcmp(argv[x], "-nc")) { - bg++; - } + nc++; + } if (argv[x] && !strcmp(argv[x], "-vg")) { vg++; @@ -276,7 +285,7 @@ int main(int argc, char *argv[]) return freeswitch_kill_background(); } - if (bg) { + if (nc) { signal(SIGHUP, handle_SIGHUP); signal(SIGTERM, handle_SIGHUP); @@ -284,14 +293,14 @@ int main(int argc, char *argv[]) #ifdef WIN32 FreeConsole(); #else - if ((pid = fork())) { + if (!nf && (pid = fork())) { fprintf(stderr, "%d Backgrounding.\n", (int)pid); exit(0); } #endif } - if (switch_core_init_and_modload(bg ? lfile : NULL, &err) != SWITCH_STATUS_SUCCESS) { + if (switch_core_init_and_modload(nc ? lfile : NULL, &err) != SWITCH_STATUS_SUCCESS) { fprintf(stderr, "Cannot Initilize [%s]\n", err); return 255; } @@ -305,7 +314,7 @@ int main(int argc, char *argv[]) fprintf(f, "%d", pid = getpid()); fclose(f); - switch_core_runtime_loop(bg); + switch_core_runtime_loop(nc); return switch_core_destroy(vg); }