[FFmpeg-devel] "OPW Qualification Task: Enable daemon mode for FFserver"
Binathi Bingi
binti179 at gmail.com
Wed Oct 29 21:44:59 CET 2014
>From 0fb7dcf1f126bd137e2b2025c5cd6cff4af65801 Mon Sep 17 00:00:00 2001
From: Binathi Bingi <binti179 at gmail.com>
Date: Thu, 30 Oct 2014 01:14:08 +0530
Subject: [PATCH] ffserver: enable back deamon mode
---
ffserver.c | 34 ++++++++++++++++++++++++++++++----
ffserver_config.c | 2 --
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/ffserver.c b/ffserver.c
index ea2a2ae..96e312e 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -236,7 +236,7 @@ static int rtp_new_av_stream(HTTPContext *c,
HTTPContext *rtsp_c);
static const char *my_program_name;
-
+static int ffserver_daemon;
static int no_launch;
static int need_to_start_children;
@@ -3671,6 +3671,7 @@ static void handle_child_exit(int sig)
static void opt_debug(void)
{
config.debug = 1;
+ ffserver_daemon = 1;
snprintf(config.logfilename, sizeof(config.logfilename), "-");
}
@@ -3694,7 +3695,7 @@ int main(int argc, char **argv)
{
struct sigaction sigact = { { 0 } };
int ret = 0;
-
+ ffserver_daemon = 1;
config.filename = av_strdup("/etc/ffserver.conf");
parse_loglevel(argc, argv, options);
@@ -3736,10 +3737,35 @@ int main(int argc, char **argv)
build_feed_streams();
compute_bandwidth();
-
+ if(ffserver_daemon){
+ int ffserver_id = 0;
+ pid_t sid = 0;
+
+ ffserver_id = fork(); // Create child process
+
+ if (ffserver_id < 0){
+ printf("fork failed!\n"); //Indication of failure
+ exit(1);
+ }
+
+ if(ffserver_id > 0){ //Parent process need to kill
+ exit(0);
+ }
+
+ sid = setsid(); //set new session
+ if(sid < 0){
+ exit(1); //return failure
+ }
+
+ open ("/dev/null", O_RDWR);
+
+ if (strcmp(config.logfilename, "-") != 0) {
+ close(1);
+ }
+ }
/* signal init */
signal(SIGPIPE, SIG_IGN);
-
+
if (http_server() < 0) {
http_log("Could not start server\n");
exit(1);
diff --git a/ffserver_config.c b/ffserver_config.c
index e44cdf7..e2c78d8 100644
--- a/ffserver_config.c
+++ b/ffserver_config.c
@@ -358,8 +358,6 @@ static int ffserver_parse_config_global(FFServerConfig
*config, const char *cmd,
ffserver_get_arg(arg, sizeof(arg), p);
if (resolve_host(&config->http_addr.sin_addr, arg) != 0)
ERROR("%s:%d: Invalid host/IP address: %s\n", arg);
- } else if (!av_strcasecmp(cmd, "NoDaemon")) {
- WARNING("NoDaemon option has no effect, you should remove it\n");
} else if (!av_strcasecmp(cmd, "RTSPPort")) {
ffserver_get_arg(arg, sizeof(arg), p);
val = atoi(arg);
--
1.9.1
Cheers,
Binathi
More information about the ffmpeg-devel
mailing list