Commit 0a1ba857 authored by Ed "oddsock" Zaleski's avatar Ed "oddsock" Zaleski

printf to stdout not valid with our win32 binary, so lets now use something...

printf to stdout not valid with our win32 binary, so lets now use something that will work on win32.  note that these should only be used up to the point at which logging is started, then everything should go there.

also added a new stat to represent what is currently being sent to the yp server as "what's playing"

svn path=/trunk/icecast/; revision=4613
parent 9431588c
...@@ -42,6 +42,15 @@ ...@@ -42,6 +42,15 @@
#undef CATMODULE #undef CATMODULE
#define CATMODULE "main" #define CATMODULE "main"
static void _fatal_error(char *perr)
{
#ifdef WIN32
MessageBox(NULL, perr, "Error", MB_OK);
#else
fprintf(stdout, "%s\n", perr);
#endif
}
static void _print_usage() static void _print_usage()
{ {
printf("Usage:\n"); printf("Usage:\n");
...@@ -132,6 +141,8 @@ static int _start_logging(void) ...@@ -132,6 +141,8 @@ static int _start_logging(void)
{ {
char fn_error[FILENAME_MAX]; char fn_error[FILENAME_MAX];
char fn_access[FILENAME_MAX]; char fn_access[FILENAME_MAX];
char pbuf[1024];
ice_config_t *config = config_get_config_unlocked(); ice_config_t *config = config_get_config_unlocked();
if(strcmp(config->error_log, "-")) { if(strcmp(config->error_log, "-")) {
...@@ -150,11 +161,14 @@ static int _start_logging(void) ...@@ -150,11 +161,14 @@ static int _start_logging(void)
log_set_level(errorlog, config->loglevel); log_set_level(errorlog, config->loglevel);
log_set_level(accesslog, 4); log_set_level(accesslog, 4);
if (errorlog < 0) if (errorlog < 0) {
fprintf(stderr, "FATAL: could not open %s for error logging\n", fn_error); _fatal_error("FATAL: could not open error logging");
if (accesslog < 0) }
fprintf(stderr, "FATAL: could not open %s for access logging\n", fn_access); if (accesslog < 0) {
memset(pbuf, '\000', sizeof(pbuf));
snprintf(pbuf, sizeof(pbuf)-1, "FATAL: could not open access logging");
_fatal_error(pbuf);
}
if (errorlog >= 0 && accesslog >= 0) return 1; if (errorlog >= 0 && accesslog >= 0) return 1;
return 0; return 0;
...@@ -166,6 +180,7 @@ static int _setup_sockets(void) ...@@ -166,6 +180,7 @@ static int _setup_sockets(void)
int i = 0; int i = 0;
int ret = 0; int ret = 0;
int successful = 0; int successful = 0;
char pbuf[1024];
config = config_get_config_unlocked(); config = config_get_config_unlocked();
...@@ -177,8 +192,11 @@ static int _setup_sockets(void) ...@@ -177,8 +192,11 @@ static int _setup_sockets(void)
config->listeners[i].port, config->listeners[i].bind_address); config->listeners[i].port, config->listeners[i].bind_address);
if (global.serversock[i] == SOCK_ERROR) { if (global.serversock[i] == SOCK_ERROR) {
fprintf(stderr, "Could not create listener socket on port %d\n", memset(pbuf, '\000', sizeof(pbuf));
snprintf(pbuf, sizeof(pbuf)-1,
"Could not create listener socket on port %d",
config->listeners[i].port); config->listeners[i].port);
_fatal_error(pbuf);
return 0; return 0;
} }
else { else {
...@@ -212,7 +230,7 @@ static int _server_proc_init(void) ...@@ -212,7 +230,7 @@ static int _server_proc_init(void)
return 0; return 0;
if (!_start_listening()) { if (!_start_listening()) {
fprintf(stderr, "Failed trying to listen on server socket\n"); _fatal_error("Failed trying to listen on server socket");
return 0; return 0;
} }
...@@ -311,6 +329,7 @@ int main(int argc, char **argv) ...@@ -311,6 +329,7 @@ int main(int argc, char **argv)
{ {
int res, ret; int res, ret;
char filename[512]; char filename[512];
char pbuf[1024];
/* parse the '-c icecast.xml' option /* parse the '-c icecast.xml' option
** only, so that we can read a configfile ** only, so that we can read a configfile
...@@ -325,19 +344,22 @@ int main(int argc, char **argv) ...@@ -325,19 +344,22 @@ int main(int argc, char **argv)
ret = config_initial_parse_file(filename); ret = config_initial_parse_file(filename);
config_release_config(); config_release_config();
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "FATAL: error parsing config file:"); memset(pbuf, '\000', sizeof(pbuf));
snprintf(pbuf, sizeof(pbuf)-1,
"FATAL: error parsing config file (%s)", filename);
_fatal_error(pbuf);
switch (ret) { switch (ret) {
case CONFIG_EINSANE: case CONFIG_EINSANE:
fprintf(stderr, "filename was null or blank\n"); _fatal_error("filename was null of blank");
break; break;
case CONFIG_ENOROOT: case CONFIG_ENOROOT:
fprintf(stderr, "no root element found\n"); _fatal_error("no root element found");
break; break;
case CONFIG_EBADROOT: case CONFIG_EBADROOT:
fprintf(stderr, "root element is not <icecast>\n"); _fatal_error("root element is not <icecast>");
break; break;
default: default:
fprintf(stderr, "parse error\n"); _fatal_error("XML config parsing error");
break; break;
} }
_shutdown_subsystems(); _shutdown_subsystems();
...@@ -353,7 +375,7 @@ int main(int argc, char **argv) ...@@ -353,7 +375,7 @@ int main(int argc, char **argv)
/* Bind socket, before we change userid */ /* Bind socket, before we change userid */
if(!_server_proc_init()) { if(!_server_proc_init()) {
fprintf(stderr, "Server startup failed. Exiting.\n"); _fatal_error("Server startup failed. Exiting");
_shutdown_subsystems(); _shutdown_subsystems();
return 1; return 1;
} }
...@@ -379,7 +401,7 @@ int main(int argc, char **argv) ...@@ -379,7 +401,7 @@ int main(int argc, char **argv)
sighandler_initialize(); sighandler_initialize();
if (!_start_logging()) { if (!_start_logging()) {
fprintf(stderr, "FATAL: Could not start logging\n"); _fatal_error("FATAL: Could not start logging");
_shutdown_subsystems(); _shutdown_subsystems();
return 1; return 1;
} }
......
...@@ -831,7 +831,7 @@ static void _add_yp_info(source_t *source, char *stat_name, ...@@ -831,7 +831,7 @@ static void _add_yp_info(source_t *source, char *stat_name,
source->ypdata[i]->current_song = source->ypdata[i]->current_song =
malloc(strlen((char *)escaped) +1); malloc(strlen((char *)escaped) +1);
strcpy(source->ypdata[i]->current_song, (char *)escaped); strcpy(source->ypdata[i]->current_song, (char *)escaped);
stats_event(source->mount, stat_name, (char *)info); stats_event(source->mount, "yp_currently_playing", (char *)info);
free(escaped); free(escaped);
} }
break; break;
......
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