2008-12-27 19:03:33 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
2008-12-27 19:03:33 +01:00
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2008-12-27 19:03:33 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-01-03 17:31:38 +01:00
|
|
|
#include "CommandLine.hxx"
|
2017-12-29 17:12:55 +01:00
|
|
|
#include "GitVersion.hxx"
|
2013-01-03 17:34:51 +01:00
|
|
|
#include "ls.hxx"
|
2013-09-27 22:31:24 +02:00
|
|
|
#include "LogInit.hxx"
|
2013-01-09 22:33:06 +01:00
|
|
|
#include "Log.hxx"
|
2018-08-19 22:47:05 +02:00
|
|
|
#include "config/File.hxx"
|
2014-01-24 00:02:24 +01:00
|
|
|
#include "decoder/DecoderList.hxx"
|
|
|
|
#include "decoder/DecoderPlugin.hxx"
|
2014-01-28 11:42:54 +01:00
|
|
|
#include "output/Registry.hxx"
|
2014-01-23 23:49:50 +01:00
|
|
|
#include "output/OutputPlugin.hxx"
|
2014-01-24 16:18:21 +01:00
|
|
|
#include "input/Registry.hxx"
|
|
|
|
#include "input/InputPlugin.hxx"
|
2014-01-23 23:30:12 +01:00
|
|
|
#include "playlist/PlaylistRegistry.hxx"
|
|
|
|
#include "playlist/PlaylistPlugin.hxx"
|
2013-10-17 21:59:35 +02:00
|
|
|
#include "fs/AllocatedPath.hxx"
|
2020-04-02 16:18:06 +02:00
|
|
|
#include "fs/NarrowPath.hxx"
|
2013-10-17 23:23:25 +02:00
|
|
|
#include "fs/Traits.hxx"
|
2013-01-29 17:23:35 +01:00
|
|
|
#include "fs/FileSystem.hxx"
|
2013-12-06 23:33:58 +01:00
|
|
|
#include "fs/StandardDirectory.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Domain.hxx"
|
2013-11-24 12:19:51 +01:00
|
|
|
#include "util/OptionDef.hxx"
|
|
|
|
#include "util/OptionParser.hxx"
|
2020-05-05 15:08:55 +02:00
|
|
|
#include "Version.h"
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2019-07-05 09:59:00 +02:00
|
|
|
#ifdef _WIN32
|
|
|
|
#include "system/Error.hxx"
|
|
|
|
#endif
|
|
|
|
|
2014-01-30 20:29:48 +01:00
|
|
|
#ifdef ENABLE_DATABASE
|
|
|
|
#include "db/Registry.hxx"
|
|
|
|
#include "db/DatabasePlugin.hxx"
|
2014-02-05 19:23:02 +01:00
|
|
|
#include "storage/Registry.hxx"
|
|
|
|
#include "storage/StoragePlugin.hxx"
|
2014-01-30 20:29:48 +01:00
|
|
|
#endif
|
|
|
|
|
2014-01-18 16:36:42 +01:00
|
|
|
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
|
|
|
#include "neighbor/Registry.hxx"
|
|
|
|
#include "neighbor/NeighborPlugin.hxx"
|
|
|
|
#endif
|
|
|
|
|
2020-05-05 14:45:18 +02:00
|
|
|
#include "encoder/Features.h"
|
2009-11-17 20:39:26 +01:00
|
|
|
#ifdef ENABLE_ENCODER
|
2014-01-23 23:09:14 +01:00
|
|
|
#include "encoder/EncoderList.hxx"
|
|
|
|
#include "encoder/EncoderPlugin.hxx"
|
2009-11-17 20:39:26 +01:00
|
|
|
#endif
|
|
|
|
|
2008-12-27 19:03:33 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
2014-01-24 00:09:37 +01:00
|
|
|
#include "archive/ArchiveList.hxx"
|
|
|
|
#include "archive/ArchivePlugin.hxx"
|
2008-12-27 19:03:33 +01:00
|
|
|
#endif
|
|
|
|
|
2018-07-17 17:02:49 +02:00
|
|
|
namespace {
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifdef _WIN32
|
2018-07-17 17:02:49 +02:00
|
|
|
constexpr auto CONFIG_FILE_LOCATION = Path::FromFS(PATH_LITERAL("mpd\\mpd.conf"));
|
|
|
|
constexpr auto APP_CONFIG_FILE_LOCATION = Path::FromFS(PATH_LITERAL("conf\\mpd.conf"));
|
2013-10-15 08:33:44 +02:00
|
|
|
#else
|
2018-07-17 17:02:49 +02:00
|
|
|
constexpr auto USER_CONFIG_FILE_LOCATION1 = Path::FromFS(PATH_LITERAL(".mpdconf"));
|
|
|
|
constexpr auto USER_CONFIG_FILE_LOCATION2 = Path::FromFS(PATH_LITERAL(".mpd/mpd.conf"));
|
|
|
|
constexpr auto USER_CONFIG_FILE_LOCATION_XDG = Path::FromFS(PATH_LITERAL("mpd/mpd.conf"));
|
2010-05-20 15:53:07 +02:00
|
|
|
#endif
|
2020-02-03 01:28:41 +01:00
|
|
|
} // namespace
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2018-01-17 10:24:06 +01:00
|
|
|
enum Option {
|
|
|
|
OPTION_KILL,
|
|
|
|
OPTION_NO_CONFIG,
|
|
|
|
OPTION_NO_DAEMON,
|
|
|
|
OPTION_STDOUT,
|
|
|
|
OPTION_STDERR,
|
|
|
|
OPTION_VERBOSE,
|
|
|
|
OPTION_VERSION,
|
|
|
|
OPTION_HELP,
|
|
|
|
OPTION_HELP2,
|
|
|
|
};
|
|
|
|
|
|
|
|
static constexpr OptionDef option_defs[] = {
|
|
|
|
{"kill", "kill the currently running mpd session"},
|
|
|
|
{"no-config", "don't read from config"},
|
|
|
|
{"no-daemon", "don't detach from console"},
|
|
|
|
{"stdout", nullptr}, // hidden, compatibility with old versions
|
|
|
|
{"stderr", "print messages to stderr"},
|
|
|
|
{"verbose", 'v', "verbose logging"},
|
|
|
|
{"version", 'V', "print version number"},
|
|
|
|
{"help", 'h', "show help options"},
|
|
|
|
{nullptr, '?', nullptr}, // hidden, standard alias for --help
|
|
|
|
};
|
2013-11-24 12:19:51 +01:00
|
|
|
|
2013-08-10 18:02:44 +02:00
|
|
|
static constexpr Domain cmdline_domain("cmdline");
|
2009-09-24 21:40:05 +02:00
|
|
|
|
2020-03-16 05:03:09 +01:00
|
|
|
[[noreturn]]
|
2020-02-01 05:12:05 +01:00
|
|
|
static void version()
|
2008-12-27 19:03:33 +01:00
|
|
|
{
|
2019-04-18 09:20:12 +02:00
|
|
|
printf("Music Player Daemon " VERSION " (%s)"
|
2014-12-08 18:25:03 +01:00
|
|
|
"\n"
|
2018-10-31 17:54:59 +01:00
|
|
|
"Copyright 2003-2007 Warren Dukes <warren.dukes@gmail.com>\n"
|
|
|
|
"Copyright 2008-2018 Max Kellermann <max.kellermann@gmail.com>\n"
|
2014-12-08 18:25:03 +01:00
|
|
|
"This is free software; see the source for copying conditions. There is NO\n"
|
2019-04-18 09:20:12 +02:00
|
|
|
"warranty; not even MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
|
|
|
|
GIT_VERSION);
|
2014-01-30 20:29:48 +01:00
|
|
|
|
|
|
|
#ifdef ENABLE_DATABASE
|
2019-04-18 09:20:12 +02:00
|
|
|
printf("\n"
|
|
|
|
"Database plugins:\n");
|
2014-01-13 22:29:07 +01:00
|
|
|
|
|
|
|
for (auto i = database_plugins; *i != nullptr; ++i)
|
|
|
|
printf(" %s", (*i)->name);
|
2014-02-05 19:23:02 +01:00
|
|
|
|
2014-12-08 18:25:03 +01:00
|
|
|
printf("\n\n"
|
|
|
|
"Storage plugins:\n");
|
2014-02-05 19:23:02 +01:00
|
|
|
|
|
|
|
for (auto i = storage_plugins; *i != nullptr; ++i)
|
|
|
|
printf(" %s", (*i)->name);
|
2014-12-08 18:30:02 +01:00
|
|
|
|
2019-04-18 09:20:12 +02:00
|
|
|
printf("\n");
|
2014-01-30 20:29:48 +01:00
|
|
|
#endif
|
2014-01-13 22:29:07 +01:00
|
|
|
|
2014-01-18 16:36:42 +01:00
|
|
|
#ifdef ENABLE_NEIGHBOR_PLUGINS
|
2019-04-18 09:20:12 +02:00
|
|
|
printf("\n"
|
2014-12-08 18:25:03 +01:00
|
|
|
"Neighbor plugins:\n");
|
2014-01-18 16:36:42 +01:00
|
|
|
for (auto i = neighbor_plugins; *i != nullptr; ++i)
|
|
|
|
printf(" %s", (*i)->name);
|
2014-12-08 18:30:02 +01:00
|
|
|
|
2014-01-18 16:36:42 +01:00
|
|
|
#endif
|
|
|
|
|
2019-04-18 09:20:12 +02:00
|
|
|
printf("\n"
|
2014-12-08 18:30:02 +01:00
|
|
|
"\n"
|
2014-12-08 18:25:03 +01:00
|
|
|
"Decoders plugins:\n");
|
2012-06-12 22:29:04 +02:00
|
|
|
|
2013-10-21 22:02:19 +02:00
|
|
|
decoder_plugins_for_each([](const DecoderPlugin &plugin){
|
|
|
|
printf(" [%s]", plugin.name);
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2013-10-21 22:02:19 +02:00
|
|
|
const char *const*suffixes = plugin.suffixes;
|
|
|
|
if (suffixes != nullptr)
|
|
|
|
for (; *suffixes != nullptr; ++suffixes)
|
|
|
|
printf(" %s", *suffixes);
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2014-12-08 18:25:03 +01:00
|
|
|
printf("\n");
|
2013-10-21 22:02:19 +02:00
|
|
|
});
|
2008-12-30 14:08:59 +01:00
|
|
|
|
2014-12-08 18:25:03 +01:00
|
|
|
printf("\n"
|
2015-06-26 16:42:06 +02:00
|
|
|
"Filters:\n"
|
|
|
|
#ifdef ENABLE_LIBSAMPLERATE
|
|
|
|
" libsamplerate"
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SOXR
|
|
|
|
" soxr"
|
|
|
|
#endif
|
|
|
|
"\n\n"
|
2014-12-08 18:25:03 +01:00
|
|
|
"Tag plugins:\n"
|
2014-12-07 17:14:19 +01:00
|
|
|
#ifdef ENABLE_ID3TAG
|
2014-12-08 18:25:03 +01:00
|
|
|
" id3tag"
|
2014-12-07 17:14:19 +01:00
|
|
|
#endif
|
2014-12-08 18:25:03 +01:00
|
|
|
"\n\n"
|
|
|
|
"Output plugins:\n");
|
2012-06-12 22:29:04 +02:00
|
|
|
audio_output_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
2014-12-08 18:30:02 +01:00
|
|
|
printf("\n"
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2009-11-17 20:39:26 +01:00
|
|
|
#ifdef ENABLE_ENCODER
|
2014-12-08 18:30:02 +01:00
|
|
|
"\n"
|
2014-12-08 18:25:03 +01:00
|
|
|
"Encoder plugins:\n");
|
2012-06-12 22:29:04 +02:00
|
|
|
encoder_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
2014-12-08 18:30:02 +01:00
|
|
|
printf("\n"
|
2009-11-17 20:39:26 +01:00
|
|
|
#endif
|
|
|
|
|
2008-12-27 19:03:33 +01:00
|
|
|
#ifdef ENABLE_ARCHIVE
|
2014-12-08 18:30:02 +01:00
|
|
|
"\n"
|
2014-12-08 18:25:03 +01:00
|
|
|
"Archive plugins:\n");
|
2012-06-12 22:29:04 +02:00
|
|
|
archive_plugins_for_each(plugin) {
|
|
|
|
printf(" [%s]", plugin->name);
|
|
|
|
|
|
|
|
const char *const*suffixes = plugin->suffixes;
|
2013-10-19 18:19:03 +02:00
|
|
|
if (suffixes != nullptr)
|
|
|
|
for (; *suffixes != nullptr; ++suffixes)
|
2012-06-12 22:29:04 +02:00
|
|
|
printf(" %s", *suffixes);
|
|
|
|
|
2014-12-08 18:25:03 +01:00
|
|
|
printf("\n");
|
2012-06-12 22:29:04 +02:00
|
|
|
}
|
2014-12-08 18:30:02 +01:00
|
|
|
|
|
|
|
printf(""
|
2008-12-27 19:03:33 +01:00
|
|
|
#endif
|
2009-01-01 18:26:59 +01:00
|
|
|
|
2014-12-08 18:30:02 +01:00
|
|
|
"\n"
|
2018-01-20 19:07:34 +01:00
|
|
|
"Input plugins:\n"
|
|
|
|
" file"
|
|
|
|
#ifdef ENABLE_ARCHIVE
|
|
|
|
" archive"
|
|
|
|
#endif
|
|
|
|
);
|
2012-06-12 22:24:42 +02:00
|
|
|
input_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
|
|
|
|
2014-12-08 18:25:03 +01:00
|
|
|
printf("\n\n"
|
|
|
|
"Playlist plugins:\n");
|
2012-06-12 19:59:03 +02:00
|
|
|
playlist_plugins_for_each(plugin)
|
|
|
|
printf(" %s", plugin->name);
|
|
|
|
|
2014-12-08 18:25:03 +01:00
|
|
|
printf("\n\n"
|
|
|
|
"Protocols:\n");
|
2009-03-03 17:01:42 +01:00
|
|
|
print_supported_uri_schemes_to_fp(stdout);
|
|
|
|
|
2015-06-26 16:42:06 +02:00
|
|
|
printf("\n"
|
|
|
|
"Other features:\n"
|
|
|
|
#ifdef HAVE_AVAHI
|
|
|
|
" avahi"
|
|
|
|
#endif
|
2018-05-31 10:54:27 +02:00
|
|
|
#ifdef ENABLE_DBUS
|
|
|
|
" dbus"
|
|
|
|
#endif
|
2018-05-31 10:52:36 +02:00
|
|
|
#ifdef ENABLE_UDISKS
|
|
|
|
" udisks"
|
|
|
|
#endif
|
2015-06-26 16:42:06 +02:00
|
|
|
#ifdef USE_EPOLL
|
|
|
|
" epoll"
|
|
|
|
#endif
|
2015-06-26 16:43:27 +02:00
|
|
|
#ifdef HAVE_ICONV
|
|
|
|
" iconv"
|
|
|
|
#endif
|
2015-06-26 16:42:06 +02:00
|
|
|
#ifdef HAVE_ICU
|
|
|
|
" icu"
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_INOTIFY
|
|
|
|
" inotify"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_IPV6
|
|
|
|
" ipv6"
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SYSTEMD_DAEMON
|
|
|
|
" systemd"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_TCP
|
|
|
|
" tcp"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_UN
|
|
|
|
" un"
|
|
|
|
#endif
|
|
|
|
"\n");
|
|
|
|
|
2020-03-27 02:44:09 +01:00
|
|
|
std::exit(EXIT_SUCCESS);
|
2008-12-27 19:03:33 +01:00
|
|
|
}
|
|
|
|
|
2013-11-24 12:19:51 +01:00
|
|
|
static void PrintOption(const OptionDef &opt)
|
|
|
|
{
|
|
|
|
if (opt.HasShortOption())
|
|
|
|
printf(" -%c, --%-12s%s\n",
|
|
|
|
opt.GetShortOption(),
|
|
|
|
opt.GetLongOption(),
|
|
|
|
opt.GetDescription());
|
|
|
|
else
|
|
|
|
printf(" --%-16s%s\n",
|
|
|
|
opt.GetLongOption(),
|
|
|
|
opt.GetDescription());
|
|
|
|
}
|
|
|
|
|
2020-03-16 05:03:09 +01:00
|
|
|
[[noreturn]]
|
2020-02-01 05:12:05 +01:00
|
|
|
static void help()
|
2013-11-24 12:19:51 +01:00
|
|
|
{
|
2014-12-08 18:25:03 +01:00
|
|
|
printf("Usage:\n"
|
|
|
|
" mpd [OPTION...] [path/to/mpd.conf]\n"
|
|
|
|
"\n"
|
|
|
|
"Music Player Daemon - a daemon for playing music.\n"
|
|
|
|
"\n"
|
|
|
|
"Options:\n");
|
2013-11-24 12:19:51 +01:00
|
|
|
|
2018-01-17 10:24:06 +01:00
|
|
|
for (const auto &i : option_defs)
|
2020-02-01 06:25:24 +01:00
|
|
|
if(i.HasDescription()) // hide hidden options from help print
|
2018-03-02 14:22:47 +01:00
|
|
|
PrintOption(i);
|
2013-11-24 12:19:51 +01:00
|
|
|
|
2020-03-27 02:44:09 +01:00
|
|
|
std::exit(EXIT_SUCCESS);
|
2013-11-24 12:19:51 +01:00
|
|
|
}
|
2008-12-27 19:36:03 +01:00
|
|
|
|
2013-12-06 23:33:58 +01:00
|
|
|
class ConfigLoader
|
2013-01-29 17:23:35 +01:00
|
|
|
{
|
2018-08-19 22:47:05 +02:00
|
|
|
ConfigData &config;
|
|
|
|
|
2013-12-06 23:33:58 +01:00
|
|
|
public:
|
2018-08-19 22:47:05 +02:00
|
|
|
explicit ConfigLoader(ConfigData &_config) noexcept
|
|
|
|
:config(_config) {}
|
|
|
|
|
2020-02-02 23:16:14 +01:00
|
|
|
bool TryFile(Path path);
|
2018-07-17 17:02:49 +02:00
|
|
|
bool TryFile(const AllocatedPath &base_path, Path path);
|
2013-12-06 23:33:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
bool ConfigLoader::TryFile(Path path)
|
|
|
|
{
|
|
|
|
if (FileExists(path)) {
|
2018-08-19 22:47:05 +02:00
|
|
|
ReadConfigFile(config, path);
|
2013-12-06 23:33:58 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-17 17:02:49 +02:00
|
|
|
bool ConfigLoader::TryFile(const AllocatedPath &base_path, Path path)
|
2013-12-06 23:33:58 +01:00
|
|
|
{
|
|
|
|
if (base_path.IsNull())
|
|
|
|
return false;
|
2018-07-17 17:01:02 +02:00
|
|
|
auto full_path = base_path / path;
|
2013-12-06 23:33:58 +01:00
|
|
|
return TryFile(full_path);
|
2013-01-29 17:23:35 +01:00
|
|
|
}
|
|
|
|
|
2016-11-02 10:30:46 +01:00
|
|
|
void
|
2018-08-19 22:47:05 +02:00
|
|
|
ParseCommandLine(int argc, char **argv, struct options &options,
|
|
|
|
ConfigData &config)
|
2008-12-27 19:03:33 +01:00
|
|
|
{
|
2013-11-24 12:19:51 +01:00
|
|
|
bool use_config_file = true;
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2013-11-24 12:19:51 +01:00
|
|
|
// First pass: handle command line options
|
2018-01-17 10:24:06 +01:00
|
|
|
OptionParser parser(option_defs, argc, argv);
|
2018-01-17 11:00:07 +01:00
|
|
|
while (auto o = parser.Next()) {
|
|
|
|
switch (Option(o.index)) {
|
2018-01-17 10:24:06 +01:00
|
|
|
case OPTION_KILL:
|
2018-01-17 10:56:42 +01:00
|
|
|
options.kill = true;
|
2018-01-17 10:24:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_NO_CONFIG:
|
2013-11-24 12:19:51 +01:00
|
|
|
use_config_file = false;
|
2018-01-17 10:24:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_NO_DAEMON:
|
2018-01-17 10:56:42 +01:00
|
|
|
options.daemon = false;
|
2018-01-17 10:24:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_STDOUT:
|
|
|
|
case OPTION_STDERR:
|
2018-01-17 10:56:42 +01:00
|
|
|
options.log_stderr = true;
|
2018-01-17 10:24:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_VERBOSE:
|
2018-01-17 10:56:42 +01:00
|
|
|
options.verbose = true;
|
2018-01-17 10:24:06 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OPTION_VERSION:
|
2013-11-24 12:19:51 +01:00
|
|
|
version();
|
2008-12-27 19:03:33 +01:00
|
|
|
|
2018-01-17 10:24:06 +01:00
|
|
|
case OPTION_HELP:
|
|
|
|
case OPTION_HELP2:
|
|
|
|
help();
|
|
|
|
}
|
2013-11-24 12:19:51 +01:00
|
|
|
}
|
2008-12-27 19:36:03 +01:00
|
|
|
|
2009-02-19 08:35:20 +01:00
|
|
|
/* initialize the logging library, so the configuration file
|
|
|
|
parser can use it already */
|
2018-01-17 10:56:42 +01:00
|
|
|
log_early_init(options.verbose);
|
2009-02-19 08:35:20 +01:00
|
|
|
|
2013-11-24 12:19:51 +01:00
|
|
|
if (!use_config_file) {
|
2013-09-27 22:31:24 +02:00
|
|
|
LogDebug(cmdline_domain,
|
|
|
|
"Ignoring config, using daemon defaults");
|
2016-11-02 10:30:46 +01:00
|
|
|
return;
|
2013-11-24 12:19:51 +01:00
|
|
|
}
|
2013-01-29 17:23:35 +01:00
|
|
|
|
2013-11-24 12:19:51 +01:00
|
|
|
// Second pass: find non-option parameters (i.e. config file)
|
|
|
|
const char *config_file = nullptr;
|
2018-01-16 11:03:04 +01:00
|
|
|
for (const char *i : parser.GetRemaining()) {
|
2013-11-24 12:19:51 +01:00
|
|
|
if (config_file == nullptr) {
|
2018-01-16 11:03:04 +01:00
|
|
|
config_file = i;
|
2013-11-24 12:19:51 +01:00
|
|
|
continue;
|
2010-05-20 15:53:07 +02:00
|
|
|
}
|
2016-11-02 10:30:46 +01:00
|
|
|
|
|
|
|
throw std::runtime_error("too many arguments");
|
2013-11-24 12:19:51 +01:00
|
|
|
}
|
2013-08-07 16:08:48 +02:00
|
|
|
|
2013-11-24 12:19:51 +01:00
|
|
|
if (config_file != nullptr) {
|
|
|
|
/* use specified configuration file */
|
2020-04-02 16:18:06 +02:00
|
|
|
ReadConfigFile(config, FromNarrowPath(config_file));
|
2016-11-02 10:30:46 +01:00
|
|
|
return;
|
2013-11-24 12:19:51 +01:00
|
|
|
}
|
2013-01-29 17:23:35 +01:00
|
|
|
|
2013-11-24 12:19:51 +01:00
|
|
|
/* use default configuration file path */
|
2013-12-06 23:33:58 +01:00
|
|
|
|
2018-08-19 22:47:05 +02:00
|
|
|
ConfigLoader loader(config);
|
2013-12-06 23:33:58 +01:00
|
|
|
|
|
|
|
bool found =
|
2017-12-12 10:22:20 +01:00
|
|
|
#ifdef _WIN32
|
2013-12-06 23:33:58 +01:00
|
|
|
loader.TryFile(GetUserConfigDir(), CONFIG_FILE_LOCATION) ||
|
|
|
|
loader.TryFile(GetSystemConfigDir(), CONFIG_FILE_LOCATION) ||
|
|
|
|
loader.TryFile(GetAppBaseDir(), APP_CONFIG_FILE_LOCATION);
|
2013-11-24 12:19:51 +01:00
|
|
|
#else
|
2013-12-06 23:33:58 +01:00
|
|
|
loader.TryFile(GetUserConfigDir(),
|
|
|
|
USER_CONFIG_FILE_LOCATION_XDG) ||
|
|
|
|
loader.TryFile(GetHomeDir(), USER_CONFIG_FILE_LOCATION1) ||
|
|
|
|
loader.TryFile(GetHomeDir(), USER_CONFIG_FILE_LOCATION2) ||
|
|
|
|
loader.TryFile(Path::FromFS(SYSTEM_CONFIG_FILE_LOCATION));
|
2013-11-24 12:19:51 +01:00
|
|
|
#endif
|
2016-11-02 10:30:46 +01:00
|
|
|
if (!found)
|
|
|
|
throw std::runtime_error("No configuration file found");
|
2008-12-27 19:03:33 +01:00
|
|
|
}
|