diff options
Diffstat (limited to 'src/Main.cxx')
-rw-r--r-- | src/Main.cxx | 86 |
1 files changed, 50 insertions, 36 deletions
diff --git a/src/Main.cxx b/src/Main.cxx index a3a1b0021..1a074d439 100644 --- a/src/Main.cxx +++ b/src/Main.cxx @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 The Music Player Daemon Project + * Copyright (C) 2003-2015 The Music Player Daemon Project * http://www.musicpd.org * * This program is free software; you can redistribute it and/or modify @@ -25,7 +25,7 @@ #include "PlaylistGlobal.hxx" #include "MusicChunk.hxx" #include "StateFile.hxx" -#include "PlayerThread.hxx" +#include "player/Thread.hxx" #include "Mapper.hxx" #include "Permission.hxx" #include "Listen.hxx" @@ -50,7 +50,6 @@ #include "AudioConfig.hxx" #include "pcm/PcmConvert.hxx" #include "unix/SignalHandlers.hxx" -#include "unix/Daemon.hxx" #include "system/FatalError.hxx" #include "util/UriUtil.hxx" #include "util/Error.hxx" @@ -58,12 +57,16 @@ #include "thread/Slack.hxx" #include "lib/icu/Init.hxx" #include "config/ConfigGlobal.hxx" -#include "config/ConfigData.hxx" +#include "config/Param.hxx" #include "config/ConfigDefaults.hxx" #include "config/ConfigOption.hxx" #include "config/ConfigError.hxx" #include "Stats.hxx" +#ifdef ENABLE_DAEMON +#include "unix/Daemon.hxx" +#endif + #ifdef ENABLE_DATABASE #include "db/update/Service.hxx" #include "db/Configured.hxx" @@ -98,8 +101,8 @@ #include "org_musicpd_Bridge.h" #endif -#ifdef HAVE_GLIB -#include <glib.h> +#ifdef ENABLE_SYSTEMD_DAEMON +#include <systemd/sd-daemon.h> #endif #include <stdlib.h> @@ -130,17 +133,17 @@ Instance *instance; static StateFile *state_file; -#ifndef ANDROID +#ifdef ENABLE_DAEMON static bool glue_daemonize_init(const struct options *options, Error &error) { - auto pid_file = config_get_path(CONF_PID_FILE, error); + auto pid_file = config_get_path(ConfigOption::PID_FILE, error); if (pid_file.IsNull() && error.IsDefined()) return false; - daemonize_init(config_get_string(CONF_USER, nullptr), - config_get_string(CONF_GROUP, nullptr), + daemonize_init(config_get_string(ConfigOption::USER, nullptr), + config_get_string(ConfigOption::GROUP, nullptr), std::move(pid_file)); if (options->kill) @@ -154,7 +157,7 @@ glue_daemonize_init(const struct options *options, Error &error) static bool glue_mapper_init(Error &error) { - auto playlist_dir = config_get_path(CONF_PLAYLIST_DIR, error); + auto playlist_dir = config_get_path(ConfigOption::PLAYLIST_DIR, error); if (playlist_dir.IsNull() && error.IsDefined()) return false; @@ -249,7 +252,7 @@ glue_sticker_init(void) { #ifdef ENABLE_SQLITE Error error; - auto sticker_file = config_get_path(CONF_STICKER_FILE, error); + auto sticker_file = config_get_path(ConfigOption::STICKER_FILE, error); if (sticker_file.IsNull()) { if (error.IsDefined()) FatalError(error); @@ -264,7 +267,7 @@ glue_sticker_init(void) static bool glue_state_file_init(Error &error) { - auto path_fs = config_get_path(CONF_STATE_FILE, error); + auto path_fs = config_get_path(ConfigOption::STATE_FILE, error); if (path_fs.IsNull()) { if (error.IsDefined()) return false; @@ -280,8 +283,9 @@ glue_state_file_init(Error &error) #endif } - unsigned interval = config_get_unsigned(CONF_STATE_FILE_INTERVAL, - StateFile::DEFAULT_INTERVAL); + const unsigned interval = + config_get_unsigned(ConfigOption::STATE_FILE_INTERVAL, + StateFile::DEFAULT_INTERVAL); state_file = new StateFile(std::move(path_fs), interval, *instance->partition, @@ -318,7 +322,7 @@ initialize_decoder_and_player(void) const struct config_param *param; size_t buffer_size; - param = config_get_param(CONF_AUDIO_BUFFER_SIZE); + param = config_get_param(ConfigOption::AUDIO_BUFFER_SIZE); if (param != nullptr) { char *test; long tmp = strtol(param->value.c_str(), &test, 10); @@ -339,7 +343,7 @@ initialize_decoder_and_player(void) (unsigned long)buffer_size); float perc; - param = config_get_param(CONF_BUFFER_BEFORE_PLAY); + param = config_get_param(ConfigOption::BUFFER_BEFORE_PLAY); if (param != nullptr) { char *test; perc = strtod(param->value.c_str(), &test); @@ -357,7 +361,7 @@ initialize_decoder_and_player(void) buffered_before_play = buffered_chunks; const unsigned max_length = - config_get_positive(CONF_MAX_PLAYLIST_LENGTH, + config_get_positive(ConfigOption::MAX_PLAYLIST_LENGTH, DEFAULT_PLAYLIST_MAX_LENGTH); instance->partition = new Partition(*instance, @@ -419,21 +423,15 @@ int mpd_main(int argc, char *argv[]) struct options options; Error error; -#ifndef ANDROID +#ifdef ENABLE_DAEMON daemonize_close_stdin(); +#endif +#ifndef ANDROID #ifdef HAVE_LOCALE_H /* initialize locale */ setlocale(LC_CTYPE,""); -#endif - -#ifdef HAVE_GLIB - g_set_application_name("Music Player Daemon"); - -#if !GLIB_CHECK_VERSION(2,32,0) - /* enable GLib's thread safety code */ - g_thread_init(nullptr); -#endif + setlocale(LC_COLLATE, ""); #endif #endif @@ -467,7 +465,9 @@ int mpd_main(int argc, char *argv[]) LogError(error); return EXIT_FAILURE; } +#endif +#ifdef ENABLE_DAEMON if (!glue_daemonize_init(&options, error)) { LogError(error); return EXIT_FAILURE; @@ -498,7 +498,8 @@ int mpd_main(int argc, char *argv[]) } #endif - const unsigned max_clients = config_get_positive(CONF_MAX_CONN, 10); + const unsigned max_clients = + config_get_positive(ConfigOption::MAX_CONN, 10); instance->client_list = new ClientList(max_clients); initialize_decoder_and_player(); @@ -509,7 +510,7 @@ int mpd_main(int argc, char *argv[]) return EXIT_FAILURE; } -#ifndef ANDROID +#ifdef ENABLE_DAEMON daemonize_set_user(); daemonize_begin(options.daemon); #endif @@ -541,7 +542,10 @@ static int mpd_main_after_fork(struct options options) GlobalEvents::Register(GlobalEvents::SHUTDOWN, shutdown_event_emitted); #endif - ConfigureFS(); + if (!ConfigureFS(error)) { + LogError(error); + return EXIT_FAILURE; + } if (!glue_mapper_init(error)) { LogError(error); @@ -582,9 +586,11 @@ static int mpd_main_after_fork(struct options options) playlist_list_global_init(); -#ifndef ANDROID +#ifdef ENABLE_DAEMON daemonize_commit(); +#endif +#ifndef ANDROID setup_log_output(options.log_stderr); SignalHandlersInit(*instance->event_loop); @@ -620,17 +626,17 @@ static int mpd_main_after_fork(struct options options) instance->partition->outputs.SetReplayGainMode(replay_gain_get_real_mode(instance->partition->playlist.queue.random)); #ifdef ENABLE_DATABASE - if (config_get_bool(CONF_AUTO_UPDATE, false)) { + if (config_get_bool(ConfigOption::AUTO_UPDATE, false)) { #ifdef ENABLE_INOTIFY if (instance->storage != nullptr && instance->update != nullptr) mpd_inotify_init(*instance->event_loop, *instance->storage, *instance->update, - config_get_unsigned(CONF_AUTO_UPDATE_DEPTH, + config_get_unsigned(ConfigOption::AUTO_UPDATE_DEPTH, INT_MAX)); #else - FormatWarning(main_domain, + FormatWarning(config_domain, "inotify: auto_update was disabled. enable during compilation phase"); #endif } @@ -650,6 +656,10 @@ static int mpd_main_after_fork(struct options options) a huge value to allow the kernel to reduce CPU wakeups */ SetThreadTimerSlackMS(100); +#ifdef ENABLE_SYSTEMD_DAEMON + sd_notify(0, "READY=1"); +#endif + /* run the main loop */ instance->event_loop->Run(); @@ -707,6 +717,8 @@ static int mpd_main_after_fork(struct options options) mapper_finish(); #endif + DeinitFS(); + delete instance->partition; command_finish(); decoder_plugin_deinit_all(); @@ -721,9 +733,11 @@ static int mpd_main_after_fork(struct options options) delete instance->event_loop; delete instance; instance = nullptr; -#ifndef ANDROID + +#ifdef ENABLE_DAEMON daemonize_finish(); #endif + #ifdef WIN32 WSACleanup(); #endif |