2004-01-28 20:02:12 -05:00
|
|
|
/* Icecast
|
|
|
|
*
|
|
|
|
* This program is distributed under the GNU General Public License, version 2.
|
|
|
|
* A copy of this license is included with this source.
|
|
|
|
*
|
|
|
|
* Copyright 2000-2004, Jack Moffitt <jack@xiph.org,
|
|
|
|
* Michael Smith <msmith@xiph.org>,
|
|
|
|
* oddsock <oddsock@xiph.org>,
|
|
|
|
* Karl Heyes <karl@xiph.org>
|
|
|
|
* and others (see AUTHORS for details).
|
|
|
|
*/
|
|
|
|
|
2003-03-27 12:10:14 -05:00
|
|
|
/* -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
2003-07-20 21:58:54 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2001-09-09 22:21:46 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2003-07-24 12:21:22 -04:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2003-07-16 15:41:59 -04:00
|
|
|
#include "thread/thread.h"
|
|
|
|
#include "avl/avl.h"
|
|
|
|
#include "net/sock.h"
|
|
|
|
#include "net/resolver.h"
|
|
|
|
#include "httpp/httpp.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2002-05-14 07:06:54 -04:00
|
|
|
#ifdef CHUID
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-07-20 21:58:54 -04:00
|
|
|
#include "cfgfile.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
#include "sighandler.h"
|
|
|
|
|
|
|
|
#include "global.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "connection.h"
|
|
|
|
#include "refbuf.h"
|
|
|
|
#include "client.h"
|
2002-08-05 10:48:04 -04:00
|
|
|
#include "slave.h"
|
2001-09-09 22:21:46 -04:00
|
|
|
#include "stats.h"
|
|
|
|
#include "logging.h"
|
2002-08-13 08:46:45 -04:00
|
|
|
#include "xslt.h"
|
2002-08-18 01:06:58 -04:00
|
|
|
#include "fserve.h"
|
2003-05-28 11:04:53 -04:00
|
|
|
#ifdef USE_YP
|
2003-02-02 09:26:54 -05:00
|
|
|
#include "geturl.h"
|
2003-07-24 12:21:22 -04:00
|
|
|
#include "yp.h"
|
2003-03-27 12:10:14 -05:00
|
|
|
#endif
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2002-12-29 09:06:20 -05:00
|
|
|
#include <libxml/xmlmemory.h>
|
|
|
|
|
2001-10-20 02:43:04 -04:00
|
|
|
#ifdef _WIN32
|
2003-12-04 11:24:34 -05:00
|
|
|
/* For getpid() */
|
|
|
|
#include <process.h>
|
2001-10-20 02:43:04 -04:00
|
|
|
#define snprintf _snprintf
|
2003-12-01 18:30:13 -05:00
|
|
|
#define getpid _getpid
|
2001-10-20 02:51:29 -04:00
|
|
|
#endif
|
2001-10-20 02:43:04 -04:00
|
|
|
|
2001-09-09 22:21:46 -04:00
|
|
|
#undef CATMODULE
|
|
|
|
#define CATMODULE "main"
|
|
|
|
|
2003-04-16 23:23:18 -04:00
|
|
|
static void _fatal_error(char *perr)
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
MessageBox(NULL, perr, "Error", MB_OK);
|
|
|
|
#else
|
|
|
|
fprintf(stdout, "%s\n", perr);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-02-07 22:59:17 -05:00
|
|
|
static void _print_usage()
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2004-02-24 16:02:44 -05:00
|
|
|
printf(ICECAST_VERSION_STRING "\n\n");
|
2003-12-29 11:18:48 -05:00
|
|
|
printf("usage: icecast [-h -b -v] -c <file>\n");
|
|
|
|
printf("options:\n");
|
2004-02-24 16:02:44 -05:00
|
|
|
printf("\t-c <file>\tSpecify configuration file\n");
|
|
|
|
printf("\t-h\t\tDisplay usage\n");
|
|
|
|
printf("\t-v\t\tDisplay version info\n");
|
|
|
|
printf("\t-b\t\tRun icecast in the background\n");
|
2003-03-14 21:10:19 -05:00
|
|
|
printf("\n");
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2002-08-18 04:49:25 -04:00
|
|
|
static void _stop_logging(void)
|
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
log_close(errorlog);
|
|
|
|
log_close(accesslog);
|
2002-08-18 04:49:25 -04:00
|
|
|
}
|
|
|
|
|
2002-02-07 22:59:17 -05:00
|
|
|
static void _initialize_subsystems(void)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
log_initialize();
|
|
|
|
thread_initialize();
|
|
|
|
sock_initialize();
|
|
|
|
resolver_initialize();
|
|
|
|
config_initialize();
|
|
|
|
connection_initialize();
|
|
|
|
global_initialize();
|
|
|
|
refbuf_initialize();
|
2002-08-13 08:46:45 -04:00
|
|
|
xslt_initialize();
|
2003-05-28 11:04:53 -04:00
|
|
|
#ifdef USE_YP
|
2003-03-14 21:10:19 -05:00
|
|
|
curl_initialize();
|
2003-03-27 12:10:14 -05:00
|
|
|
#endif
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2002-02-07 22:59:17 -05:00
|
|
|
static void _shutdown_subsystems(void)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2002-08-18 01:06:58 -04:00
|
|
|
fserve_shutdown();
|
2002-08-13 08:46:45 -04:00
|
|
|
xslt_shutdown();
|
2003-03-14 21:10:19 -05:00
|
|
|
refbuf_shutdown();
|
|
|
|
slave_shutdown();
|
2004-01-28 18:23:10 -05:00
|
|
|
stats_shutdown();
|
2004-02-24 16:02:44 -05:00
|
|
|
#ifdef USE_YP
|
|
|
|
curl_shutdown();
|
|
|
|
#endif
|
2002-08-18 04:49:25 -04:00
|
|
|
|
|
|
|
/* Now that these are done, we can stop the loggers. */
|
2003-03-14 21:10:19 -05:00
|
|
|
_stop_logging();
|
2002-08-18 04:49:25 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
global_shutdown();
|
|
|
|
connection_shutdown();
|
|
|
|
config_shutdown();
|
|
|
|
resolver_shutdown();
|
|
|
|
sock_shutdown();
|
|
|
|
thread_shutdown();
|
|
|
|
log_shutdown();
|
2002-12-29 09:06:20 -05:00
|
|
|
|
|
|
|
xmlCleanupParser();
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2004-03-21 21:16:57 -05:00
|
|
|
static int _parse_config_opts(int argc, char **argv, char *filename, int size)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
int i = 1;
|
2004-03-21 21:16:57 -05:00
|
|
|
int processID = 0;
|
|
|
|
int config_ok = 0;
|
|
|
|
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-12-29 11:18:48 -05:00
|
|
|
if (argc < 2) return -1;
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
while (i < argc) {
|
|
|
|
if (strcmp(argv[i], "-b") == 0) {
|
2003-02-02 09:26:54 -05:00
|
|
|
#ifndef WIN32
|
2004-02-24 16:02:44 -05:00
|
|
|
fprintf(stdout, "Starting icecast2\nDetaching from the console\n");
|
|
|
|
if ((processID = (int)fork()) > 0) {
|
|
|
|
/* exit the parent */
|
2004-03-21 21:16:57 -05:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fprintf(stderr, "FATAL: Unable to fork child!");
|
|
|
|
exit(1);
|
2004-02-24 16:02:44 -05:00
|
|
|
}
|
2003-02-02 09:26:54 -05:00
|
|
|
#endif
|
2003-03-14 21:10:19 -05:00
|
|
|
}
|
2003-12-29 11:18:48 -05:00
|
|
|
if (strcmp(argv[i], "-v") == 0) {
|
|
|
|
fprintf(stdout, "%s\n", ICECAST_VERSION_STRING);
|
2004-02-24 16:02:44 -05:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
if (strcmp(argv[i], "-c") == 0) {
|
|
|
|
if (i + 1 < argc) {
|
|
|
|
strncpy(filename, argv[i + 1], size-1);
|
2002-12-29 03:10:10 -05:00
|
|
|
filename[size-1] = 0;
|
2004-03-21 21:16:57 -05:00
|
|
|
config_ok = 1;
|
2003-03-14 21:10:19 -05:00
|
|
|
} else {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2004-03-21 21:16:57 -05:00
|
|
|
if(config_ok)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return -1;
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2002-02-07 22:59:17 -05:00
|
|
|
static int _start_logging(void)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
char fn_error[FILENAME_MAX];
|
|
|
|
char fn_access[FILENAME_MAX];
|
2004-04-06 21:53:46 -04:00
|
|
|
char buf[1024];
|
2003-04-16 23:23:18 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
ice_config_t *config = config_get_config_unlocked();
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
if(strcmp(config->error_log, "-")) {
|
2002-05-20 20:05:31 -04:00
|
|
|
snprintf(fn_error, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->error_log);
|
2003-03-14 21:10:19 -05:00
|
|
|
errorlog = log_open(fn_error);
|
2002-05-20 20:05:31 -04:00
|
|
|
} else {
|
|
|
|
errorlog = log_open_file(stderr);
|
|
|
|
}
|
2004-04-06 21:53:46 -04:00
|
|
|
|
|
|
|
if (errorlog < 0) {
|
|
|
|
buf[sizeof(buf)-1] = 0;
|
|
|
|
snprintf(buf, sizeof(buf)-1, "FATAL: could not open error logging: %s",
|
|
|
|
strerror(errno));
|
|
|
|
_fatal_error(buf);
|
|
|
|
}
|
|
|
|
log_set_level(errorlog, config->loglevel);
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
if(strcmp(config->access_log, "-")) {
|
2002-05-20 20:05:31 -04:00
|
|
|
snprintf(fn_access, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->access_log);
|
2003-03-14 21:10:19 -05:00
|
|
|
accesslog = log_open(fn_access);
|
2002-05-20 20:05:31 -04:00
|
|
|
} else {
|
|
|
|
accesslog = log_open_file(stderr);
|
|
|
|
}
|
2004-04-06 21:53:46 -04:00
|
|
|
|
|
|
|
if (accesslog < 0) {
|
|
|
|
buf[sizeof(buf)-1] = 0;
|
|
|
|
snprintf(buf, sizeof(buf)-1, "FATAL: could not open access logging: %s",
|
|
|
|
strerror(errno));
|
|
|
|
_fatal_error(buf);
|
|
|
|
}
|
2003-03-14 21:10:19 -05:00
|
|
|
|
|
|
|
log_set_level(errorlog, config->loglevel);
|
|
|
|
log_set_level(accesslog, 4);
|
|
|
|
|
|
|
|
if (errorlog >= 0 && accesslog >= 0) return 1;
|
|
|
|
|
|
|
|
return 0;
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2003-03-09 06:27:06 -05:00
|
|
|
static int _setup_sockets(void)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
ice_config_t *config;
|
2003-03-09 06:27:06 -05:00
|
|
|
int i = 0;
|
|
|
|
int ret = 0;
|
|
|
|
int successful = 0;
|
2003-04-16 23:23:18 -04:00
|
|
|
char pbuf[1024];
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
config = config_get_config_unlocked();
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-09 06:27:06 -05:00
|
|
|
for(i = 0; i < MAX_LISTEN_SOCKETS; i++) {
|
|
|
|
if(config->listeners[i].port <= 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
global.serversock[i] = sock_get_server_socket(
|
|
|
|
config->listeners[i].port, config->listeners[i].bind_address);
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
if (global.serversock[i] == SOCK_ERROR) {
|
2003-04-16 23:23:18 -04:00
|
|
|
memset(pbuf, '\000', sizeof(pbuf));
|
|
|
|
snprintf(pbuf, sizeof(pbuf)-1,
|
|
|
|
"Could not create listener socket on port %d",
|
|
|
|
config->listeners[i].port);
|
|
|
|
_fatal_error(pbuf);
|
2003-03-09 06:27:06 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ret = 1;
|
|
|
|
successful++;
|
|
|
|
}
|
|
|
|
}
|
2003-03-05 08:03:35 -05:00
|
|
|
|
2003-03-09 06:27:06 -05:00
|
|
|
global.server_sockets = successful;
|
2003-03-14 21:10:19 -05:00
|
|
|
|
|
|
|
return ret;
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2002-02-07 22:59:17 -05:00
|
|
|
static int _start_listening(void)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2003-03-09 06:27:06 -05:00
|
|
|
int i;
|
|
|
|
for(i=0; i < global.server_sockets; i++) {
|
2003-03-14 21:10:19 -05:00
|
|
|
if (sock_listen(global.serversock[i], ICE_LISTEN_QUEUE) == SOCK_ERROR)
|
|
|
|
return 0;
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
sock_set_blocking(global.serversock[i], SOCK_NONBLOCK);
|
2003-03-09 06:27:06 -05:00
|
|
|
}
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
return 1;
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2002-05-14 07:06:54 -04:00
|
|
|
/* bind the socket and start listening */
|
2002-08-09 09:14:59 -04:00
|
|
|
static int _server_proc_init(void)
|
2001-09-09 22:21:46 -04:00
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
if (!_setup_sockets())
|
|
|
|
return 0;
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
if (!_start_listening()) {
|
2003-04-16 23:23:18 -04:00
|
|
|
_fatal_error("Failed trying to listen on server socket");
|
2003-03-14 21:10:19 -05:00
|
|
|
return 0;
|
|
|
|
}
|
2002-08-09 09:14:59 -04:00
|
|
|
|
|
|
|
return 1;
|
2002-05-14 07:06:54 -04:00
|
|
|
}
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2002-05-14 07:06:54 -04:00
|
|
|
/* this is the heart of the beast */
|
|
|
|
static void _server_proc(void)
|
|
|
|
{
|
2003-03-09 06:27:06 -05:00
|
|
|
int i;
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
connection_accept_loop();
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-09 06:27:06 -05:00
|
|
|
for(i=0; i < MAX_LISTEN_SOCKETS; i++)
|
2003-03-14 21:10:19 -05:00
|
|
|
sock_close(global.serversock[i]);
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
2002-05-14 07:06:54 -04:00
|
|
|
/* chroot the process. Watch out - we need to do this before starting other
|
2002-05-20 09:25:31 -04:00
|
|
|
* threads. Change uid as well, after figuring out uid _first_ */
|
2002-05-14 07:06:54 -04:00
|
|
|
|
2002-07-23 11:15:11 -04:00
|
|
|
static void _ch_root_uid_setup(void)
|
2002-05-14 07:06:54 -04:00
|
|
|
{
|
2003-03-05 08:03:35 -05:00
|
|
|
ice_config_t *conf = config_get_config_unlocked();
|
2002-05-20 09:25:31 -04:00
|
|
|
#ifdef CHUID
|
|
|
|
struct passwd *user;
|
|
|
|
struct group *group;
|
|
|
|
uid_t uid=-1;
|
|
|
|
gid_t gid=-1;
|
|
|
|
|
|
|
|
if(conf->chuid)
|
|
|
|
{
|
2002-05-20 20:05:31 -04:00
|
|
|
if(conf->user) {
|
|
|
|
user = getpwnam(conf->user);
|
|
|
|
if(user)
|
|
|
|
uid = user->pw_uid;
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Couldn't find user \"%s\" in password file\n", conf->user);
|
|
|
|
}
|
|
|
|
if(conf->group) {
|
|
|
|
group = getgrnam(conf->group);
|
2002-05-14 07:06:54 -04:00
|
|
|
|
2002-05-20 20:05:31 -04:00
|
|
|
if(group)
|
|
|
|
gid = group->gr_gid;
|
|
|
|
else
|
|
|
|
fprintf(stderr, "Couldn't find group \"%s\" in groups file\n", conf->group);
|
|
|
|
}
|
2002-05-20 09:25:31 -04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CHROOT
|
2002-05-14 07:06:54 -04:00
|
|
|
if (conf->chroot)
|
|
|
|
{
|
|
|
|
if(getuid()) /* root check */
|
|
|
|
{
|
|
|
|
fprintf(stderr, "WARNING: Cannot change server root unless running as root.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(chroot(conf->base_dir))
|
|
|
|
{
|
|
|
|
fprintf(stderr,"WARNING: Couldn't change server root: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
fprintf(stdout, "Changed root successfully to \"%s\".\n", conf->base_dir);
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef CHUID
|
2002-05-20 09:25:31 -04:00
|
|
|
|
2002-05-14 07:06:54 -04:00
|
|
|
if(conf->chuid)
|
|
|
|
{
|
|
|
|
if(getuid()) /* root check */
|
|
|
|
{
|
|
|
|
fprintf(stderr, "WARNING: Can't change user id unless you are root.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-05-20 09:25:31 -04:00
|
|
|
if(gid != -1) {
|
|
|
|
if(!setgid(gid))
|
2004-03-09 18:52:20 -05:00
|
|
|
fprintf(stdout, "Changed groupid to %i.\n", (int)gid);
|
2002-05-20 09:25:31 -04:00
|
|
|
else
|
|
|
|
fprintf(stdout, "Error changing groupid: %s.\n", strerror(errno));
|
|
|
|
}
|
2002-05-14 07:06:54 -04:00
|
|
|
|
2002-05-20 09:25:31 -04:00
|
|
|
if(uid != -1) {
|
|
|
|
if(!setuid(uid))
|
2004-03-09 18:52:20 -05:00
|
|
|
fprintf(stdout, "Changed userid to %i.\n", (int)uid);
|
2002-05-20 09:25:31 -04:00
|
|
|
else
|
|
|
|
fprintf(stdout, "Error changing userid: %s.\n", strerror(errno));
|
|
|
|
}
|
2002-05-14 07:06:54 -04:00
|
|
|
}
|
|
|
|
#endif
|
2002-05-20 09:25:31 -04:00
|
|
|
}
|
2002-05-14 07:06:54 -04:00
|
|
|
|
2001-09-09 22:21:46 -04:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2003-03-14 21:10:19 -05:00
|
|
|
int res, ret;
|
2003-12-01 18:30:13 -05:00
|
|
|
ice_config_t *config;
|
|
|
|
char *pidfile = NULL;
|
2003-03-14 21:10:19 -05:00
|
|
|
char filename[512];
|
2003-04-16 23:23:18 -04:00
|
|
|
char pbuf[1024];
|
2003-03-14 21:10:19 -05:00
|
|
|
|
|
|
|
/* parse the '-c icecast.xml' option
|
|
|
|
** only, so that we can read a configfile
|
|
|
|
*/
|
2004-03-21 21:16:57 -05:00
|
|
|
res = _parse_config_opts(argc, argv, filename, 512);
|
2003-03-14 21:10:19 -05:00
|
|
|
if (res == 1) {
|
|
|
|
/* startup all the modules */
|
|
|
|
_initialize_subsystems();
|
|
|
|
|
|
|
|
/* parse the config file */
|
2003-03-05 08:03:35 -05:00
|
|
|
config_get_config();
|
2003-03-14 21:10:19 -05:00
|
|
|
ret = config_initial_parse_file(filename);
|
2003-03-05 08:03:35 -05:00
|
|
|
config_release_config();
|
2003-03-14 21:10:19 -05:00
|
|
|
if (ret < 0) {
|
2003-04-16 23:23:18 -04:00
|
|
|
memset(pbuf, '\000', sizeof(pbuf));
|
|
|
|
snprintf(pbuf, sizeof(pbuf)-1,
|
|
|
|
"FATAL: error parsing config file (%s)", filename);
|
|
|
|
_fatal_error(pbuf);
|
2003-03-14 21:10:19 -05:00
|
|
|
switch (ret) {
|
|
|
|
case CONFIG_EINSANE:
|
2003-04-16 23:23:18 -04:00
|
|
|
_fatal_error("filename was null of blank");
|
2003-03-14 21:10:19 -05:00
|
|
|
break;
|
|
|
|
case CONFIG_ENOROOT:
|
2003-04-16 23:23:18 -04:00
|
|
|
_fatal_error("no root element found");
|
2003-03-14 21:10:19 -05:00
|
|
|
break;
|
|
|
|
case CONFIG_EBADROOT:
|
2003-04-16 23:23:18 -04:00
|
|
|
_fatal_error("root element is not <icecast>");
|
2003-03-14 21:10:19 -05:00
|
|
|
break;
|
|
|
|
default:
|
2003-04-16 23:23:18 -04:00
|
|
|
_fatal_error("XML config parsing error");
|
2003-03-14 21:10:19 -05:00
|
|
|
break;
|
|
|
|
}
|
2002-07-31 11:00:12 -04:00
|
|
|
_shutdown_subsystems();
|
|
|
|
return 1;
|
2003-03-14 21:10:19 -05:00
|
|
|
}
|
|
|
|
} else if (res == -1) {
|
|
|
|
_print_usage();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* override config file options with commandline options */
|
|
|
|
config_parse_cmdline(argc, argv);
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2002-08-09 09:14:59 -04:00
|
|
|
/* Bind socket, before we change userid */
|
|
|
|
if(!_server_proc_init()) {
|
2003-04-16 23:23:18 -04:00
|
|
|
_fatal_error("Server startup failed. Exiting");
|
2002-08-09 09:14:59 -04:00
|
|
|
_shutdown_subsystems();
|
|
|
|
return 1;
|
|
|
|
}
|
2002-05-14 07:06:54 -04:00
|
|
|
|
2002-07-23 11:15:11 -04:00
|
|
|
_ch_root_uid_setup(); /* Change user id and root if requested/possible */
|
2002-05-14 07:06:54 -04:00
|
|
|
|
|
|
|
stats_initialize(); /* We have to do this later on because of threading */
|
2002-08-25 02:12:51 -04:00
|
|
|
fserve_initialize(); /* This too */
|
2002-05-14 07:06:54 -04:00
|
|
|
|
|
|
|
#ifdef CHUID
|
|
|
|
/* We'll only have getuid() if we also have setuid(), it's reasonable to
|
|
|
|
* assume */
|
|
|
|
if(!getuid()) /* Running as root! Don't allow this */
|
|
|
|
{
|
|
|
|
fprintf(stderr, "WARNING: You should not run icecast2 as root\n");
|
|
|
|
fprintf(stderr, "Use the changeowner directive in the config file\n");
|
|
|
|
_shutdown_subsystems();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* setup default signal handlers */
|
|
|
|
sighandler_initialize();
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
if (!_start_logging()) {
|
2003-04-16 23:23:18 -04:00
|
|
|
_fatal_error("FATAL: Could not start logging");
|
2003-03-14 21:10:19 -05:00
|
|
|
_shutdown_subsystems();
|
|
|
|
return 1;
|
|
|
|
}
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-12-01 18:30:13 -05:00
|
|
|
config = config_get_config_unlocked();
|
|
|
|
/* recreate the pid file */
|
|
|
|
if (config->pidfile)
|
|
|
|
{
|
|
|
|
FILE *f;
|
|
|
|
pidfile = strdup (config->pidfile);
|
|
|
|
if (pidfile && (f = fopen (config->pidfile, "w")) != NULL)
|
|
|
|
{
|
2004-03-09 18:52:20 -05:00
|
|
|
fprintf (f, "%d\n", (int)getpid());
|
2003-12-01 18:30:13 -05:00
|
|
|
fclose (f);
|
|
|
|
}
|
|
|
|
}
|
2002-08-05 10:48:04 -04:00
|
|
|
|
2004-02-24 16:02:44 -05:00
|
|
|
INFO0 (ICECAST_VERSION_STRING " server started");
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
/* REM 3D Graphics */
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
/* let her rip */
|
|
|
|
global.running = ICE_RUNNING;
|
2003-06-26 09:33:15 -04:00
|
|
|
|
|
|
|
#ifdef USE_YP
|
|
|
|
/* Startup yp thread */
|
|
|
|
yp_initialize();
|
|
|
|
#endif
|
|
|
|
|
2004-01-28 18:23:10 -05:00
|
|
|
/* Do this after logging init */
|
|
|
|
slave_initialize();
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
_server_proc();
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
INFO0("Shutting down");
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
_shutdown_subsystems();
|
2001-09-09 22:21:46 -04:00
|
|
|
|
2003-12-01 18:30:13 -05:00
|
|
|
if (pidfile)
|
|
|
|
{
|
|
|
|
remove (pidfile);
|
|
|
|
free (pidfile);
|
|
|
|
}
|
|
|
|
|
2003-03-14 21:10:19 -05:00
|
|
|
return 0;
|
2001-09-09 22:21:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|