ffserver: unify exit path from build_feed_streams()

Exit from main on build_feed_streams() failures & use
standard EXIT_ codes on error out/normal exit.

Signed-off-by: Reynaldo H. Verdejo Pinochet <reynaldo@osg.samsung.com>
This commit is contained in:
Reynaldo H. Verdejo Pinochet 2015-12-15 14:51:18 -08:00
parent c2ad248321
commit 532a283383
1 changed files with 29 additions and 17 deletions

View File

@ -3622,7 +3622,7 @@ static void build_file_streams(void)
} }
/* compute the needed AVStream for each feed */ /* compute the needed AVStream for each feed */
static void build_feed_streams(void) static int build_feed_streams(void)
{ {
FFServerStream *stream, *feed; FFServerStream *stream, *feed;
int i; int i;
@ -3658,7 +3658,7 @@ static void build_feed_streams(void)
int ret = ffio_set_buf_size(s->pb, FFM_PACKET_SIZE); int ret = ffio_set_buf_size(s->pb, FFM_PACKET_SIZE);
if (ret < 0) { if (ret < 0) {
http_log("Failed to set buffer size\n"); http_log("Failed to set buffer size\n");
exit(1); goto bail;
} }
/* Now see if it matches */ /* Now see if it matches */
@ -3723,7 +3723,7 @@ static void build_feed_streams(void)
if (feed->readonly) { if (feed->readonly) {
http_log("Unable to delete feed file '%s' as it is marked readonly\n", http_log("Unable to delete feed file '%s' as it is marked readonly\n",
feed->feed_filename); feed->feed_filename);
exit(1); goto bail;
} }
unlink(feed->feed_filename); unlink(feed->feed_filename);
} }
@ -3733,27 +3733,27 @@ static void build_feed_streams(void)
if (!s) { if (!s) {
http_log("Failed to allocate context\n"); http_log("Failed to allocate context\n");
exit(1); goto bail;
} }
if (feed->readonly) { if (feed->readonly) {
http_log("Unable to create feed file '%s' as it is marked readonly\n", http_log("Unable to create feed file '%s' as it is marked readonly\n",
feed->feed_filename); feed->feed_filename);
exit(1); goto bail;
} }
/* only write the header of the ffm file */ /* only write the header of the ffm file */
if (avio_open(&s->pb, feed->feed_filename, AVIO_FLAG_WRITE) < 0) { if (avio_open(&s->pb, feed->feed_filename, AVIO_FLAG_WRITE) < 0) {
http_log("Could not open output feed file '%s'\n", http_log("Could not open output feed file '%s'\n",
feed->feed_filename); feed->feed_filename);
exit(1); goto bail;
} }
s->oformat = feed->fmt; s->oformat = feed->fmt;
s->nb_streams = feed->nb_streams; s->nb_streams = feed->nb_streams;
s->streams = feed->streams; s->streams = feed->streams;
if (avformat_write_header(s, NULL) < 0) { if (avformat_write_header(s, NULL) < 0) {
http_log("Container doesn't support the required parameters\n"); http_log("Container doesn't support the required parameters\n");
exit(1); goto bail;
} }
/* XXX: need better API */ /* XXX: need better API */
av_freep(&s->priv_data); av_freep(&s->priv_data);
@ -3767,7 +3767,7 @@ static void build_feed_streams(void)
if (fd < 0) { if (fd < 0) {
http_log("Could not open output feed file '%s'\n", http_log("Could not open output feed file '%s'\n",
feed->feed_filename); feed->feed_filename);
exit(1); goto bail;
} }
feed->feed_write_index = FFMAX(ffm_read_write_index(fd), FFM_PACKET_SIZE); feed->feed_write_index = FFMAX(ffm_read_write_index(fd), FFM_PACKET_SIZE);
@ -3778,6 +3778,10 @@ static void build_feed_streams(void)
close(fd); close(fd);
} }
return 0;
bail:
return -1;
} }
/* compute the bandwidth used by each stream */ /* compute the bandwidth used by each stream */
@ -3858,7 +3862,9 @@ static const OptionDef options[] = {
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct sigaction sigact = { { 0 } }; struct sigaction sigact = { { 0 } };
int ret = 0; int cfg_parsed;
int ret = EXIT_FAILURE;
config.filename = av_strdup("/etc/ffserver.conf"); config.filename = av_strdup("/etc/ffserver.conf");
@ -3880,13 +3886,11 @@ int main(int argc, char **argv)
sigact.sa_flags = SA_NOCLDSTOP | SA_RESTART; sigact.sa_flags = SA_NOCLDSTOP | SA_RESTART;
sigaction(SIGCHLD, &sigact, 0); sigaction(SIGCHLD, &sigact, 0);
if ((ret = ffserver_parse_ffconfig(config.filename, &config)) < 0) { if ((cfg_parsed = ffserver_parse_ffconfig(config.filename, &config)) < 0) {
fprintf(stderr, "Error reading configuration file '%s': %s\n", fprintf(stderr, "Error reading configuration file '%s': %s\n",
config.filename, av_err2str(ret)); config.filename, av_err2str(cfg_parsed));
av_freep(&config.filename); goto bail;
exit(1);
} }
av_freep(&config.filename);
/* open log file if needed */ /* open log file if needed */
if (config.logfilename[0] != '\0') { if (config.logfilename[0] != '\0') {
@ -3899,7 +3903,10 @@ int main(int argc, char **argv)
build_file_streams(); build_file_streams();
build_feed_streams(); if (build_feed_streams() < 0) {
http_log("Could not setup feed streams\n");
goto bail;
}
compute_bandwidth(); compute_bandwidth();
@ -3908,8 +3915,13 @@ int main(int argc, char **argv)
if (http_server() < 0) { if (http_server() < 0) {
http_log("Could not start server\n"); http_log("Could not start server\n");
exit(1); goto bail;
} }
return 0; ret=EXIT_SUCCESS;
bail:
av_freep (&config.filename);
avformat_network_deinit();
return ret;
} }