diff --git a/daemon/Makefile b/daemon/Makefile index a2bcdd889..25d9c9a44 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -68,7 +68,7 @@ endif SRCS= main.c kernel.c poller.c aux.c control_tcp.c streambuf.c call.c control_udp.c redis.c \ bencode.c cookie_cache.c udp_listener.c control_ng.c sdp.c str.c stun.c rtcp.c \ crypto.c rtp.c call_interfaces.c dtls.c log.c cli.c graphite.c ice.c socket.c \ - media_socket.c rtcp_xr.c homer.c recording.c rtplib.c loglib.c + media_socket.c rtcp_xr.c homer.c recording.c rtplib.c loglib.c auxlib.c OBJS= $(SRCS:.c=.o) diff --git a/daemon/auxlib.c b/daemon/auxlib.c new file mode 120000 index 000000000..16d8d732c --- /dev/null +++ b/daemon/auxlib.c @@ -0,0 +1 @@ +../lib/auxlib.c \ No newline at end of file diff --git a/daemon/main.c b/daemon/main.c index 8d1f6a79c..94951544e 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -31,6 +31,7 @@ #include "media_socket.h" #include "homer.h" #include "recording.h" +#include "auxlib.h" @@ -469,30 +470,6 @@ static void options(int *argc, char ***argv) { } -static void daemonize(void) { - if (fork()) - _exit(0); - write_log = (write_log_t *) syslog; - stdin = freopen("/dev/null", "r", stdin); - stdout = freopen("/dev/null", "w", stdout); - stderr = freopen("/dev/null", "w", stderr); - setpgrp(); -} - -static void wpidfile(void) { - FILE *fp; - - if (!pidfile) - return; - - fp = fopen(pidfile, "w"); - if (fp) { - fprintf(fp, "%u\n", getpid()); - fclose(fp); - } -} - - static void cb_openssl_threadid(CRYPTO_THREADID *tid) { pthread_t me; @@ -665,7 +642,7 @@ no_kernel: if (!foreground) daemonize(); - wpidfile(); + wpidfile(pidfile); ctx->m->homer = homer_sender_new(&homer_ep, homer_protocol, homer_id); @@ -731,7 +708,8 @@ int main(int argc, char **argv) { threads_join_all(0); } - redis_notify_event_base_action(ctx.m, EVENT_BASE_LOOPBREAK); + if (!is_addr_unspecified(&redis_ep.address)) + redis_notify_event_base_action(ctx.m, EVENT_BASE_LOOPBREAK); threads_join_all(1); diff --git a/lib/auxlib.c b/lib/auxlib.c new file mode 100644 index 000000000..2f20a9167 --- /dev/null +++ b/lib/auxlib.c @@ -0,0 +1,28 @@ +#include "auxlib.h" +#include +#include +#include +#include "loglib.h" + +void daemonize(void) { + if (fork()) + _exit(0); + write_log = (write_log_t *) syslog; + stdin = freopen("/dev/null", "r", stdin); + stdout = freopen("/dev/null", "w", stdout); + stderr = freopen("/dev/null", "w", stderr); + setpgrp(); +} + +void wpidfile(const char *pidfile) { + FILE *fp; + + if (!pidfile) + return; + + fp = fopen(pidfile, "w"); + if (fp) { + fprintf(fp, "%u\n", getpid()); + fclose(fp); + } +} diff --git a/lib/auxlib.h b/lib/auxlib.h new file mode 100644 index 000000000..823565a09 --- /dev/null +++ b/lib/auxlib.h @@ -0,0 +1,9 @@ +#ifndef _AUXLIB_H_ +#define _AUXLIB_H_ + + +void daemonize(void); +void wpidfile(const char *pidfile); + + +#endif diff --git a/recording-daemon/Makefile b/recording-daemon/Makefile index 5176513e6..7251a774c 100644 --- a/recording-daemon/Makefile +++ b/recording-daemon/Makefile @@ -36,7 +36,7 @@ ifneq ($(DBG),yes) endif SRCS= epoll.c garbage.c inotify.c main.c metafile.c stream.c recaux.c rtplib.c packet.c \ - decoder.c loglib.c + decoder.c loglib.c auxlib.c OBJS= $(SRCS:.c=.o) diff --git a/recording-daemon/auxlib.c b/recording-daemon/auxlib.c new file mode 120000 index 000000000..16d8d732c --- /dev/null +++ b/recording-daemon/auxlib.c @@ -0,0 +1 @@ +../lib/auxlib.c \ No newline at end of file diff --git a/recording-daemon/main.c b/recording-daemon/main.c index c6b7718b9..e7f10d510 100644 --- a/recording-daemon/main.c +++ b/recording-daemon/main.c @@ -14,6 +14,7 @@ #include "metafile.h" #include "garbage.h" #include "loglib.h" +#include "auxlib.h" @@ -49,6 +50,7 @@ static void setup(void) { epoll_setup(); inotify_setup(); av_log_set_callback(avlog_ilog); + openlog("rtpengine-recording", LOG_PID | LOG_NDELAY, LOG_DAEMON); } @@ -104,6 +106,8 @@ static void cleanup(void) { int main() { setup(); + daemonize(); + //wpidfile(); for (int i = 0; i < NUM_THREADS; i++) start_poller_thread();