freeswitch: Clean up daemonize().

Whitespace and indentation clean up.

Use EXIT_SUCESS/_FAILURE.

Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
Stefan Knoblich 2012-07-11 00:11:59 +02:00
parent f9d0e249a1
commit b494d46f45

View File

@ -236,43 +236,41 @@ void WINAPI service_main(DWORD numArgs, char **args)
#else #else
void daemonize(int do_wait) static void daemonize(int do_wait)
{ {
int fd; int fd;
pid_t pid; pid_t pid;
if (!do_wait) { if (!do_wait) {
switch (fork()) { switch (fork()) {
case 0: case 0: /* child process */
break; break;
case -1: case -1:
fprintf(stderr, "Error Backgrounding (fork)! %d - %s\n", errno, strerror(errno)); fprintf(stderr, "Error Backgrounding (fork)! %d - %s\n", errno, strerror(errno));
exit(0); exit(EXIT_SUCCESS);
break; break;
default: default: /* parent process */
exit(0); exit(EXIT_SUCCESS);
} }
if (setsid() < 0) { if (setsid() < 0) {
fprintf(stderr, "Error Backgrounding (setsid)! %d - %s\n", errno, strerror(errno)); fprintf(stderr, "Error Backgrounding (setsid)! %d - %s\n", errno, strerror(errno));
exit(0); exit(EXIT_SUCCESS);
} }
} }
pid = fork(); pid = fork();
switch (pid) { switch (pid) {
case 0: case 0: /* child process */
break; break;
case -1: case -1:
fprintf(stderr, "Error Backgrounding (fork2)! %d - %s\n", errno, strerror(errno)); fprintf(stderr, "Error Backgrounding (fork2)! %d - %s\n", errno, strerror(errno));
exit(0); exit(EXIT_SUCCESS);
break; break;
default: default: /* parent process */
{
fprintf(stderr, "%d Backgrounding.\n", (int) pid); fprintf(stderr, "%d Backgrounding.\n", (int) pid);
if (do_wait) { if (do_wait) {
unsigned int sanity = 60; unsigned int sanity = 60;
char *o; char *o;
@ -291,20 +289,15 @@ void daemonize(int do_wait)
} }
sleep(1); sleep(1);
} }
if (!system_ready) {
if (system_ready == 1) {
printf("FreeSWITCH[%d] System Ready pid:%d\n", (int) getpid(), (int) pid);
} else {
printf("FreeSWITCH[%d] Error starting system! pid:%d\n", (int)getpid(), (int) pid); printf("FreeSWITCH[%d] Error starting system! pid:%d\n", (int)getpid(), (int) pid);
kill(pid, 9); kill(pid, 9);
exit(-1); exit(EXIT_FAILURE);
} }
printf("FreeSWITCH[%d] System Ready pid:%d\n", (int) getpid(), (int) pid);
} }
exit(EXIT_SUCCESS);
}
exit(0);
} }
if (do_wait) { if (do_wait) {
@ -317,11 +310,13 @@ void daemonize(int do_wait)
dup2(fd, 0); dup2(fd, 0);
close(fd); close(fd);
} }
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
if (fd != 1) { if (fd != 1) {
dup2(fd, 1); dup2(fd, 1);
close(fd); close(fd);
} }
fd = open("/dev/null", O_WRONLY); fd = open("/dev/null", O_WRONLY);
if (fd != 2) { if (fd != 2) {
dup2(fd, 2); dup2(fd, 2);