aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c84
1 files changed, 64 insertions, 20 deletions
diff --git a/src/main.c b/src/main.c
index 5035a4836..3d0aaabc9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -90,13 +90,39 @@ 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();
+}
+
+static void
+glue_mapper_init(void)
+{
+ const char *music_dir, *playlist_dir;
+
+ music_dir = config_get_path(CONF_MUSIC_DIR);
+#if GLIB_CHECK_VERSION(2,14,0)
+ if (music_dir == NULL)
+ music_dir = g_get_user_special_dir(G_USER_DIRECTORY_MUSIC);
+#endif
+
+ playlist_dir = config_get_path(CONF_PLAYLIST_DIR);
+
+ mapper_init(music_dir, playlist_dir);
+}
+
/**
* Returns the database. If this function returns false, this has not
* succeeded, and the caller should create the database after the
* process has been daemonized.
*/
static bool
-openDB(const Options *options)
+glue_db_init_and_load(const struct options *options)
{
const char *path = config_get_path(CONF_DB_FILE);
bool ret;
@@ -115,7 +141,7 @@ openDB(const Options *options)
db_init(path);
- if (options->createDB > 0)
+ if (options->create_db > 0)
/* don't attempt to load the old database */
return false;
@@ -124,7 +150,7 @@ openDB(const Options *options)
g_warning("Failed to load database: %s", error->message);
g_error_free(error);
- if (options->createDB < 0)
+ if (options->create_db < 0)
g_error("can't open db file and using "
"\"--no-create-db\" command line option");
@@ -141,6 +167,29 @@ openDB(const 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
@@ -228,7 +277,7 @@ idle_event_emitted(void)
int main(int argc, char *argv[])
{
- Options options;
+ struct options options;
clock_t start;
bool create_db;
@@ -251,17 +300,13 @@ int main(int argc, char *argv[])
tag_pool_init();
config_global_init();
- parseOptions(argc, argv, &options);
+ 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();
- log_init(options.verbose, options.stdOutput);
+ log_init(options.verbose, options.stderr);
listen_global_init();
@@ -275,9 +320,9 @@ int main(int argc, char *argv[])
event_pipe_register(PIPE_EVENT_IDLE, idle_event_emitted);
path_global_init();
- mapper_init();
+ glue_mapper_init();
initPermissions();
- initPlaylist();
+ playlist_global_init();
spl_global_init();
#ifdef ENABLE_ARCHIVE
archive_plugin_init_all();
@@ -285,11 +330,9 @@ int main(int argc, char *argv[])
decoder_plugin_init_all();
update_global_init();
- create_db = !openDB(&options);
+ create_db = !glue_db_init_and_load(&options);
-#ifdef ENABLE_SQLITE
- sticker_global_init(config_get_path(CONF_STICKER_FILE));
-#endif
+ glue_sticker_init();
command_init();
initialize_decoder_and_player();
@@ -303,7 +346,7 @@ int main(int argc, char *argv[])
daemonize(options.daemon);
- setup_log_output(options.stdOutput);
+ setup_log_output(options.stderr);
initSigHandlers();
@@ -319,8 +362,9 @@ int main(int argc, char *argv[])
g_error("directory update failed");
}
+ glue_state_file_init();
- state_file_init(config_get_path(CONF_STATE_FILE));
+ config_global_check();
/* run the main loop */
@@ -335,7 +379,7 @@ int main(int argc, char *argv[])
finishZeroconf();
client_manager_deinit();
listen_global_finish();
- finishPlaylist();
+ playlist_global_finish();
start = clock();
db_finish();