support daemonizing in recording daemon

Change-Id: I9c76d63efe72d6598087a97f8bf93e0958b81fad
changes/03/9903/1
Richard Fuchs 9 years ago
parent 1de1706152
commit ea72733ac0

@ -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)

@ -0,0 +1 @@
../lib/auxlib.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);

@ -0,0 +1,28 @@
#include "auxlib.h"
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#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);
}
}

@ -0,0 +1,9 @@
#ifndef _AUXLIB_H_
#define _AUXLIB_H_
void daemonize(void);
void wpidfile(const char *pidfile);
#endif

@ -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)

@ -0,0 +1 @@
../lib/auxlib.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();

Loading…
Cancel
Save