[FFmpeg-devel] "OPW Qualification Task: Enable daemon mode for FFserver"
Nicolas George
george at nsup.org
Thu Nov 13 12:36:28 CET 2014
Le duodi 22 brumaire, an CCXXIII, Binathi Bingi a écrit :
> From a7c6a1f74902b6df8e4cc62480e8fd6f023905c4 Mon Sep 17 00:00:00 2001
> From: Binathi Bingi <binti179 at gmail.com>
> Date: Tue, 4 Nov 2014 21:42:07 +0530
> Subject: [PATCH] Restore Daemon mode in FFserver
>
> Signed-off-by: Binathi Bingi <binti179 at gmail.com>
>
> Author: Binathi Bingi <binti179 at gmail.com>
> ---
> doc/ffserver.conf | 4 ++++
> doc/ffserver.texi | 11 +++++++----
> ffserver.c | 34 ++++++++++++++++++++++++++++++++++
> ffserver_config.c | 4 ++--
> ffserver_config.h | 1 +
> 5 files changed, 48 insertions(+), 6 deletions(-)
I was about to say that the patch can be applied, but unfortunately another
patch to ffserver was applied very recently, and it no longer applies
cleanly: it needs to be rebased once more. The conflict does not seem severe
though.
Since there is one more iteration, I have added very minor comments below.
Regards,
--
Nicolas George
>
> diff --git a/doc/ffserver.conf b/doc/ffserver.conf
> index b756961..a10bd77 100644
> --- a/doc/ffserver.conf
> +++ b/doc/ffserver.conf
> @@ -25,6 +25,10 @@ MaxBandwidth 1000
> # '-' is the standard output.
> CustomLog -
>
> +# Enable Daemon, to launch FFserver in Daemon mode.
> +# NoDaemon is the default.
> +#Daemon
> +
> ##################################################################
> # Definition of the live feeds. Each live feed contains one video
> # and/or audio sequence coming from an ffmpeg encoder or another
> diff --git a/doc/ffserver.texi b/doc/ffserver.texi
> index 77273d2..9938500 100644
> --- a/doc/ffserver.texi
> +++ b/doc/ffserver.texi
> @@ -404,10 +404,13 @@ If not specified @command{ffserver} will produce no log.
> In case the commandline option @option{-d} is specified this option is
> ignored, and the log is written to standard output.
>
> - at item NoDaemon
> -Set no-daemon mode. This option is currently ignored since now
> - at command{ffserver} will always work in no-daemon mode, and is
> -deprecated.
> + at item Daemon
> +Set Daemon mode. The default is NoDaemon.
> +In daemon mode @command{ffserver} will fork in background upon
> +starting, without the need to specify the "&" shell operator in the
> +command line. In daemon mode also @command{ffserver} will continue to
> +log on stdout, unlike in NoDaemon mode.
I believe that is not completely exact. If I read the code correctly, the
logging works exactly the same in Daemon and NoDaemon mode. Probably best to
just remove the last sentence.
> +
> @end table
>
> @section Feed section
> diff --git a/ffserver.c b/ffserver.c
> index ea2a2ae..32b48ee 100644
> --- a/ffserver.c
> +++ b/ffserver.c
> @@ -3671,6 +3671,7 @@ static void handle_child_exit(int sig)
> static void opt_debug(void)
> {
> config.debug = 1;
> + config.ffserver_daemon = 0;
> snprintf(config.logfilename, sizeof(config.logfilename), "-");
> }
>
> @@ -3737,6 +3738,39 @@ int main(int argc, char **argv)
>
> compute_bandwidth();
>
> + if (config.ffserver_daemon) {
> + pid_t ffserver_id = 0;
> + pid_t sid = 0;
> + int fd;
> + ffserver_id = fork();
> +
> + if (ffserver_id < 0) {
I would be slightly happier with an empty line after the variable
declarations and no empty line between system call and error check. But that
is very minor.
> + ret = AVERROR(errno);
> + av_log(NULL, AV_LOG_ERROR, "Impossible to start in daemon mode: %s\n", av_err2str(ret));
> + exit(1);
> + }
> +
> + if (ffserver_id > 0)
> + exit(0);
> +
> + sid = setsid();
> + if (sid < 0)
> + exit(1);
> +
> + fd = open("/dev/null", O_RDWR,0);
> +
> + if (fd < 0) {
Same here.
> + ret = AVERROR(errno);
> + av_log(NULL, AV_LOG_ERROR, "Unable to reopen file descriptors: %s\n", av_err2str(ret));
> + exit(1);
> + }
> + dup2(fd, 0);
> + dup2(fd, 2);
> + if (strcmp(config.logfilename, "-") != 0)
> + dup2(fd, 1);
> + close(fd);
> + }
> +
> /* signal init */
> signal(SIGPIPE, SIG_IGN);
>
> diff --git a/ffserver_config.c b/ffserver_config.c
> index e44cdf7..f0368c1 100644
> --- a/ffserver_config.c
> +++ b/ffserver_config.c
> @@ -358,8 +358,8 @@ 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, "Daemon")){
> + config->ffserver_daemon = 1;
> } else if (!av_strcasecmp(cmd, "RTSPPort")) {
> ffserver_get_arg(arg, sizeof(arg), p);
> val = atoi(arg);
> diff --git a/ffserver_config.h b/ffserver_config.h
> index 36d61d0..e3957b1 100644
> --- a/ffserver_config.h
> +++ b/ffserver_config.h
> @@ -100,6 +100,7 @@ typedef struct FFServerConfig {
> unsigned int nb_max_http_connections;
> unsigned int nb_max_connections;
> uint64_t max_bandwidth;
> + int ffserver_daemon;
> int debug;
> char logfilename[1024];
> struct sockaddr_in http_addr;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20141113/a132395a/attachment.asc>
More information about the ffmpeg-devel
mailing list