提交 ca5d5ce5 authored 作者: Michael Jerris's avatar Michael Jerris

added no fork mode to the executable so it can be used w/ sipx watchdog service.…

added no fork mode to the executable so it can be used w/ sipx watchdog service.  This mode is not available on windows as we do not fork on windows regardless.  Thanks to Paweł Pierścionek for the contribution.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3999 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 680ef8d1
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
* *
* Anthony Minessale II <anthmct@yahoo.com> * Anthony Minessale II <anthmct@yahoo.com>
* Michael Jerris <mike@jerris.com> * Michael Jerris <mike@jerris.com>
* Pawel Pierscionek <pawel@voiceworks.pl>
* *
* *
* switch.c -- Main * switch.c -- Main
...@@ -194,7 +195,10 @@ int main(int argc, char *argv[]) ...@@ -194,7 +195,10 @@ int main(int argc, char *argv[])
{ {
char pid_path[256] = ""; // full path to the pid file char pid_path[256] = ""; // full path to the pid file
const char *err = NULL; // error value for return from freeswitch initialization 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 int vg = 0; // TRUE if we are running in vg mode
FILE *f; // file handle to the pid file FILE *f; // file handle to the pid file
pid_t pid = 0; // pid_t pid = 0; //
...@@ -254,6 +258,11 @@ int main(int argc, char *argv[]) ...@@ -254,6 +258,11 @@ int main(int argc, char *argv[])
exit(0); exit(0);
} }
} }
#else
if (argv[x] && !strcmp(argv[x], "-nf")) {
nf++;
}
#endif #endif
if (argv[x] && !strcmp(argv[x], "-hp")) { if (argv[x] && !strcmp(argv[x], "-hp")) {
set_high_priority(); set_high_priority();
...@@ -264,7 +273,7 @@ int main(int argc, char *argv[]) ...@@ -264,7 +273,7 @@ int main(int argc, char *argv[])
} }
if (argv[x] && !strcmp(argv[x], "-nc")) { if (argv[x] && !strcmp(argv[x], "-nc")) {
bg++; nc++;
} }
if (argv[x] && !strcmp(argv[x], "-vg")) { if (argv[x] && !strcmp(argv[x], "-vg")) {
...@@ -276,7 +285,7 @@ int main(int argc, char *argv[]) ...@@ -276,7 +285,7 @@ int main(int argc, char *argv[])
return freeswitch_kill_background(); return freeswitch_kill_background();
} }
if (bg) { if (nc) {
signal(SIGHUP, handle_SIGHUP); signal(SIGHUP, handle_SIGHUP);
signal(SIGTERM, handle_SIGHUP); signal(SIGTERM, handle_SIGHUP);
...@@ -284,14 +293,14 @@ int main(int argc, char *argv[]) ...@@ -284,14 +293,14 @@ int main(int argc, char *argv[])
#ifdef WIN32 #ifdef WIN32
FreeConsole(); FreeConsole();
#else #else
if ((pid = fork())) { if (!nf && (pid = fork())) {
fprintf(stderr, "%d Backgrounding.\n", (int)pid); fprintf(stderr, "%d Backgrounding.\n", (int)pid);
exit(0); exit(0);
} }
#endif #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); fprintf(stderr, "Cannot Initilize [%s]\n", err);
return 255; return 255;
} }
...@@ -305,7 +314,7 @@ int main(int argc, char *argv[]) ...@@ -305,7 +314,7 @@ int main(int argc, char *argv[])
fprintf(f, "%d", pid = getpid()); fprintf(f, "%d", pid = getpid());
fclose(f); fclose(f);
switch_core_runtime_loop(bg); switch_core_runtime_loop(nc);
return switch_core_destroy(vg); return switch_core_destroy(vg);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论