2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2008-08-28 20:02:43 +02:00
|
|
|
#include "client.h"
|
2008-10-14 22:38:14 +02:00
|
|
|
#include "idle.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "command.h"
|
|
|
|
#include "playlist.h"
|
2008-10-08 11:07:35 +02:00
|
|
|
#include "database.h"
|
2008-10-08 10:48:48 +02:00
|
|
|
#include "update.h"
|
2008-08-26 08:27:09 +02:00
|
|
|
#include "player_thread.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "listen.h"
|
|
|
|
#include "conf.h"
|
|
|
|
#include "path.h"
|
2008-10-15 19:36:33 +02:00
|
|
|
#include "mapper.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "playerData.h"
|
2008-08-26 08:45:14 +02:00
|
|
|
#include "outputBuffer.h"
|
2008-08-26 08:44:12 +02:00
|
|
|
#include "decoder_thread.h"
|
2008-08-26 08:45:14 +02:00
|
|
|
#include "decoder_control.h"
|
2008-08-26 08:44:38 +02:00
|
|
|
#include "player_control.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
#include "stats.h"
|
|
|
|
#include "sig_handlers.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "volume.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "permission.h"
|
2004-05-08 14:00:30 +02:00
|
|
|
#include "replayGain.h"
|
2008-08-26 08:27:08 +02:00
|
|
|
#include "decoder_list.h"
|
2006-07-16 16:57:26 +02:00
|
|
|
#include "audioOutput.h"
|
2008-10-26 19:38:50 +01:00
|
|
|
#include "input_stream.h"
|
2006-07-31 01:32:47 +02:00
|
|
|
#include "state_file.h"
|
2004-11-10 22:58:27 +01:00
|
|
|
#include "tag.h"
|
2004-11-11 03:36:25 +01:00
|
|
|
#include "dbUtils.h"
|
2004-04-16 03:06:14 +02:00
|
|
|
#include "../config.h"
|
2005-12-31 04:23:46 +01:00
|
|
|
#include "utils.h"
|
2006-07-27 02:50:59 +02:00
|
|
|
#include "normalize.h"
|
2007-01-11 21:41:17 +01:00
|
|
|
#include "zeroconf.h"
|
2008-04-12 11:46:11 +02:00
|
|
|
#include "main_notify.h"
|
2008-01-03 08:29:49 +01:00
|
|
|
#include "os_compat.h"
|
2004-02-24 00:41:20 +01:00
|
|
|
|
|
|
|
#define SYSTEM_CONFIG_FILE_LOCATION "/etc/mpd.conf"
|
|
|
|
#define USER_CONFIG_FILE_LOCATION "/.mpdconf"
|
|
|
|
|
|
|
|
typedef struct _Options {
|
2005-03-09 04:13:33 +01:00
|
|
|
int kill;
|
2006-07-19 20:04:15 +02:00
|
|
|
int daemon;
|
|
|
|
int stdOutput;
|
|
|
|
int createDB;
|
2006-08-01 06:18:53 +02:00
|
|
|
int verbose;
|
2004-02-24 00:41:20 +01:00
|
|
|
} Options;
|
|
|
|
|
2006-04-23 00:18:15 +02:00
|
|
|
/*
|
|
|
|
* from git-1.3.0, needed for solaris
|
2006-04-22 23:30:48 +02:00
|
|
|
*/
|
2006-06-04 13:36:06 +02:00
|
|
|
#ifndef HAVE_SETENV
|
2006-07-15 15:16:52 +02:00
|
|
|
static int setenv(const char *name, const char *value, int replace)
|
2006-04-23 00:18:15 +02:00
|
|
|
{
|
|
|
|
int out;
|
|
|
|
size_t namelen, valuelen;
|
|
|
|
char *envstr;
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
if (!name || !value)
|
|
|
|
return -1;
|
2006-04-23 00:18:15 +02:00
|
|
|
if (!replace) {
|
|
|
|
char *oldval = NULL;
|
|
|
|
oldval = getenv(name);
|
2006-07-19 20:04:15 +02:00
|
|
|
if (oldval)
|
|
|
|
return 0;
|
2006-04-23 00:18:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
namelen = strlen(name);
|
|
|
|
valuelen = strlen(value);
|
2006-08-26 08:25:57 +02:00
|
|
|
envstr = xmalloc((namelen + valuelen + 2));
|
2006-07-19 20:04:15 +02:00
|
|
|
if (!envstr)
|
|
|
|
return -1;
|
2006-04-23 00:18:15 +02:00
|
|
|
|
|
|
|
memcpy(envstr, name, namelen);
|
|
|
|
envstr[namelen] = '=';
|
|
|
|
memcpy(envstr + namelen + 1, value, valuelen);
|
|
|
|
envstr[namelen + valuelen + 1] = 0;
|
|
|
|
|
|
|
|
out = putenv(envstr);
|
|
|
|
/* putenv(3) makes the argument string part of the environment,
|
|
|
|
* and changing that string modifies the environment --- which
|
|
|
|
* means we do not own that storage anymore. Do not free
|
|
|
|
* envstr.
|
|
|
|
*/
|
|
|
|
|
|
|
|
return out;
|
2006-04-22 23:30:48 +02:00
|
|
|
}
|
2006-07-20 20:53:56 +02:00
|
|
|
#endif /* HAVE_SETENV */
|
2006-07-19 20:04:15 +02:00
|
|
|
|
|
|
|
static void usage(char *argv[])
|
|
|
|
{
|
|
|
|
ERROR("usage:\n");
|
|
|
|
ERROR(" %s [options] <conf file>\n", argv[0]);
|
|
|
|
ERROR(" %s [options] (searches for ~%s then %s)\n",
|
|
|
|
argv[0], USER_CONFIG_FILE_LOCATION, SYSTEM_CONFIG_FILE_LOCATION);
|
|
|
|
ERROR("\n");
|
|
|
|
ERROR("options:\n");
|
|
|
|
ERROR(" --help this usage statement\n");
|
|
|
|
ERROR(" --kill kill the currently running mpd session\n");
|
|
|
|
ERROR
|
|
|
|
(" --create-db force (re)creation of database and exit\n");
|
|
|
|
ERROR
|
|
|
|
(" --no-create-db don't create database, even if it doesn't exist\n");
|
|
|
|
ERROR(" --no-daemon don't detach from console\n");
|
|
|
|
ERROR(" --stdout print messages to stdout and stderr\n");
|
|
|
|
ERROR(" --verbose verbose logging\n");
|
|
|
|
ERROR(" --version prints version information\n");
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
static void version(void)
|
|
|
|
{
|
2008-10-14 17:21:27 +02:00
|
|
|
LOG(PACKAGE " (MPD: Music Player Daemon) %s\n", VERSION);
|
2006-07-19 20:04:15 +02:00
|
|
|
LOG("\n");
|
2007-04-05 05:22:33 +02:00
|
|
|
LOG("Copyright (C) 2003-2007 Warren Dukes <warren.dukes@gmail.com>\n");
|
2008-10-14 17:21:27 +02:00
|
|
|
LOG("Copyright (C) 2008 Max Kellermann <max@duempel.org>\n");
|
2006-07-19 20:04:15 +02:00
|
|
|
LOG("This is free software; see the source for copying conditions. There is NO\n");
|
|
|
|
LOG("warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
|
|
|
|
LOG("\n");
|
|
|
|
LOG("Supported formats:\n");
|
|
|
|
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_init_all();
|
|
|
|
decoder_plugin_print_all_suffixes(stdout);
|
2006-07-19 20:04:15 +02:00
|
|
|
|
|
|
|
LOG("\n");
|
|
|
|
LOG("Supported outputs:\n");
|
|
|
|
printAllOutputPluginTypes(stdout);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
static void parseOptions(int argc, char **argv, Options * options)
|
|
|
|
{
|
|
|
|
int argcLeft = argc;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-08-03 03:57:52 +02:00
|
|
|
options->verbose = 0;
|
2006-07-19 20:04:15 +02:00
|
|
|
options->daemon = 1;
|
|
|
|
options->stdOutput = 0;
|
|
|
|
options->createDB = 0;
|
2005-03-09 04:13:33 +01:00
|
|
|
options->kill = 0;
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
if (argc > 1) {
|
|
|
|
int i = 1;
|
|
|
|
while (i < argc) {
|
2008-09-23 20:48:12 +02:00
|
|
|
if (!prefixcmp(argv[i], "--")) {
|
2006-07-19 20:04:15 +02:00
|
|
|
if (strcmp(argv[i], "--help") == 0) {
|
|
|
|
usage(argv);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
} else if (strcmp(argv[i], "--kill") == 0) {
|
|
|
|
options->kill++;
|
|
|
|
argcLeft--;
|
|
|
|
} else if (strcmp(argv[i], "--no-daemon") == 0) {
|
|
|
|
options->daemon = 0;
|
|
|
|
argcLeft--;
|
|
|
|
} else if (strcmp(argv[i], "--stdout") == 0) {
|
|
|
|
options->stdOutput = 1;
|
|
|
|
argcLeft--;
|
|
|
|
} else if (strcmp(argv[i], "--create-db") == 0) {
|
|
|
|
options->stdOutput = 1;
|
|
|
|
options->createDB = 1;
|
|
|
|
argcLeft--;
|
|
|
|
} else if (strcmp(argv[i], "--no-create-db") ==
|
|
|
|
0) {
|
|
|
|
options->createDB = -1;
|
|
|
|
argcLeft--;
|
|
|
|
} else if (strcmp(argv[i], "--verbose") == 0) {
|
2006-08-01 06:18:53 +02:00
|
|
|
options->verbose = 1;
|
2006-07-19 20:04:15 +02:00
|
|
|
argcLeft--;
|
|
|
|
} else if (strcmp(argv[i], "--version") == 0) {
|
|
|
|
version();
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
} else {
|
2006-07-31 01:32:39 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"unknown command line option: %s\n",
|
2006-07-19 20:04:15 +02:00
|
|
|
argv[i]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
i++;
|
2004-10-28 07:14:55 +02:00
|
|
|
}
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (argcLeft <= 2) {
|
|
|
|
if (argcLeft == 2) {
|
|
|
|
readConf(argv[argc - 1]);
|
|
|
|
return;
|
|
|
|
} else if (argcLeft == 1) {
|
2005-03-06 20:00:58 +01:00
|
|
|
struct stat st;
|
2006-07-19 20:04:15 +02:00
|
|
|
char *homedir = getenv("HOME");
|
2007-12-28 03:56:25 +01:00
|
|
|
char userfile[MPD_PATH_MAX] = "";
|
2006-07-19 20:04:15 +02:00
|
|
|
if (homedir && (strlen(homedir) +
|
|
|
|
strlen(USER_CONFIG_FILE_LOCATION)) <
|
2007-12-28 03:56:25 +01:00
|
|
|
MPD_PATH_MAX) {
|
2006-07-19 20:04:15 +02:00
|
|
|
strcpy(userfile, homedir);
|
|
|
|
strcat(userfile, USER_CONFIG_FILE_LOCATION);
|
|
|
|
}
|
|
|
|
if (strlen(userfile) && (0 == stat(userfile, &st))) {
|
|
|
|
readConf(userfile);
|
2005-03-06 20:00:58 +01:00
|
|
|
return;
|
2006-07-19 20:04:15 +02:00
|
|
|
} else if (0 == stat(SYSTEM_CONFIG_FILE_LOCATION, &st)) {
|
|
|
|
readConf(SYSTEM_CONFIG_FILE_LOCATION);
|
2005-03-06 20:00:58 +01:00
|
|
|
return;
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
usage(argv);
|
|
|
|
exit(EXIT_FAILURE);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
static void closeAllFDs(void)
|
|
|
|
{
|
|
|
|
int i;
|
2004-06-20 06:37:17 +02:00
|
|
|
int fds = getdtablesize();
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
for (i = 3; i < fds; i++)
|
|
|
|
close(i);
|
2004-06-02 06:05:09 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
static void changeToUser(void)
|
|
|
|
{
|
|
|
|
ConfigParam *param = getConfigParam(CONF_USER);
|
|
|
|
|
|
|
|
if (param && strlen(param->value)) {
|
|
|
|
/* get uid */
|
|
|
|
struct passwd *userpwd;
|
|
|
|
if ((userpwd = getpwnam(param->value)) == NULL) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("no such user \"%s\" at line %i\n", param->value,
|
2006-07-19 20:04:15 +02:00
|
|
|
param->line);
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
if (setgid(userpwd->pw_gid) == -1) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("cannot setgid for user \"%s\" at line %i: %s\n",
|
2006-07-19 20:04:15 +02:00
|
|
|
param->value, param->line, strerror(errno));
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
#ifdef _BSD_SOURCE
|
2006-07-19 20:04:15 +02:00
|
|
|
/* init suplementary groups
|
|
|
|
* (must be done before we change our uid)
|
|
|
|
*/
|
|
|
|
if (initgroups(param->value, userpwd->pw_gid) == -1) {
|
|
|
|
WARNING("cannot init supplementary groups "
|
|
|
|
"of user \"%s\" at line %i: %s\n",
|
|
|
|
param->value, param->line, strerror(errno));
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
#endif
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
/* set uid */
|
|
|
|
if (setuid(userpwd->pw_uid) == -1) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("cannot change to uid of user "
|
2006-07-19 20:04:15 +02:00
|
|
|
"\"%s\" at line %i: %s\n",
|
|
|
|
param->value, param->line, strerror(errno));
|
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2005-03-06 20:00:58 +01:00
|
|
|
/* this is needed by libs such as arts */
|
2006-07-19 20:04:15 +02:00
|
|
|
if (userpwd->pw_dir) {
|
2004-10-31 05:34:54 +01:00
|
|
|
setenv("HOME", userpwd->pw_dir, 1);
|
|
|
|
}
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
2004-06-02 06:05:09 +02:00
|
|
|
}
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
static void openDB(Options * options, char *argv0)
|
|
|
|
{
|
2008-10-08 11:07:55 +02:00
|
|
|
if (options->createDB > 0 || db_load() < 0) {
|
2006-07-19 20:04:15 +02:00
|
|
|
if (options->createDB < 0) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("can't open db file and using "
|
|
|
|
"\"--no-create-db\" command line option\n"
|
|
|
|
"try running \"%s --create-db\"\n", argv0);
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
|
|
|
flushWarningLog();
|
2008-10-08 11:07:55 +02:00
|
|
|
if (db_check() < 0)
|
2006-07-19 20:04:15 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2008-10-08 11:07:55 +02:00
|
|
|
db_init();
|
|
|
|
if (db_save() < 0)
|
2006-07-19 20:04:15 +02:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
if (options->createDB)
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2004-06-02 06:05:09 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
static void daemonize(Options * options)
|
|
|
|
{
|
|
|
|
FILE *fp = NULL;
|
|
|
|
ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
|
|
|
|
|
2006-06-05 22:05:24 +02:00
|
|
|
if (pidFileParam) {
|
|
|
|
/* do this before daemon'izing so we can fail gracefully if we can't
|
|
|
|
* write to the pid file */
|
|
|
|
DEBUG("opening pid file\n");
|
|
|
|
fp = fopen(pidFileParam->value, "w+");
|
2006-07-19 20:04:15 +02:00
|
|
|
if (!fp) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("could not open %s \"%s\" (at line %i) for writing: %s\n",
|
2006-07-19 20:04:15 +02:00
|
|
|
CONF_PID_FILE, pidFileParam->value,
|
|
|
|
pidFileParam->line, strerror(errno));
|
2006-06-05 22:05:24 +02:00
|
|
|
}
|
2005-03-09 04:13:33 +01:00
|
|
|
}
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
if (options->daemon) {
|
|
|
|
int pid;
|
|
|
|
|
|
|
|
fflush(NULL);
|
|
|
|
pid = fork();
|
|
|
|
if (pid > 0)
|
|
|
|
_exit(EXIT_SUCCESS);
|
|
|
|
else if (pid < 0) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("problems fork'ing for daemon!\n");
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (chdir("/") < 0) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("problems changing to root directory\n");
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (setsid() < 0) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("problems setsid'ing\n");
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fflush(NULL);
|
|
|
|
pid = fork();
|
|
|
|
if (pid > 0)
|
|
|
|
_exit(EXIT_SUCCESS);
|
|
|
|
else if (pid < 0) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("problems fork'ing for daemon!\n");
|
2005-03-09 04:13:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG("daemonized!\n");
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
2005-03-09 04:13:33 +01:00
|
|
|
|
2006-06-05 22:05:24 +02:00
|
|
|
if (pidFileParam) {
|
|
|
|
DEBUG("writing pid file\n");
|
|
|
|
fprintf(fp, "%lu\n", (unsigned long)getpid());
|
|
|
|
fclose(fp);
|
|
|
|
}
|
2004-06-02 06:05:09 +02:00
|
|
|
}
|
2004-06-01 01:49:38 +02:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
static void cleanUpPidFile(void)
|
|
|
|
{
|
|
|
|
ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
|
2006-06-05 22:05:24 +02:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
if (!pidFileParam)
|
|
|
|
return;
|
2005-03-09 04:13:33 +01:00
|
|
|
|
|
|
|
DEBUG("cleaning up pid file\n");
|
2006-07-19 20:04:15 +02:00
|
|
|
|
2005-03-09 04:13:33 +01:00
|
|
|
unlink(pidFileParam->value);
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:02 +02:00
|
|
|
static void killFromPidFile(void)
|
2006-07-19 20:04:15 +02:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
ConfigParam *pidFileParam = parseConfigFilePath(CONF_PID_FILE, 0);
|
2005-03-09 04:13:33 +01:00
|
|
|
int pid;
|
|
|
|
|
2006-06-05 22:05:24 +02:00
|
|
|
if (!pidFileParam) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("no pid_file specified in the config file\n");
|
2006-06-05 22:05:24 +02:00
|
|
|
}
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
fp = fopen(pidFileParam->value, "r");
|
|
|
|
if (!fp) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("unable to open %s \"%s\": %s\n",
|
2006-07-19 20:04:15 +02:00
|
|
|
CONF_PID_FILE, pidFileParam->value, strerror(errno));
|
2005-03-09 04:13:33 +01:00
|
|
|
}
|
2006-07-19 20:04:15 +02:00
|
|
|
if (fscanf(fp, "%i", &pid) != 1) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("unable to read the pid from file \"%s\"\n",
|
2006-07-19 20:04:15 +02:00
|
|
|
pidFileParam->value);
|
2005-03-09 04:13:33 +01:00
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
if (kill(pid, SIGTERM)) {
|
2007-05-26 20:15:54 +02:00
|
|
|
FATAL("unable to kill proccess %i: %s\n", pid, strerror(errno));
|
2005-03-09 04:13:33 +01:00
|
|
|
}
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
Options options;
|
2006-08-07 22:49:20 +02:00
|
|
|
clock_t start;
|
2004-06-02 06:05:09 +02:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
closeAllFDs();
|
2004-06-02 06:05:09 +02:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
initConf();
|
2004-06-02 06:05:09 +02:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
parseOptions(argc, argv, &options);
|
2004-06-02 06:05:09 +02:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
if (options.kill)
|
2008-08-26 08:27:02 +02:00
|
|
|
killFromPidFile();
|
2005-03-09 04:13:33 +01:00
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
initStats();
|
2008-08-29 09:38:21 +02:00
|
|
|
tag_lib_init();
|
2006-08-01 06:18:53 +02:00
|
|
|
initLog(options.verbose);
|
2006-07-19 20:04:15 +02:00
|
|
|
|
2007-04-25 20:47:34 +02:00
|
|
|
if (options.createDB <= 0)
|
2006-07-19 20:04:15 +02:00
|
|
|
listenOnPort();
|
|
|
|
|
|
|
|
changeToUser();
|
2004-06-02 06:05:09 +02:00
|
|
|
|
2006-08-01 06:18:53 +02:00
|
|
|
open_log_files(options.stdOutput);
|
2004-06-02 06:05:09 +02:00
|
|
|
|
2005-03-06 20:00:58 +01:00
|
|
|
initPaths();
|
2008-10-15 19:36:33 +02:00
|
|
|
mapper_init();
|
2006-08-06 08:40:11 +02:00
|
|
|
initPermissions();
|
|
|
|
initPlaylist();
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_init_all();
|
2006-08-06 08:40:11 +02:00
|
|
|
|
2008-10-09 19:11:54 +02:00
|
|
|
init_main_notify();
|
|
|
|
|
2006-08-06 08:40:11 +02:00
|
|
|
openDB(&options, argv[0]);
|
|
|
|
|
2008-10-22 21:40:44 +02:00
|
|
|
command_init();
|
2006-08-06 08:40:11 +02:00
|
|
|
initPlayerData();
|
2008-08-26 08:45:14 +02:00
|
|
|
pc_init(buffered_before_play);
|
|
|
|
ob_init(buffered_chunks, &pc.notify);
|
|
|
|
dc_init();
|
2005-11-16 15:43:04 +01:00
|
|
|
initAudioConfig();
|
2006-07-19 20:04:15 +02:00
|
|
|
initAudioDriver();
|
2006-08-06 08:40:11 +02:00
|
|
|
initVolume();
|
2008-08-28 20:03:02 +02:00
|
|
|
client_manager_init();
|
2006-08-06 08:40:11 +02:00
|
|
|
initReplayGainState();
|
2006-07-27 02:50:59 +02:00
|
|
|
initNormalization();
|
2008-10-26 20:34:47 +01:00
|
|
|
input_stream_global_init();
|
2006-07-21 19:48:54 +02:00
|
|
|
|
|
|
|
daemonize(&options);
|
2005-11-16 15:43:04 +01:00
|
|
|
|
2006-08-01 06:18:53 +02:00
|
|
|
setup_log_output(options.stdOutput);
|
2004-06-02 06:05:09 +02:00
|
|
|
|
2006-08-06 08:40:11 +02:00
|
|
|
initSigHandlers();
|
2005-11-18 13:09:05 +01:00
|
|
|
|
2007-06-04 19:41:18 +02:00
|
|
|
initZeroconf();
|
|
|
|
|
2005-11-18 13:09:05 +01:00
|
|
|
openVolumeDevice();
|
2008-08-26 08:44:29 +02:00
|
|
|
decoder_thread_start();
|
2008-08-26 08:27:09 +02:00
|
|
|
player_create();
|
2006-07-31 01:32:47 +02:00
|
|
|
read_state_file();
|
2005-08-23 14:01:37 +02:00
|
|
|
|
2008-08-28 20:03:02 +02:00
|
|
|
while (COMMAND_RETURN_KILL != client_manager_io() &&
|
2008-03-26 11:37:02 +01:00
|
|
|
COMMAND_RETURN_KILL != handlePendingSignals()) {
|
2008-10-14 22:38:14 +02:00
|
|
|
unsigned flags;
|
|
|
|
|
2006-07-19 20:04:15 +02:00
|
|
|
syncPlayerAndPlaylist();
|
2008-08-28 20:03:02 +02:00
|
|
|
client_manager_expire();
|
2008-09-23 22:37:18 +02:00
|
|
|
reap_update_task();
|
2008-10-14 22:38:14 +02:00
|
|
|
|
|
|
|
/* send "idle" notificaions to all subscribed
|
|
|
|
clients */
|
|
|
|
flags = idle_get();
|
|
|
|
if (flags != 0)
|
|
|
|
client_manager_idle_add(flags);
|
2006-07-19 20:04:15 +02:00
|
|
|
}
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-31 01:32:47 +02:00
|
|
|
write_state_file();
|
2006-08-06 08:40:11 +02:00
|
|
|
playerKill();
|
2007-01-11 21:41:17 +01:00
|
|
|
finishZeroconf();
|
2008-08-28 20:03:02 +02:00
|
|
|
client_manager_deinit();
|
2006-07-19 20:04:15 +02:00
|
|
|
closeAllListenSockets();
|
2006-08-15 01:31:08 +02:00
|
|
|
finishPlaylist();
|
2006-07-18 17:50:10 +02:00
|
|
|
|
2006-08-07 22:49:20 +02:00
|
|
|
start = clock();
|
2008-10-08 11:07:55 +02:00
|
|
|
db_finish();
|
|
|
|
DEBUG("db_finish took %f seconds\n",
|
2006-08-06 08:40:11 +02:00
|
|
|
((float)(clock()-start))/CLOCKS_PER_SEC);
|
2006-07-18 17:50:10 +02:00
|
|
|
|
2008-09-24 07:14:11 +02:00
|
|
|
deinit_main_notify();
|
|
|
|
|
2008-10-26 19:30:13 +01:00
|
|
|
input_stream_global_finish();
|
2006-07-27 02:50:59 +02:00
|
|
|
finishNormalization();
|
2006-07-19 20:04:15 +02:00
|
|
|
finishAudioDriver();
|
|
|
|
finishAudioConfig();
|
|
|
|
finishVolume();
|
2008-10-15 19:36:33 +02:00
|
|
|
mapper_finish();
|
2004-02-24 00:41:20 +01:00
|
|
|
finishPaths();
|
|
|
|
finishPermissions();
|
2008-09-24 07:14:11 +02:00
|
|
|
dc_deinit();
|
|
|
|
pc_deinit();
|
2008-10-22 21:40:44 +02:00
|
|
|
command_finish();
|
2008-08-26 08:27:09 +02:00
|
|
|
decoder_plugin_deinit_all();
|
2008-08-26 08:45:14 +02:00
|
|
|
ob_free();
|
2005-03-09 04:13:33 +01:00
|
|
|
cleanUpPidFile();
|
2005-11-18 13:09:05 +01:00
|
|
|
finishConf();
|
2006-07-19 20:04:15 +02:00
|
|
|
|
2006-08-01 06:18:53 +02:00
|
|
|
close_log_files();
|
2006-07-19 20:04:15 +02:00
|
|
|
return EXIT_SUCCESS;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|