aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-07-15 18:58:12 +0200
committerMax Kellermann <max@duempel.org>2009-07-15 18:58:12 +0200
commit7bc8c7518b088d160f9861cac418d080c3f69531 (patch)
tree42f732028047281060579b0631b40b02555a9ae9 /src/main.c
parent739984f920504752ad2863449e8f611e9ef765e2 (diff)
downloadmpd-7bc8c7518b088d160f9861cac418d080c3f69531.tar.gz
mpd-7bc8c7518b088d160f9861cac418d080c3f69531.tar.xz
mpd-7bc8c7518b088d160f9861cac418d080c3f69531.zip
main: moved complex initialization code to glue functions
The glue_*() functions act as a glue between MPD's main() function and its libraries. They handle disabled features, and pass validated configuration options.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c53
1 files changed, 36 insertions, 17 deletions
diff --git a/src/main.c b/src/main.c
index f176a9da9..f1eaa08aa 100644
--- a/src/main.c
+++ b/src/main.c
@@ -90,6 +90,16 @@ GMainLoop *main_loop;
struct notify main_notify;
+static void
+glue_daemonize_init(const struct options *options)
+{
+ daemonize_init(config_get_string(CONF_USER, NULL),
+ config_get_path(CONF_PID_FILE));
+
+ if (options->kill)
+ daemonize_kill();
+}
+
/**
* Returns the database. If this function returns false, this has not
* succeeded, and the caller should create the database after the
@@ -141,6 +151,29 @@ glue_db_init_and_load(const struct options *options)
}
/**
+ * Configure and initialize the sticker subsystem.
+ */
+static void
+glue_sticker_init(void)
+{
+#ifdef ENABLE_SQLITE
+ bool success;
+ GError *error = NULL;
+
+ success = sticker_global_init(config_get_path(CONF_STICKER_FILE),
+ &error);
+ if (!success)
+ g_error("%s", error->message);
+#endif
+}
+
+static void
+glue_state_file_init(void)
+{
+ state_file_init(config_get_path(CONF_STATE_FILE));
+}
+
+/**
* Windows-only initialization of the Winsock2 library.
*/
#ifdef WIN32
@@ -231,10 +264,6 @@ int main(int argc, char *argv[])
struct options options;
clock_t start;
bool create_db;
-#ifdef ENABLE_SQLITE
- bool success;
- GError *error = NULL;
-#endif
daemonize_close_stdin();
@@ -257,11 +286,7 @@ int main(int argc, char *argv[])
parse_cmdline(argc, argv, &options);
- daemonize_init(config_get_string(CONF_USER, NULL),
- config_get_path(CONF_PID_FILE));
-
- if (options.kill)
- daemonize_kill();
+ glue_daemonize_init(&options);
stats_global_init();
tag_lib_init();
@@ -291,12 +316,7 @@ int main(int argc, char *argv[])
create_db = !glue_db_init_and_load(&options);
-#ifdef ENABLE_SQLITE
- success = sticker_global_init(config_get_path(CONF_STICKER_FILE),
- &error);
- if (!success)
- g_error("%s", error->message);
-#endif
+ glue_sticker_init();
command_init();
initialize_decoder_and_player();
@@ -326,8 +346,7 @@ int main(int argc, char *argv[])
g_error("directory update failed");
}
-
- state_file_init(config_get_path(CONF_STATE_FILE));
+ glue_state_file_init();
config_global_check();