2018-05-24 18:17:54 +00:00
|
|
|
/* myMPD
|
2019-01-21 20:35:51 +00:00
|
|
|
(c) 2018-2019 Juergen Mang <mail@jcgames.de>
|
2018-06-21 21:29:49 +00:00
|
|
|
This project's homepage is: https://github.com/jcorporation/mympd
|
2018-05-24 18:17:54 +00:00
|
|
|
|
2019-01-21 20:35:51 +00:00
|
|
|
myMPD ist fork of: ympd (c) 2013-2014 Andrew Karpow <andy@ndyk.de>
|
|
|
|
ympd project's homepage is: http://www.ympd.org
|
2018-05-24 18:17:54 +00: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; version 2 of the License.
|
|
|
|
|
|
|
|
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.,
|
|
|
|
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2019-01-21 00:20:48 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
|
2018-05-24 18:17:54 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/time.h>
|
2018-06-14 19:56:12 +00:00
|
|
|
#include <pwd.h>
|
2018-08-27 23:45:14 +00:00
|
|
|
#include <grp.h>
|
2018-10-15 22:34:25 +00:00
|
|
|
#include <libgen.h>
|
2019-01-05 00:01:34 +00:00
|
|
|
#include <pthread.h>
|
2019-01-05 12:29:10 +00:00
|
|
|
#include <dirent.h>
|
2018-11-26 15:55:26 +00:00
|
|
|
#include <mpd/client.h>
|
2019-01-08 00:09:43 +00:00
|
|
|
#include <stdbool.h>
|
2018-05-24 18:17:54 +00:00
|
|
|
|
2019-01-08 00:09:43 +00:00
|
|
|
#include "list.h"
|
|
|
|
#include "tiny_queue.h"
|
2019-01-05 12:29:10 +00:00
|
|
|
#include "global.h"
|
2018-05-24 18:17:54 +00:00
|
|
|
#include "mpd_client.h"
|
2019-01-11 00:38:44 +00:00
|
|
|
#include "../dist/src/mongoose/mongoose.h"
|
2019-01-05 00:01:34 +00:00
|
|
|
#include "web_server.h"
|
2019-01-08 00:09:43 +00:00
|
|
|
#include "mympd_api.h"
|
|
|
|
#include "../dist/src/inih/ini.h"
|
2019-01-11 00:38:44 +00:00
|
|
|
|
2018-05-24 18:17:54 +00:00
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
static void mympd_signal_handler(int sig_num) {
|
|
|
|
signal(sig_num, mympd_signal_handler); // Reinstantiate signal handler
|
2018-08-06 21:29:20 +00:00
|
|
|
s_signal_received = sig_num;
|
2019-01-25 00:08:38 +00:00
|
|
|
//Wakeup mympd_api_loop
|
|
|
|
pthread_cond_signal(&mympd_api_queue->wakeup);
|
2018-05-24 18:17:54 +00:00
|
|
|
}
|
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
static int mympd_inihandler(void *user, const char *section, const char *name, const char* value) {
|
2018-08-17 09:52:22 +00:00
|
|
|
t_config* p_config = (t_config*)user;
|
2018-08-22 12:06:22 +00:00
|
|
|
char *crap;
|
2018-08-06 20:51:48 +00:00
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
#define MATCH(s, n) strcasecmp(section, s) == 0 && strcasecmp(name, n) == 0
|
2018-08-21 19:28:13 +00:00
|
|
|
|
2019-01-25 00:08:38 +00:00
|
|
|
if (MATCH("mpd", "mpdhost")) {
|
|
|
|
free(p_config->mpdhost);
|
2018-08-06 20:51:48 +00:00
|
|
|
p_config->mpdhost = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mpd", "mpdport")) {
|
2018-08-22 12:06:22 +00:00
|
|
|
p_config->mpdport = strtol(value, &crap, 10);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mpd", "mpdpass")) {
|
|
|
|
free(p_config->mpdpass);
|
2018-08-06 20:51:48 +00:00
|
|
|
p_config->mpdpass = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mpd", "streamport")) {
|
2019-01-14 19:43:40 +00:00
|
|
|
p_config->streamport = strtol(value, &crap, 10);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("webserver", "webport")) {
|
|
|
|
free(p_config->webport);
|
2018-08-06 20:51:48 +00:00
|
|
|
p_config->webport = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("webserver", "ssl")) {
|
|
|
|
p_config->ssl = strcmp(value, "true") == 0 ? true : false;
|
|
|
|
}
|
|
|
|
else if (MATCH("webserver", "sslport")) {
|
|
|
|
free(p_config->sslport);
|
2018-11-28 14:23:29 +00:00
|
|
|
p_config->sslport = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("webserver", "sslcert")) {
|
|
|
|
free(p_config->sslcert);
|
2018-08-06 20:51:48 +00:00
|
|
|
p_config->sslcert = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("webserver", "sslkey")) {
|
|
|
|
free(p_config->sslkey);
|
2018-08-06 20:51:48 +00:00
|
|
|
p_config->sslkey = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "user")) {
|
|
|
|
free(p_config->user);
|
2018-08-06 20:51:48 +00:00
|
|
|
p_config->user = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "coverimage")) {
|
|
|
|
p_config->coverimage = strcmp(value, "true") == 0 ? true : false;
|
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "coverimagename")) {
|
|
|
|
free(p_config->coverimagename);
|
2018-10-29 19:41:04 +00:00
|
|
|
p_config->coverimagename = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "coverimagesize")) {
|
2018-12-24 15:37:45 +00:00
|
|
|
p_config->coverimagesize = strtol(value, &crap, 10);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "varlibdir")) {
|
|
|
|
free(p_config->varlibdir);
|
2018-09-29 23:03:00 +00:00
|
|
|
p_config->varlibdir = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "stickers")) {
|
|
|
|
p_config->stickers = strcmp(value, "true") == 0 ? true : false;
|
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "smartpls")) {
|
|
|
|
p_config->smartpls = strcmp(value, "true") == 0 ? true : false;
|
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "mixramp")) {
|
|
|
|
p_config->mixramp = strcmp(value, "true") == 0 ? true : false;
|
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "taglist")) {
|
|
|
|
free(p_config->taglist);
|
2018-10-14 22:03:56 +00:00
|
|
|
p_config->taglist = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "searchtaglist")) {
|
|
|
|
free(p_config->searchtaglist);
|
|
|
|
p_config->searchtaglist = strdup(value);
|
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "browsetaglist")) {
|
|
|
|
free(p_config->browsetaglist);
|
2018-10-29 18:17:04 +00:00
|
|
|
p_config->browsetaglist = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
2019-01-14 19:43:40 +00:00
|
|
|
else if (MATCH("mympd", "max_elements_per_page")) {
|
2018-10-14 22:03:56 +00:00
|
|
|
p_config->max_elements_per_page = strtol(value, &crap, 10);
|
|
|
|
if (p_config->max_elements_per_page > MAX_ELEMENTS_PER_PAGE) {
|
|
|
|
printf("Setting max_elements_per_page to maximal value %d", MAX_ELEMENTS_PER_PAGE);
|
|
|
|
p_config->max_elements_per_page = MAX_ELEMENTS_PER_PAGE;
|
|
|
|
}
|
|
|
|
}
|
2019-01-25 00:08:38 +00:00
|
|
|
else if (MATCH("mympd", "syscmds")) {
|
|
|
|
p_config->syscmds = strcmp(value, "true") == 0 ? true : false;
|
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "localplayer")) {
|
|
|
|
p_config->localplayer = strcmp(value, "true") == 0 ? true : false;
|
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "streamurl")) {
|
|
|
|
free(p_config->streamurl);
|
2018-10-29 18:17:04 +00:00
|
|
|
p_config->streamurl = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "last_played_count")) {
|
2018-11-12 23:48:29 +00:00
|
|
|
p_config->last_played_count = strtol(value, &crap, 10);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("mympd", "loglevel")) {
|
2018-11-27 21:24:45 +00:00
|
|
|
p_config->loglevel = strtol(value, &crap, 10);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("theme", "backgroundcolor")) {
|
|
|
|
free(p_config->backgroundcolor);
|
2019-01-19 00:20:05 +00:00
|
|
|
p_config->backgroundcolor = strdup(value);
|
2019-01-25 00:08:38 +00:00
|
|
|
}
|
2018-11-27 21:24:45 +00:00
|
|
|
else {
|
2019-01-14 19:43:40 +00:00
|
|
|
printf("Unkown config option: %s - %s\n", section, name);
|
2019-01-25 00:08:38 +00:00
|
|
|
return 0;
|
2018-11-27 21:24:45 +00:00
|
|
|
}
|
2018-08-06 20:51:48 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
static void mympd_free_config(t_config *config) {
|
2019-01-28 21:01:14 +00:00
|
|
|
free(config->mpdhost);
|
|
|
|
free(config->mpdpass);
|
|
|
|
free(config->webport);
|
|
|
|
free(config->sslport);
|
|
|
|
free(config->sslcert);
|
|
|
|
free(config->sslkey);
|
|
|
|
free(config->user);
|
|
|
|
free(config->coverimagename);
|
|
|
|
free(config->taglist);
|
|
|
|
free(config->searchtaglist);
|
|
|
|
free(config->browsetaglist);
|
|
|
|
free(config->varlibdir);
|
|
|
|
free(config->etcdir);
|
|
|
|
free(config->streamurl);
|
|
|
|
free(config->backgroundcolor);
|
|
|
|
free(config);
|
|
|
|
}
|
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
static void mympd_parse_env(struct t_config *config, const char *envvar) {
|
|
|
|
char *name, *section;
|
|
|
|
const char *value = getenv(envvar);
|
|
|
|
if (value != NULL) {
|
|
|
|
char *var = strdup(envvar);
|
|
|
|
section = strtok_r(var, "_", &name);
|
|
|
|
if (section != NULL && name != NULL) {
|
|
|
|
LOG_DEBUG() printf("DEBUG: Using environment variable %s_%s: %s\n", section, name, value);
|
|
|
|
mympd_inihandler(config, section, name, value);
|
|
|
|
}
|
|
|
|
value = NULL;
|
2019-01-30 22:10:16 +00:00
|
|
|
free(var);
|
2019-01-29 23:49:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mympd_get_env(struct t_config *config) {
|
|
|
|
const char* env_vars[]={"MPD_MPDHOST", "MPD_MPDPORT", "MPD_STREAMPORT",
|
|
|
|
"WEBSERVER_WEBPORT", "WEBSERVER_SSL", "WEBSERVER_SSLPORT", "WEBSERVER_SSLCERT", "WEBSERVER_SSLKEY",
|
|
|
|
"MYMPD_LOGLEVEL", "MYMPD_USER", "MYMPD_LOCALPLAYER", "MYMPD_COVERIMAGE", "MYMPD_COVERIMAGENAME",
|
|
|
|
"MYMPD_COVERIMAGESIZE", "MYMPD_VARLIBDIR", "MYMPD_MIXRAMP", "MYMPD_STICKERS", "MYMPD_TAGLIST",
|
|
|
|
"MYMPD_SEARCHTAGLIST", "MYMPD_BROWSETAGLIST", "MYMPD_SMARTPLS", "MYMPD_SYSCMDS",
|
|
|
|
"MYMPD_MAX_ELEMENTS_PER_PAGE", "MYMPD_LAST_PLAYED_COUNT",
|
|
|
|
"THEME_BACKGROUNDCOLOR", 0};
|
|
|
|
const char** ptr = env_vars;
|
|
|
|
while (*ptr != 0) {
|
|
|
|
mympd_parse_env(config, *ptr);
|
|
|
|
++ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-10 23:06:31 +00:00
|
|
|
int main(int argc, char **argv) {
|
2019-01-05 12:29:10 +00:00
|
|
|
s_signal_received = 0;
|
2018-10-07 21:56:11 +00:00
|
|
|
char testdirname[400];
|
2019-01-28 21:01:14 +00:00
|
|
|
bool init_webserver = false;
|
|
|
|
bool init_thread_webserver = false;
|
|
|
|
bool init_thread_mpdclient = false;
|
|
|
|
bool init_thread_mympdapi = false;
|
|
|
|
int rc = EXIT_FAILURE;
|
|
|
|
|
2019-01-05 00:01:34 +00:00
|
|
|
mpd_client_queue = tiny_queue_create();
|
2019-01-08 00:09:43 +00:00
|
|
|
mympd_api_queue = tiny_queue_create();
|
2019-01-05 00:01:34 +00:00
|
|
|
web_server_queue = tiny_queue_create();
|
2019-01-06 09:36:34 +00:00
|
|
|
|
|
|
|
srand((unsigned int)time(NULL));
|
2018-08-06 20:51:48 +00:00
|
|
|
|
2019-01-11 00:38:44 +00:00
|
|
|
//mympd config defaults
|
2019-01-28 00:34:18 +00:00
|
|
|
t_config *config = (t_config *)malloc(sizeof(t_config));
|
|
|
|
config->mpdhost = strdup("127.0.0.1");
|
|
|
|
config->mpdport = 6600;
|
|
|
|
config->mpdpass = NULL;
|
|
|
|
config->webport = strdup("80");
|
|
|
|
config->ssl = true;
|
|
|
|
config->sslport = strdup("443");
|
|
|
|
config->sslcert = strdup("/etc/mympd/ssl/server.pem");
|
|
|
|
config->sslkey = strdup("/etc/mympd/ssl/server.key");
|
|
|
|
config->user = strdup("mympd");
|
|
|
|
config->streamport = 8000;
|
|
|
|
config->streamurl = strdup("");
|
|
|
|
config->coverimage = true;
|
|
|
|
config->coverimagename = strdup("folder.jpg");
|
|
|
|
config->coverimagesize = 240;
|
|
|
|
config->varlibdir = strdup("/var/lib/mympd");
|
|
|
|
config->stickers = true;
|
|
|
|
config->mixramp = true;
|
|
|
|
config->taglist = strdup("Artist,Album,AlbumArtist,Title,Track,Genre,Date,Composer,Performer");
|
|
|
|
config->searchtaglist = strdup("Artist,Album,AlbumArtist,Title,Genre,Composer,Performer");
|
|
|
|
config->browsetaglist = strdup("Artist,Album,AlbumArtist,Genre,Composer,Performer");
|
|
|
|
config->smartpls = true;
|
|
|
|
config->max_elements_per_page = 100;
|
|
|
|
config->last_played_count = 20;
|
2019-01-29 23:49:40 +00:00
|
|
|
config->etcdir = strdup("/etc/mympd");
|
2019-01-28 00:34:18 +00:00
|
|
|
config->syscmds = false;
|
|
|
|
config->localplayer = true;
|
|
|
|
config->loglevel = 1;
|
|
|
|
config->backgroundcolor = strdup("#888");
|
2019-01-29 23:49:40 +00:00
|
|
|
|
|
|
|
char *configfile = strdup("/etc/mympd/mympd.conf");
|
2018-08-06 20:51:48 +00:00
|
|
|
if (argc == 2) {
|
2019-01-29 23:49:40 +00:00
|
|
|
if (strncmp(argv[1], "/", 1) == 0) {
|
|
|
|
printf("Starting myMPD %s\n", MYMPD_VERSION);
|
|
|
|
printf("Libmpdclient %i.%i.%i\n", LIBMPDCLIENT_MAJOR_VERSION, LIBMPDCLIENT_MINOR_VERSION, LIBMPDCLIENT_PATCH_VERSION);
|
|
|
|
free(configfile);
|
|
|
|
configfile = argv[1];
|
|
|
|
char *etcdir = strdup(configfile);
|
|
|
|
free(config->etcdir);
|
|
|
|
config->etcdir = strdup(dirname(etcdir));
|
|
|
|
free(etcdir);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("myMPD %s\n"
|
|
|
|
"Copyright (C) 2018-2019 Juergen Mang <mail@jcgames.de>\n"
|
|
|
|
"https://github.com/jcorporation/myMPD\n"
|
|
|
|
"Built " __DATE__ " "__TIME__"\n\n"
|
|
|
|
"Usage: %s [/path/to/mympd.conf]\n",
|
|
|
|
MYMPD_VERSION,
|
|
|
|
argv[0]
|
|
|
|
);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (access(configfile, F_OK ) != -1) {
|
|
|
|
printf("Parsing config file: %s\n", configfile);
|
|
|
|
if (ini_parse(configfile, mympd_inihandler, config) < 0) {
|
|
|
|
printf("Can't load config file \"%s\"\n", configfile);
|
2019-01-28 21:01:14 +00:00
|
|
|
goto cleanup;
|
2018-08-06 20:51:48 +00:00
|
|
|
}
|
2019-01-29 23:49:40 +00:00
|
|
|
}
|
2018-08-06 20:51:48 +00:00
|
|
|
else {
|
2019-01-29 23:49:40 +00:00
|
|
|
printf("No config file found, using defaults\n");
|
2018-05-24 18:17:54 +00:00
|
|
|
}
|
2019-01-29 23:49:40 +00:00
|
|
|
|
|
|
|
//read environment - overwrites config file definitions
|
|
|
|
mympd_get_env(config);
|
2018-11-28 14:23:29 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
printf("Debug flag enabled, setting loglevel to debug\n");
|
2019-01-28 00:34:18 +00:00
|
|
|
config->loglevel = 3;
|
2018-11-28 14:23:29 +00:00
|
|
|
#endif
|
2019-01-28 00:34:18 +00:00
|
|
|
printf("Setting loglevel to %ld\n", config->loglevel);
|
|
|
|
loglevel = config->loglevel;
|
2018-05-24 18:17:54 +00:00
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
//set signal handler
|
|
|
|
signal(SIGTERM, mympd_signal_handler);
|
|
|
|
signal(SIGINT, mympd_signal_handler);
|
2018-06-14 19:56:12 +00:00
|
|
|
setvbuf(stdout, NULL, _IOLBF, 0);
|
|
|
|
setvbuf(stderr, NULL, _IOLBF, 0);
|
2019-01-05 00:01:34 +00:00
|
|
|
|
2019-01-05 12:29:10 +00:00
|
|
|
//init webserver
|
2019-01-06 09:36:34 +00:00
|
|
|
struct mg_mgr mgr;
|
2019-01-28 00:34:18 +00:00
|
|
|
if (!web_server_init(&mgr, config)) {
|
2019-01-28 21:01:14 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
init_webserver = true;
|
2018-06-14 19:56:12 +00:00
|
|
|
}
|
2019-01-08 00:09:43 +00:00
|
|
|
|
2019-01-05 12:29:10 +00:00
|
|
|
//drop privileges
|
2019-01-30 22:10:16 +00:00
|
|
|
if (getuid() == 0) {
|
|
|
|
if (config->user != NULL || strlen(config->user) != 0) {
|
|
|
|
printf("Droping privileges to %s\n", config->user);
|
|
|
|
struct passwd *pw;
|
|
|
|
if ((pw = getpwnam(config->user)) == NULL) {
|
|
|
|
printf("ERROR: getpwnam() failed, unknown user\n");
|
|
|
|
goto cleanup;
|
|
|
|
} else if (setgroups(0, NULL) != 0) {
|
|
|
|
printf("ERROR: setgroups() failed\n");
|
|
|
|
goto cleanup;
|
|
|
|
} else if (setgid(pw->pw_gid) != 0) {
|
|
|
|
printf("ERROR: setgid() failed\n");
|
|
|
|
goto cleanup;
|
|
|
|
} else if (setuid(pw->pw_uid) != 0) {
|
|
|
|
printf("ERROR: setuid() failed\n");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-06-14 19:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-21 22:15:54 +00:00
|
|
|
|
|
|
|
if (getuid() == 0) {
|
2018-08-23 09:27:12 +00:00
|
|
|
printf("myMPD should not be run with root privileges\n");
|
2019-01-28 21:01:14 +00:00
|
|
|
goto cleanup;
|
2018-06-21 22:15:54 +00:00
|
|
|
}
|
2018-10-07 21:21:00 +00:00
|
|
|
|
2019-01-05 12:29:10 +00:00
|
|
|
//check needed directories
|
2019-01-28 21:01:14 +00:00
|
|
|
if (!testdir("Document root", DOC_ROOT)) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-10-07 21:56:11 +00:00
|
|
|
|
2019-01-05 12:29:10 +00:00
|
|
|
snprintf(testdirname, 400, "%s/library", DOC_ROOT);
|
2019-01-11 00:38:44 +00:00
|
|
|
if (!testdir("Link to mpd music_directory", testdirname)) {
|
|
|
|
printf("Disabling coverimage support\n");
|
2019-01-28 00:34:18 +00:00
|
|
|
config->coverimage = false;
|
2018-11-14 22:00:55 +00:00
|
|
|
}
|
2018-10-29 19:41:04 +00:00
|
|
|
|
2019-01-28 00:34:18 +00:00
|
|
|
snprintf(testdirname, 400, "%s/tmp", config->varlibdir);
|
2019-01-28 21:01:14 +00:00
|
|
|
if (!testdir("Temp dir", testdirname)) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-10-07 21:56:11 +00:00
|
|
|
|
2019-01-28 00:34:18 +00:00
|
|
|
snprintf(testdirname, 400, "%s/smartpls", config->varlibdir);
|
2019-01-28 21:01:14 +00:00
|
|
|
if (!testdir("Smartpls dir", testdirname)) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-10-07 21:56:11 +00:00
|
|
|
|
2019-01-28 00:34:18 +00:00
|
|
|
snprintf(testdirname, 400, "%s/state", config->varlibdir);
|
2019-01-28 21:01:14 +00:00
|
|
|
if (!testdir("State dir", testdirname)) {
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2018-10-07 21:56:11 +00:00
|
|
|
|
2019-01-30 09:00:26 +00:00
|
|
|
if (config->syscmds == true) {
|
|
|
|
snprintf(testdirname, 400, "%s/syscmds", config->etcdir);
|
|
|
|
if (!testdir("Syscmds directory", testdirname)) {
|
|
|
|
printf("Disabling syscmd support\n");
|
|
|
|
config->syscmds = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-05 12:29:10 +00:00
|
|
|
//Create working threads
|
2019-01-08 00:09:43 +00:00
|
|
|
pthread_t mpd_client_thread, web_server_thread, mympd_api_thread;
|
2019-01-05 12:29:10 +00:00
|
|
|
//mpd connection
|
2019-01-28 21:01:14 +00:00
|
|
|
if (pthread_create(&mpd_client_thread, NULL, mpd_client_loop, config) == 0) {
|
|
|
|
pthread_setname_np(mpd_client_thread, "mympd_mpdclient");
|
|
|
|
init_thread_mpdclient = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("ERROR: can't create mympd_client thread\n");
|
|
|
|
s_signal_received = SIGTERM;
|
|
|
|
}
|
2019-01-05 12:29:10 +00:00
|
|
|
//webserver
|
2019-01-28 21:01:14 +00:00
|
|
|
if (pthread_create(&web_server_thread, NULL, web_server_loop, &mgr) == 0) {
|
|
|
|
pthread_setname_np(web_server_thread, "mympd_webserver");
|
|
|
|
init_thread_webserver = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("ERROR: can't create mympd_webserver thread\n");
|
|
|
|
s_signal_received = SIGTERM;
|
|
|
|
}
|
2019-01-08 00:09:43 +00:00
|
|
|
//mympd api
|
2019-01-28 21:01:14 +00:00
|
|
|
if (pthread_create(&mympd_api_thread, NULL, mympd_api_loop, config) == 0) {
|
|
|
|
pthread_setname_np(mympd_api_thread, "mympd_mympdapi");
|
|
|
|
init_thread_mympdapi = true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
printf("ERROR: can't create mympd_mympdapi thread\n");
|
|
|
|
s_signal_received = SIGTERM;
|
|
|
|
}
|
2019-01-05 00:01:34 +00:00
|
|
|
|
2019-01-11 00:38:44 +00:00
|
|
|
//Outsourced all work to separate threads, do nothing...
|
2019-01-28 21:01:14 +00:00
|
|
|
rc = EXIT_SUCCESS;
|
2019-01-05 00:25:30 +00:00
|
|
|
|
2019-01-28 21:01:14 +00:00
|
|
|
//Try to cleanup all
|
|
|
|
cleanup:
|
|
|
|
if (init_thread_mpdclient)
|
|
|
|
pthread_join(mpd_client_thread, NULL);
|
|
|
|
if (init_thread_webserver)
|
|
|
|
pthread_join(web_server_thread, NULL);
|
|
|
|
if (init_thread_mympdapi)
|
|
|
|
pthread_join(mympd_api_thread, NULL);
|
|
|
|
if (init_webserver)
|
|
|
|
web_server_free(&mgr);
|
2019-01-05 12:29:10 +00:00
|
|
|
tiny_queue_free(web_server_queue);
|
|
|
|
tiny_queue_free(mpd_client_queue);
|
2019-01-08 00:09:43 +00:00
|
|
|
tiny_queue_free(mympd_api_queue);
|
2019-01-29 23:49:40 +00:00
|
|
|
mympd_free_config(config);
|
2019-01-30 22:10:16 +00:00
|
|
|
free(configfile);
|
2019-01-28 21:01:14 +00:00
|
|
|
return rc;
|
2018-05-24 18:17:54 +00:00
|
|
|
}
|