Commit 5a269462 authored by Thomas B. Rücker's avatar Thomas B. Rücker 😊

This patch closes ticket #1886.

I've rethought the approach and found a much cleaner way. 
We now split handling of command line arguments into two parts.
Only the critical part of getting the config file is done first (and -v as it prevents startup).
The rest (currently only -b) is deferred.

This achieves the important bit why #1886 was created. 
It allows us to log error messages to stderr even if the -b argument is passed.
This is mainly for the case where the logfile or TCP port can't be opened.

svn path=/icecast/trunk/icecast/; revision=18945
parent 144f478a
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
* This program is distributed under the GNU General Public License, version 2. * This program is distributed under the GNU General Public License, version 2.
* A copy of this license is included with this source. * A copy of this license is included with this source.
* *
* Copyright 2000-2004, Jack Moffitt <jack@xiph.org, * Copyright 2000-2013, Jack Moffitt <jack@xiph.org,
* Michael Smith <msmith@xiph.org>, * Michael Smith <msmith@xiph.org>,
* oddsock <oddsock@xiph.org>, * oddsock <oddsock@xiph.org>,
* Karl Heyes <karl@xiph.org> * Karl Heyes <karl@xiph.org>,
* Thomas B. Ruecker <thomas.ruecker@tieto.com>
* and others (see AUTHORS for details). * and others (see AUTHORS for details).
* Copyright 2011-2012, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>, * Copyright 2011-2012, Philipp "ph3-der-loewe" Schafft <lion@lion.leolix.org>,
*/ */
...@@ -151,31 +152,12 @@ void shutdown_subsystems(void) ...@@ -151,31 +152,12 @@ void shutdown_subsystems(void)
static int _parse_config_opts(int argc, char **argv, char *filename, int size) static int _parse_config_opts(int argc, char **argv, char *filename, int size)
{ {
int i = 1; int i;
int config_ok = 0; int config_ok = 0;
background = 0;
if (argc < 2) return -1; if (argc < 2) return -1;
while (i < argc) { for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0) {
#ifndef WIN32
pid_t pid;
fprintf(stdout, "Starting icecast2\nDetaching from the console\n");
pid = fork();
if (pid > 0) {
/* exit the parent */
exit(0);
}
else if(pid < 0) {
fprintf(stderr, "FATAL: Unable to fork child!");
exit(1);
}
background = 1;
#endif
}
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
fprintf(stdout, "%s\n", ICECAST_VERSION_STRING); fprintf(stdout, "%s\n", ICECAST_VERSION_STRING);
exit(0); exit(0);
...@@ -190,7 +172,6 @@ static int _parse_config_opts(int argc, char **argv, char *filename, int size) ...@@ -190,7 +172,6 @@ static int _parse_config_opts(int argc, char **argv, char *filename, int size)
return -1; return -1;
} }
} }
i++;
} }
if(config_ok) if(config_ok)
...@@ -199,6 +180,34 @@ static int _parse_config_opts(int argc, char **argv, char *filename, int size) ...@@ -199,6 +180,34 @@ static int _parse_config_opts(int argc, char **argv, char *filename, int size)
return -1; return -1;
} }
static int _parse_config_opts_remaining(int argc, char **argv, char *filename, int size)
{
int i;
background = 0;
for (i = 1; i < argc; i++) {
if (strcmp(argv[i], "-b") == 0) {
#ifndef WIN32
pid_t pid;
fprintf(stdout, "Starting icecast2\nDetaching from the console\n");
pid = fork();
if (pid > 0) {
/* exit the parent */
exit(0);
}
else if(pid < 0) {
fprintf(stderr, "FATAL: Unable to fork child!");
exit(1);
}
background = 1;
#endif
}
}
return 0;
}
static int _start_logging(void) static int _start_logging(void)
{ {
char fn_error[FILENAME_MAX]; char fn_error[FILENAME_MAX];
...@@ -501,6 +510,9 @@ int main(int argc, char **argv) ...@@ -501,6 +510,9 @@ int main(int argc, char **argv)
return 1; return 1;
} }
/* Delayed command line argument parsing, e.g. background */
_parse_config_opts_remaining(argc, argv, filename, 512);
INFO1 ("%s server started", ICECAST_VERSION_STRING); INFO1 ("%s server started", ICECAST_VERSION_STRING);
/* REM 3D Graphics */ /* REM 3D Graphics */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment