2003-10-13 11:03:14 -04:00
|
|
|
/*
|
2011-07-09 05:52:26 -04:00
|
|
|
* Copyright (C) 2009-2011 Julien BLACHE <jb@jblache.org>
|
2003-10-13 11:03:14 -04:00
|
|
|
*
|
2009-04-08 07:45:57 -04:00
|
|
|
* Pieces from mt-daapd:
|
2003-12-29 15:41:08 -05:00
|
|
|
* Copyright (C) 2003 Ron Pedde (ron@pedde.com)
|
2003-10-13 11:03:14 -04:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2003-10-19 16:03:54 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2009-06-05 09:25:43 -04:00
|
|
|
# include <config.h>
|
2003-10-19 16:03:54 -04:00
|
|
|
#endif
|
|
|
|
|
2003-10-13 11:03:14 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2009-06-05 09:25:43 -04:00
|
|
|
#include <unistd.h>
|
2003-10-19 16:03:54 -04:00
|
|
|
#include <string.h>
|
2009-06-05 09:25:43 -04:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2003-10-19 16:03:54 -04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2004-02-14 19:51:11 -05:00
|
|
|
#include <sys/wait.h>
|
2009-06-05 09:25:43 -04:00
|
|
|
#include <signal.h>
|
|
|
|
#include <limits.h>
|
2009-04-08 13:22:55 -04:00
|
|
|
#include <grp.h>
|
2009-06-05 11:14:49 -04:00
|
|
|
#include <stdint.h>
|
2009-04-08 13:22:55 -04:00
|
|
|
|
2010-01-09 07:44:56 -05:00
|
|
|
#if defined(__linux__)
|
|
|
|
# include <sys/signalfd.h>
|
2010-01-10 11:49:01 -05:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2010-01-09 07:44:56 -05:00
|
|
|
# include <sys/time.h>
|
|
|
|
# include <sys/event.h>
|
|
|
|
#endif
|
2009-06-05 09:25:43 -04:00
|
|
|
|
|
|
|
#include <pthread.h>
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <event.h>
|
2010-03-07 04:45:15 -05:00
|
|
|
#include <libavutil/log.h>
|
2009-06-05 09:25:43 -04:00
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
|
2010-02-05 12:38:39 -05:00
|
|
|
#include <gcrypt.h>
|
|
|
|
GCRY_THREAD_OPTION_PTHREAD_IMPL;
|
|
|
|
|
2009-04-18 11:30:14 -04:00
|
|
|
#include "conffile.h"
|
2009-06-07 12:58:02 -04:00
|
|
|
#include "db.h"
|
2009-05-08 11:46:32 -04:00
|
|
|
#include "logger.h"
|
2009-04-30 08:51:36 -04:00
|
|
|
#include "misc.h"
|
2014-11-10 16:53:08 -05:00
|
|
|
#include "cache.h"
|
2009-04-19 13:29:44 -04:00
|
|
|
#include "filescanner.h"
|
2009-04-22 15:25:53 -04:00
|
|
|
#include "httpd.h"
|
2010-09-18 10:29:06 -04:00
|
|
|
#include "mdns.h"
|
2010-01-15 13:39:37 -05:00
|
|
|
#include "remote_pairing.h"
|
2010-04-04 07:52:17 -04:00
|
|
|
#include "player.h"
|
2011-06-02 14:56:45 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR < 53
|
|
|
|
# include "ffmpeg_url_evbuffer.h"
|
|
|
|
#endif
|
2009-04-07 13:32:47 -04:00
|
|
|
|
2014-08-15 17:36:54 -04:00
|
|
|
#ifdef LASTFM
|
|
|
|
# include "lastfm.h"
|
|
|
|
#endif
|
2014-03-11 18:20:29 -04:00
|
|
|
#ifdef HAVE_SPOTIFY_H
|
|
|
|
# include "spotify.h"
|
|
|
|
#endif
|
2009-04-07 06:50:46 -04:00
|
|
|
|
2009-06-12 05:09:58 -04:00
|
|
|
#define PIDFILE STATEDIR "/run/" PACKAGE ".pid"
|
2009-04-08 13:22:55 -04:00
|
|
|
|
2009-04-07 11:37:12 -04:00
|
|
|
struct event_base *evbase_main;
|
2010-01-09 05:03:16 -05:00
|
|
|
|
|
|
|
static struct event sig_event;
|
2009-05-03 07:32:00 -04:00
|
|
|
static int main_exit;
|
|
|
|
|
2009-09-21 13:52:05 -04:00
|
|
|
static void
|
|
|
|
version(void)
|
|
|
|
{
|
|
|
|
fprintf(stdout, "Forked Media Server: Version %s\n", VERSION);
|
2011-07-09 06:12:15 -04:00
|
|
|
fprintf(stdout, "Copyright (C) 2009-2011 Julien BLACHE <jb@jblache.org>\n");
|
2009-09-21 13:52:05 -04:00
|
|
|
fprintf(stdout, "Based on mt-daapd, Copyright (C) 2003-2007 Ron Pedde <ron@pedde.com>\n");
|
|
|
|
fprintf(stdout, "Released under the GNU General Public License version 2 or later\n");
|
|
|
|
}
|
2009-04-07 11:37:12 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
static void
|
|
|
|
usage(char *program)
|
|
|
|
{
|
2009-09-21 13:52:05 -04:00
|
|
|
version();
|
|
|
|
printf("\n");
|
|
|
|
printf("Usage: %s [options]\n\n", program);
|
2009-06-05 09:25:43 -04:00
|
|
|
printf("Options:\n");
|
|
|
|
printf(" -d <number> Log level (0-5)\n");
|
|
|
|
printf(" -D <dom,dom..> Log domains\n");
|
|
|
|
printf(" -c <file> Use <file> as the configfile\n");
|
|
|
|
printf(" -P <file> Write PID to specified file\n");
|
|
|
|
printf(" -f Run in foreground\n");
|
|
|
|
printf(" -b <id> ffid to be broadcast\n");
|
|
|
|
printf(" -v Display version information\n");
|
|
|
|
printf("\n\n");
|
|
|
|
printf("Available log domains:\n");
|
|
|
|
logger_domains();
|
|
|
|
printf("\n\n");
|
2003-10-19 16:03:54 -04:00
|
|
|
}
|
|
|
|
|
2009-04-08 13:22:55 -04:00
|
|
|
static int
|
2009-06-05 10:36:07 -04:00
|
|
|
daemonize(int background, char *pidfile)
|
2009-04-08 13:22:55 -04:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
pid_t childpid;
|
2009-12-31 14:12:36 -05:00
|
|
|
pid_t pid_ret;
|
2009-06-05 10:36:07 -04:00
|
|
|
int fd;
|
2009-12-31 14:12:36 -05:00
|
|
|
int ret;
|
2009-06-05 10:36:07 -04:00
|
|
|
char *runas;
|
2009-04-08 13:22:55 -04:00
|
|
|
|
2009-05-05 11:54:20 -04:00
|
|
|
if (background)
|
2009-04-08 13:22:55 -04:00
|
|
|
{
|
|
|
|
fp = fopen(pidfile, "w");
|
|
|
|
if (!fp)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Error opening pidfile (%s): %s\n", pidfile, strerror(errno));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fd = open("/dev/null", O_RDWR, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Error opening /dev/null: %s\n", strerror(errno));
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
signal(SIGTTOU, SIG_IGN);
|
|
|
|
signal(SIGTTIN, SIG_IGN);
|
|
|
|
signal(SIGTSTP, SIG_IGN);
|
|
|
|
|
|
|
|
childpid = fork();
|
|
|
|
|
|
|
|
if (childpid > 0)
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
else if (childpid < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Fork failed: %s\n", strerror(errno));
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-12-31 14:12:36 -05:00
|
|
|
pid_ret = setsid();
|
|
|
|
if (pid_ret == (pid_t) -1)
|
2009-04-08 13:22:55 -04:00
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "setsid() failed: %s\n", strerror(errno));
|
|
|
|
|
|
|
|
close(fd);
|
|
|
|
fclose(fp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2009-05-08 11:46:32 -04:00
|
|
|
logger_detach();
|
|
|
|
|
2009-04-08 13:22:55 -04:00
|
|
|
dup2(fd, STDIN_FILENO);
|
|
|
|
dup2(fd, STDOUT_FILENO);
|
|
|
|
dup2(fd, STDERR_FILENO);
|
|
|
|
|
|
|
|
if (fd > 2)
|
|
|
|
close(fd);
|
|
|
|
|
2009-12-24 15:28:41 -05:00
|
|
|
ret = chdir("/");
|
|
|
|
if (ret < 0)
|
|
|
|
DPRINTF(E_WARN, L_MAIN, "chdir() failed: %s\n", strerror(errno));
|
|
|
|
|
2009-04-08 13:22:55 -04:00
|
|
|
umask(0);
|
|
|
|
|
|
|
|
fprintf(fp, "%d\n", getpid());
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_MAIN, "PID: %d\n", getpid());
|
|
|
|
}
|
|
|
|
|
2011-07-09 05:52:26 -04:00
|
|
|
if (geteuid() == (uid_t) 0)
|
2009-04-08 13:22:55 -04:00
|
|
|
{
|
2011-07-09 05:52:26 -04:00
|
|
|
runas = cfg_getstr(cfg_getsec(cfg, "general"), "uid");
|
|
|
|
|
|
|
|
ret = initgroups(runas, runas_gid);
|
2009-12-31 14:12:36 -05:00
|
|
|
if (ret != 0)
|
2009-04-08 13:22:55 -04:00
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "initgroups() failed: %s\n", strerror(errno));
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-07-09 05:52:26 -04:00
|
|
|
ret = setegid(runas_gid);
|
2009-12-31 14:12:36 -05:00
|
|
|
if (ret != 0)
|
2009-04-08 13:22:55 -04:00
|
|
|
{
|
2009-12-31 14:18:28 -05:00
|
|
|
DPRINTF(E_FATAL, L_MAIN, "setegid() failed: %s\n", strerror(errno));
|
2009-04-08 13:22:55 -04:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-07-09 05:52:26 -04:00
|
|
|
ret = seteuid(runas_uid);
|
2009-12-31 14:12:36 -05:00
|
|
|
if (ret != 0)
|
2009-04-08 13:22:55 -04:00
|
|
|
{
|
2009-12-31 14:18:28 -05:00
|
|
|
DPRINTF(E_FATAL, L_MAIN, "seteuid() failed: %s\n", strerror(errno));
|
2009-04-08 13:22:55 -04:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-06-05 11:14:49 -04:00
|
|
|
static int
|
|
|
|
register_services(char *ffid, int no_rsp, int no_daap)
|
|
|
|
{
|
|
|
|
cfg_t *lib;
|
2010-01-15 12:32:35 -05:00
|
|
|
char *libname;
|
2009-06-05 11:14:49 -04:00
|
|
|
char *password;
|
|
|
|
char *txtrecord[10];
|
|
|
|
char records[9][128];
|
|
|
|
int port;
|
|
|
|
uint32_t hash;
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
srand((unsigned int)time(NULL));
|
|
|
|
|
2010-03-19 14:06:47 -04:00
|
|
|
lib = cfg_getsec(cfg, "library");
|
2009-06-05 11:14:49 -04:00
|
|
|
|
2010-01-15 12:32:35 -05:00
|
|
|
libname = cfg_getstr(lib, "name");
|
|
|
|
hash = djb_hash(libname, strlen(libname));
|
2009-06-05 11:14:49 -04:00
|
|
|
|
|
|
|
for (i = 0; i < (sizeof(records) / sizeof(records[0])); i++)
|
|
|
|
{
|
|
|
|
memset(records[i], 0, 128);
|
|
|
|
txtrecord[i] = records[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
txtrecord[9] = NULL;
|
|
|
|
|
|
|
|
snprintf(txtrecord[0], 128, "txtvers=1");
|
|
|
|
snprintf(txtrecord[1], 128, "Database ID=%0X", hash);
|
|
|
|
snprintf(txtrecord[2], 128, "Machine ID=%0X", hash);
|
2010-01-15 12:32:35 -05:00
|
|
|
snprintf(txtrecord[3], 128, "Machine Name=%s", libname);
|
2009-06-05 11:14:49 -04:00
|
|
|
snprintf(txtrecord[4], 128, "mtd-version=%s", VERSION);
|
|
|
|
snprintf(txtrecord[5], 128, "iTSh Version=131073"); /* iTunes 6.0.4 */
|
|
|
|
snprintf(txtrecord[6], 128, "Version=196610"); /* iTunes 6.0.4 */
|
|
|
|
|
|
|
|
password = cfg_getstr(lib, "password");
|
|
|
|
snprintf(txtrecord[7], 128, "Password=%s", (password) ? "true" : "false");
|
|
|
|
|
|
|
|
if (ffid)
|
|
|
|
snprintf(txtrecord[8], 128, "ffid=%s", ffid);
|
|
|
|
else
|
|
|
|
snprintf(txtrecord[8], 128, "ffid=%08x", rand());
|
|
|
|
|
|
|
|
DPRINTF(E_INFO, L_MAIN, "Registering rendezvous names\n");
|
|
|
|
|
|
|
|
port = cfg_getint(lib, "port");
|
|
|
|
|
|
|
|
/* Register web server service */
|
2010-01-15 12:32:35 -05:00
|
|
|
ret = mdns_register(libname, "_http._tcp", port, txtrecord);
|
2009-06-05 11:14:49 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* Register RSP service */
|
|
|
|
if (!no_rsp)
|
|
|
|
{
|
2010-01-15 12:32:35 -05:00
|
|
|
ret = mdns_register(libname, "_rsp._tcp", port, txtrecord);
|
2009-06-05 11:14:49 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Register DAAP service */
|
|
|
|
if (!no_daap)
|
|
|
|
{
|
2010-01-15 12:32:35 -05:00
|
|
|
ret = mdns_register(libname, "_daap._tcp", port, txtrecord);
|
2009-06-05 11:14:49 -04:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-01-15 13:03:12 -05:00
|
|
|
for (i = 0; i < (sizeof(records) / sizeof(records[0])); i++)
|
|
|
|
{
|
|
|
|
memset(records[i], 0, 128);
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(txtrecord[0], 128, "txtvers=1");
|
2010-01-25 11:47:37 -05:00
|
|
|
snprintf(txtrecord[1], 128, "DbId=%016" PRIX64, libhash);
|
2010-01-15 13:03:12 -05:00
|
|
|
snprintf(txtrecord[2], 128, "DvTy=iTunes");
|
|
|
|
snprintf(txtrecord[3], 128, "DvSv=2306"); /* Magic number! Yay! */
|
|
|
|
snprintf(txtrecord[4], 128, "Ver=131073"); /* iTunes 6.0.4 */
|
|
|
|
snprintf(txtrecord[5], 128, "OSsi=0x1F5"); /* Magic number! Yay! */
|
|
|
|
snprintf(txtrecord[6], 128, "CtlN=%s", libname);
|
|
|
|
|
|
|
|
/* Terminator */
|
|
|
|
txtrecord[7] = NULL;
|
|
|
|
|
|
|
|
/* The group name for the touch-able service advertising is a 64bit hash
|
|
|
|
* but is different from the DbId in iTunes. For now we'll use a hash of
|
|
|
|
* the library name for both, and we'll change that if needed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Use as scratch space for the hash */
|
2010-01-25 11:47:37 -05:00
|
|
|
snprintf(records[7], 128, "%016" PRIX64, libhash);
|
2010-01-15 13:03:12 -05:00
|
|
|
|
|
|
|
/* Register touch-able service, for Remote.app */
|
|
|
|
ret = mdns_register(records[7], "_touch-able._tcp", port, txtrecord);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2009-06-05 11:14:49 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-04-08 13:22:55 -04:00
|
|
|
|
2010-01-09 07:44:56 -05:00
|
|
|
#if defined(__linux__)
|
2009-04-08 07:45:57 -04:00
|
|
|
static void
|
2010-01-09 07:44:56 -05:00
|
|
|
signal_signalfd_cb(int fd, short event, void *arg)
|
2009-04-08 07:45:57 -04:00
|
|
|
{
|
|
|
|
struct signalfd_siginfo info;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
while (read(fd, &info, sizeof(struct signalfd_siginfo)) > 0)
|
|
|
|
{
|
|
|
|
switch (info.ssi_signo)
|
|
|
|
{
|
|
|
|
case SIGCHLD:
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Got SIGCHLD, reaping children\n");
|
|
|
|
|
|
|
|
while (wait3(&status, WNOHANG, NULL) > 0)
|
|
|
|
/* Nothing. */ ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Got SIGTERM or SIGINT\n");
|
|
|
|
|
2009-05-03 07:32:00 -04:00
|
|
|
main_exit = 1;
|
2009-04-08 07:45:57 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGHUP:
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Got SIGHUP\n");
|
|
|
|
|
2009-05-03 07:32:00 -04:00
|
|
|
if (!main_exit)
|
2009-05-08 11:46:32 -04:00
|
|
|
logger_reinit();
|
2009-04-08 07:45:57 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-03 07:32:00 -04:00
|
|
|
if (main_exit)
|
2009-04-08 07:45:57 -04:00
|
|
|
event_base_loopbreak(evbase_main);
|
2010-01-09 05:03:16 -05:00
|
|
|
else
|
|
|
|
event_add(&sig_event, NULL);
|
2009-04-08 07:45:57 -04:00
|
|
|
}
|
|
|
|
|
2010-01-10 11:49:01 -05:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2010-01-09 07:44:56 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
signal_kqueue_cb(int fd, short event, void *arg)
|
|
|
|
{
|
|
|
|
struct timespec ts;
|
|
|
|
struct kevent ke;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
ts.tv_sec = 0;
|
|
|
|
ts.tv_nsec = 0;
|
|
|
|
|
|
|
|
while (kevent(fd, NULL, 0, &ke, 1, &ts) > 0)
|
|
|
|
{
|
|
|
|
switch (ke.ident)
|
|
|
|
{
|
|
|
|
case SIGCHLD:
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Got SIGCHLD, reaping children\n");
|
|
|
|
|
|
|
|
while (wait3(&status, WNOHANG, NULL) > 0)
|
|
|
|
/* Nothing. */ ;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGINT:
|
|
|
|
case SIGTERM:
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Got SIGTERM or SIGINT\n");
|
|
|
|
|
|
|
|
main_exit = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIGHUP:
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Got SIGHUP\n");
|
|
|
|
|
|
|
|
if (!main_exit)
|
|
|
|
logger_reinit();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (main_exit)
|
|
|
|
event_base_loopbreak(evbase_main);
|
|
|
|
else
|
|
|
|
event_add(&sig_event, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
2009-06-05 09:25:43 -04:00
|
|
|
|
2010-09-15 12:20:23 -04:00
|
|
|
|
|
|
|
static int
|
|
|
|
ffmpeg_lockmgr(void **mutex, enum AVLockOp op)
|
|
|
|
{
|
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case AV_LOCK_CREATE:
|
|
|
|
*mutex = malloc(sizeof(pthread_mutex_t));
|
|
|
|
if (!*mutex)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return !!pthread_mutex_init(*mutex, NULL);
|
|
|
|
|
|
|
|
case AV_LOCK_OBTAIN:
|
|
|
|
return !!pthread_mutex_lock(*mutex);
|
|
|
|
|
|
|
|
case AV_LOCK_RELEASE:
|
|
|
|
return !!pthread_mutex_unlock(*mutex);
|
|
|
|
|
|
|
|
case AV_LOCK_DESTROY:
|
|
|
|
pthread_mutex_destroy(*mutex);
|
|
|
|
free(*mutex);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int option;
|
2009-06-05 10:01:54 -04:00
|
|
|
char *configfile;
|
2009-06-05 09:25:43 -04:00
|
|
|
int background;
|
2009-06-05 10:01:54 -04:00
|
|
|
int mdns_no_rsp;
|
|
|
|
int mdns_no_daap;
|
|
|
|
int loglevel;
|
|
|
|
char *logdomains;
|
|
|
|
char *logfile;
|
|
|
|
char *ffid;
|
|
|
|
char *pidfile;
|
2010-02-05 12:38:39 -05:00
|
|
|
const char *gcry_version;
|
2009-06-05 09:25:43 -04:00
|
|
|
sigset_t sigs;
|
|
|
|
int sigfd;
|
2010-01-10 11:49:01 -05:00
|
|
|
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2010-01-09 07:44:56 -05:00
|
|
|
struct kevent ke_sigs[4];
|
|
|
|
#endif
|
2009-06-05 09:25:43 -04:00
|
|
|
int ret;
|
|
|
|
|
2009-06-05 10:01:54 -04:00
|
|
|
struct option option_map[] =
|
|
|
|
{
|
|
|
|
{ "ffid", 1, NULL, 'b' },
|
|
|
|
{ "debug", 1, NULL, 'd' },
|
|
|
|
{ "logdomains", 1, NULL, 'D' },
|
|
|
|
{ "foreground", 0, NULL, 'f' },
|
|
|
|
{ "config", 1, NULL, 'c' },
|
|
|
|
{ "pidfile", 1, NULL, 'P' },
|
|
|
|
{ "version", 0, NULL, 'v' },
|
|
|
|
|
|
|
|
{ "mdns-no-rsp", 0, NULL, 512 },
|
|
|
|
{ "mdns-no-daap", 0, NULL, 513 },
|
|
|
|
|
|
|
|
{ NULL, 0, NULL, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
configfile = CONFFILE;
|
|
|
|
pidfile = PIDFILE;
|
|
|
|
loglevel = -1;
|
|
|
|
logdomains = NULL;
|
|
|
|
logfile = NULL;
|
2009-06-05 09:25:43 -04:00
|
|
|
background = 1;
|
2009-06-05 10:01:54 -04:00
|
|
|
ffid = NULL;
|
|
|
|
mdns_no_rsp = 0;
|
|
|
|
mdns_no_daap = 0;
|
2009-06-05 09:25:43 -04:00
|
|
|
|
2009-06-05 10:01:54 -04:00
|
|
|
while ((option = getopt_long(argc, argv, "D:d:c:P:fb:v", option_map, NULL)) != -1)
|
2009-06-05 09:25:43 -04:00
|
|
|
{
|
|
|
|
switch (option)
|
|
|
|
{
|
2009-06-05 10:01:54 -04:00
|
|
|
case 512:
|
|
|
|
mdns_no_rsp = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 513:
|
|
|
|
mdns_no_daap = 1;
|
|
|
|
break;
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
case 'b':
|
|
|
|
ffid = optarg;
|
2006-07-15 01:56:32 -04:00
|
|
|
break;
|
2006-08-24 23:37:03 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
case 'd':
|
2010-02-02 15:02:24 -05:00
|
|
|
ret = safe_atoi32(optarg, &option);
|
2009-06-05 09:25:43 -04:00
|
|
|
if (ret < 0)
|
|
|
|
fprintf(stderr, "Error: loglevel must be an integer in '-d %s'\n", optarg);
|
|
|
|
else
|
2009-06-05 11:14:49 -04:00
|
|
|
loglevel = option;
|
2005-11-07 00:58:05 -05:00
|
|
|
break;
|
2006-08-24 23:37:03 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
case 'D':
|
2009-05-08 11:46:32 -04:00
|
|
|
logdomains = optarg;
|
2005-11-07 00:58:05 -05:00
|
|
|
break;
|
2006-08-24 23:37:03 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
case 'f':
|
2009-05-05 11:54:20 -04:00
|
|
|
background = 0;
|
2005-11-07 00:58:05 -05:00
|
|
|
break;
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
case 'c':
|
|
|
|
configfile = optarg;
|
2005-11-07 00:58:05 -05:00
|
|
|
break;
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
case 'P':
|
2009-04-08 13:22:55 -04:00
|
|
|
pidfile = optarg;
|
2005-11-07 00:58:05 -05:00
|
|
|
break;
|
2009-04-02 05:04:33 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
case 'v':
|
2009-09-21 13:52:05 -04:00
|
|
|
version();
|
2009-06-05 12:07:36 -04:00
|
|
|
return EXIT_SUCCESS;
|
2007-01-09 13:12:39 -05:00
|
|
|
break;
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
default:
|
2005-11-07 00:58:05 -05:00
|
|
|
usage(argv[0]);
|
2009-06-05 12:07:36 -04:00
|
|
|
return EXIT_FAILURE;
|
2005-11-07 00:58:05 -05:00
|
|
|
break;
|
|
|
|
}
|
2003-10-19 16:03:54 -04:00
|
|
|
}
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
ret = logger_init(NULL, NULL, (loglevel < 0) ? E_LOG : loglevel);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Could not initialize log facility\n");
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
return EXIT_FAILURE;
|
2006-02-27 17:48:42 -05:00
|
|
|
}
|
2005-03-19 23:13:34 -05:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
ret = conffile_load(configfile);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Config file errors; please fix your config\n");
|
|
|
|
|
|
|
|
logger_deinit();
|
2009-06-05 12:07:36 -04:00
|
|
|
return EXIT_FAILURE;
|
2004-03-08 15:36:07 -05:00
|
|
|
}
|
2007-09-07 02:55:25 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
logger_deinit();
|
2003-10-13 11:03:14 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
/* Reinit log facility with configfile values */
|
|
|
|
if (loglevel < 0)
|
|
|
|
loglevel = cfg_getint(cfg_getsec(cfg, "general"), "loglevel");
|
2003-11-26 01:10:58 -05:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
logfile = cfg_getstr(cfg_getsec(cfg, "general"), "logfile");
|
2009-05-04 11:51:42 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
ret = logger_init(logfile, logdomains, loglevel);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Could not reinitialize log facility with config file settings\n");
|
2004-04-13 00:23:36 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
conffile_unload();
|
2009-06-05 12:07:36 -04:00
|
|
|
return EXIT_FAILURE;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
2009-05-08 11:46:32 -04:00
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
/* Set up libevent logging callback */
|
|
|
|
event_set_log_callback(logger_libevent);
|
2003-10-13 11:03:14 -04:00
|
|
|
|
2009-06-12 05:09:58 -04:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "Forked Media Server Version %s taking off\n", VERSION);
|
2009-06-05 09:25:43 -04:00
|
|
|
|
2010-09-15 12:20:23 -04:00
|
|
|
ret = av_lockmgr_register(ffmpeg_lockmgr);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Could not register ffmpeg lock manager callback\n");
|
|
|
|
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto ffmpeg_init_fail;
|
|
|
|
}
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
av_register_all();
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 13)
|
2013-08-14 17:40:55 -04:00
|
|
|
avformat_network_init();
|
2013-11-25 13:43:17 -05:00
|
|
|
#endif
|
2010-03-07 04:45:15 -05:00
|
|
|
av_log_set_callback(logger_ffmpeg);
|
2011-06-02 14:56:45 -04:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR < 53
|
2010-03-07 04:50:50 -05:00
|
|
|
register_ffmpeg_evbuffer_url_protocol();
|
2011-06-02 14:56:45 -04:00
|
|
|
#endif
|
2009-06-05 09:25:43 -04:00
|
|
|
|
2010-02-05 12:38:39 -05:00
|
|
|
/* Initialize libgcrypt */
|
|
|
|
gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread);
|
|
|
|
|
|
|
|
gcry_version = gcry_check_version(GCRYPT_VERSION);
|
|
|
|
if (!gcry_version)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "libgcrypt version mismatch\n");
|
|
|
|
|
2010-09-15 12:05:20 -04:00
|
|
|
ret = EXIT_FAILURE;
|
2010-02-05 12:38:39 -05:00
|
|
|
goto gcrypt_init_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We aren't handling anything sensitive, so give up on secure
|
|
|
|
* memory, which is a scarce system resource.
|
|
|
|
*/
|
|
|
|
gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
|
|
|
|
|
|
|
|
gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
|
|
|
|
|
|
|
|
DPRINTF(E_DBG, L_MAIN, "Initialized with gcrypt %s\n", gcry_version);
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
/* Block signals for all threads except the main one */
|
|
|
|
sigemptyset(&sigs);
|
|
|
|
sigaddset(&sigs, SIGINT);
|
|
|
|
sigaddset(&sigs, SIGHUP);
|
|
|
|
sigaddset(&sigs, SIGCHLD);
|
|
|
|
sigaddset(&sigs, SIGTERM);
|
|
|
|
sigaddset(&sigs, SIGPIPE);
|
|
|
|
ret = pthread_sigmask(SIG_BLOCK, &sigs, NULL);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Error setting signal set\n");
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto signal_block_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Daemonize and drop privileges */
|
2009-06-05 10:36:07 -04:00
|
|
|
ret = daemonize(background, pidfile);
|
2009-06-05 09:25:43 -04:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Could not initialize server\n");
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto daemon_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize libevent (after forking) */
|
|
|
|
evbase_main = event_init();
|
|
|
|
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "mDNS init\n");
|
|
|
|
ret = mdns_init();
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "mDNS init failed\n");
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto mdns_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
2009-06-07 12:58:02 -04:00
|
|
|
/* Initialize the database before starting */
|
|
|
|
DPRINTF(E_INFO, L_MAIN, "Initializing database\n");
|
|
|
|
ret = db_init();
|
|
|
|
if (ret < 0)
|
2009-06-05 09:25:43 -04:00
|
|
|
{
|
2009-06-07 12:58:02 -04:00
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Database init failed\n");
|
2009-06-05 09:25:43 -04:00
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto db_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
2010-01-30 10:47:50 -05:00
|
|
|
/* Open a DB connection for the main thread */
|
|
|
|
ret = db_perthread_init();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Could not perform perthread DB init for main\n");
|
|
|
|
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto db_fail;
|
|
|
|
}
|
|
|
|
|
2014-11-10 16:53:08 -05:00
|
|
|
/* Spawn cache thread */
|
|
|
|
ret = cache_init();
|
2014-08-19 18:21:48 -04:00
|
|
|
if (ret != 0)
|
|
|
|
{
|
2014-11-10 16:53:08 -05:00
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Cache thread failed to start\n");
|
2014-08-19 18:21:48 -04:00
|
|
|
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto cache_fail;
|
|
|
|
}
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
/* Spawn file scanner thread */
|
|
|
|
ret = filescanner_init();
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "File scanner thread failed to start\n");
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto filescanner_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
2014-03-11 18:20:29 -04:00
|
|
|
#ifdef HAVE_SPOTIFY_H
|
|
|
|
/* Spawn Spotify thread */
|
|
|
|
ret = spotify_init();
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_INFO, L_MAIN, "Spotify thread not started\n");;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-04-04 07:52:17 -04:00
|
|
|
/* Spawn player thread */
|
|
|
|
ret = player_init();
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Player thread failed to start\n");
|
|
|
|
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto player_fail;
|
|
|
|
}
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
/* Spawn HTTPd thread */
|
|
|
|
ret = httpd_init();
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "HTTPd thread failed to start\n");
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto httpd_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
2010-01-15 13:39:37 -05:00
|
|
|
/* Start Remote pairing service */
|
|
|
|
ret = remote_pairing_init();
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Remote pairing service failed to start\n");
|
|
|
|
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto remote_fail;
|
|
|
|
}
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
/* Register mDNS services */
|
2009-06-05 11:14:49 -04:00
|
|
|
ret = register_services(ffid, mdns_no_rsp, mdns_no_daap);
|
|
|
|
if (ret < 0)
|
2009-06-05 09:25:43 -04:00
|
|
|
{
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto mdns_reg_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
2010-01-09 07:44:56 -05:00
|
|
|
#if defined(__linux__)
|
2009-06-05 09:25:43 -04:00
|
|
|
/* Set up signal fd */
|
|
|
|
sigfd = signalfd(-1, &sigs, SFD_NONBLOCK | SFD_CLOEXEC);
|
|
|
|
if (sigfd < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Could not setup signalfd: %s\n", strerror(errno));
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto signalfd_fail;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
2010-01-09 07:44:56 -05:00
|
|
|
event_set(&sig_event, sigfd, EV_READ, signal_signalfd_cb, NULL);
|
|
|
|
|
2010-01-10 11:49:01 -05:00
|
|
|
#elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
|
2010-01-09 07:44:56 -05:00
|
|
|
sigfd = kqueue();
|
|
|
|
if (sigfd < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Could not setup kqueue: %s\n", strerror(errno));
|
|
|
|
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto signalfd_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
EV_SET(&ke_sigs[0], SIGINT, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
|
|
|
|
EV_SET(&ke_sigs[1], SIGTERM, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
|
|
|
|
EV_SET(&ke_sigs[2], SIGHUP, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
|
|
|
|
EV_SET(&ke_sigs[3], SIGCHLD, EVFILT_SIGNAL, EV_ADD, 0, 0, NULL);
|
|
|
|
|
|
|
|
ret = kevent(sigfd, ke_sigs, 4, NULL, 0, NULL);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
DPRINTF(E_FATAL, L_MAIN, "Could not register signal events: %s\n", strerror(errno));
|
|
|
|
|
|
|
|
ret = EXIT_FAILURE;
|
|
|
|
goto signalfd_fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
event_set(&sig_event, sigfd, EV_READ, signal_kqueue_cb, NULL);
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 09:25:43 -04:00
|
|
|
event_base_set(evbase_main, &sig_event);
|
|
|
|
event_add(&sig_event, NULL);
|
|
|
|
|
|
|
|
/* Run the loop */
|
|
|
|
event_base_dispatch(evbase_main);
|
|
|
|
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Stopping gracefully\n");
|
2009-06-05 12:07:36 -04:00
|
|
|
ret = EXIT_SUCCESS;
|
2009-06-05 09:25:43 -04:00
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
/*
|
|
|
|
* On a clean shutdown, bring mDNS down first to give a chance
|
|
|
|
* to the clients to perform a clean shutdown on their end
|
|
|
|
*/
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "mDNS deinit\n");
|
|
|
|
mdns_deinit();
|
|
|
|
|
|
|
|
signalfd_fail:
|
|
|
|
mdns_reg_fail:
|
2010-01-15 13:39:37 -05:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "Remote pairing deinit\n");
|
|
|
|
remote_pairing_deinit();
|
|
|
|
|
|
|
|
remote_fail:
|
2009-06-05 09:25:43 -04:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "HTTPd deinit\n");
|
|
|
|
httpd_deinit();
|
|
|
|
|
2010-07-30 11:47:23 -04:00
|
|
|
httpd_fail:
|
2010-04-04 07:52:17 -04:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "Player deinit\n");
|
|
|
|
player_deinit();
|
|
|
|
|
2010-07-30 11:47:23 -04:00
|
|
|
player_fail:
|
2014-08-15 17:36:54 -04:00
|
|
|
#ifdef LASTFM
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "LastFM deinit\n");
|
|
|
|
lastfm_deinit();
|
|
|
|
#endif
|
2014-03-11 18:20:29 -04:00
|
|
|
#ifdef HAVE_SPOTIFY_H
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Spotify deinit\n");
|
|
|
|
spotify_deinit();
|
|
|
|
#endif
|
2009-06-05 09:25:43 -04:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "File scanner deinit\n");
|
|
|
|
filescanner_deinit();
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
filescanner_fail:
|
2014-11-10 16:53:08 -05:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "Cache deinit\n");
|
|
|
|
cache_deinit();
|
2014-08-19 18:21:48 -04:00
|
|
|
|
|
|
|
cache_fail:
|
2010-04-26 12:24:09 -04:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "Database deinit\n");
|
2010-01-30 10:47:50 -05:00
|
|
|
db_perthread_deinit();
|
2010-04-26 12:24:09 -04:00
|
|
|
db_deinit();
|
2014-08-19 18:21:48 -04:00
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
db_fail:
|
|
|
|
if (ret == EXIT_FAILURE)
|
|
|
|
{
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "mDNS deinit\n");
|
|
|
|
mdns_deinit();
|
|
|
|
}
|
|
|
|
|
|
|
|
mdns_fail:
|
|
|
|
daemon_fail:
|
2009-06-05 09:25:43 -04:00
|
|
|
if (background)
|
|
|
|
{
|
2009-12-31 14:17:22 -05:00
|
|
|
ret = seteuid(0);
|
2009-06-05 09:25:43 -04:00
|
|
|
if (ret < 0)
|
2009-12-31 14:17:22 -05:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "seteuid() failed: %s\n", strerror(errno));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = unlink(pidfile);
|
|
|
|
if (ret < 0)
|
|
|
|
DPRINTF(E_LOG, L_MAIN, "Could not unlink PID file %s: %s\n", pidfile, strerror(errno));
|
|
|
|
}
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
signal_block_fail:
|
2010-09-15 12:05:20 -04:00
|
|
|
gcrypt_init_fail:
|
2013-11-25 13:43:17 -05:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR >= 54 || (LIBAVFORMAT_VERSION_MAJOR == 53 && LIBAVFORMAT_VERSION_MINOR >= 13)
|
2013-08-14 17:40:55 -04:00
|
|
|
avformat_network_deinit();
|
2013-11-25 13:43:17 -05:00
|
|
|
#endif
|
2010-09-15 12:20:23 -04:00
|
|
|
av_lockmgr_register(NULL);
|
|
|
|
|
|
|
|
ffmpeg_init_fail:
|
2009-06-05 09:25:43 -04:00
|
|
|
DPRINTF(E_LOG, L_MAIN, "Exiting.\n");
|
2009-06-05 12:07:36 -04:00
|
|
|
conffile_unload();
|
2009-06-05 09:25:43 -04:00
|
|
|
logger_deinit();
|
|
|
|
|
2009-06-05 12:07:36 -04:00
|
|
|
return ret;
|
2009-06-05 09:25:43 -04:00
|
|
|
}
|