29 #include "xmms_configuration.h"
64 static void install_scripts (
const gchar *into_dir);
65 static void spawn_script_setup (gpointer data);
98 static GMainLoop *mainloop;
101 static gchar *conffile = NULL;
112 ret = g_tree_new_full ((GCompareDataFunc) strcmp, NULL,
117 g_tree_insert (ret, (gpointer)
"version",
119 g_tree_insert (ret, (gpointer)
"uptime",
126 xmms_main_client_list_foreach (
xmms_plugin_t *plugin, gpointer data)
139 *list = g_list_prepend (*list, dict);
163 do_scriptdir (
const gchar *scriptdir,
const gchar *arg1)
168 gchar *argv[3] = {NULL, NULL, NULL};
170 XMMS_DBG (
"Running scripts in %s", scriptdir);
171 if (!g_file_test (scriptdir, G_FILE_TEST_IS_DIR)) {
172 g_mkdir_with_parents (scriptdir, 0755);
173 install_scripts (scriptdir);
176 dir = g_dir_open (scriptdir, 0, &err);
178 xmms_log_error (
"Could not open script dir '%s' error: %s", scriptdir, err->message);
182 argv[1] = g_strdup (arg1);
183 while ((f = g_dir_read_name (dir))) {
184 argv[0] = g_strdup_printf (
"%s/%s", scriptdir, f);
185 if (g_file_test (argv[0], G_FILE_TEST_IS_EXECUTABLE)) {
186 if (!g_spawn_async (g_get_home_dir (), argv, NULL, 0,
187 spawn_script_setup, NULL, NULL, &err)) {
189 argv[0], err->message);
204 spawn_script_setup (gpointer data)
226 }
else if (!g_file_test (configdir, G_FILE_TEST_IS_DIR)) {
227 g_mkdir_with_parents (configdir, 0755);
244 const gchar *outname;
246 if (!mainobj->output)
255 xmms_log_error (
"Baaaaad output plugin, try to change the output.plugin config variable to something useful");
258 xmms_log_error (
"Baaaaad output plugin, try to change the output.plugin config variable to something useful");
284 g_usleep (G_USEC_PER_SEC);
297 xmms_main_unregister_ipc_commands ();
315 XMMS_DBG (
"Client '%s' connected", client);
319 kill_server (gpointer
object) {
342 g_timeout_add (1, kill_server,
object);
346 install_scripts (
const gchar *into_dir)
354 s = strrchr (into_dir, G_DIR_SEPARATOR);
360 g_snprintf (path,
XMMS_PATH_MAX,
"%s/scripts/%s", SHAREDDIR, s);
362 dir = g_dir_open (path, 0, &err);
368 while ((f = g_dir_read_name (dir))) {
369 gchar *source = g_strdup_printf (
"%s/%s", path, f);
370 gchar *dest = g_strdup_printf (
"%s/%s", into_dir, f);
389 printf (
"XMMS2 version " XMMS_VERSION
"\n");
390 printf (
"Copyright (C) 2003-2011 XMMS2 Team\n");
391 printf (
"This is free software; see the source for copying conditions.\n");
392 printf (
"There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A\n");
393 printf (
"PARTICULAR PURPOSE.\n");
394 printf (
" Using glib version %d.%d.%d (compiled against "
395 G_STRINGIFY (GLIB_MAJOR_VERSION)
"."
396 G_STRINGIFY (GLIB_MINOR_VERSION)
"."
397 G_STRINGIFY (GLIB_MICRO_VERSION)
")\n",
418 gboolean verbose = FALSE;
419 gboolean quiet = FALSE;
420 gboolean version = FALSE;
421 gboolean runasroot = FALSE;
422 gboolean showhelp = FALSE;
423 const gchar *outname = NULL;
424 const gchar *ipcpath = NULL;
427 GOptionContext *context = NULL;
428 GError *error = NULL;
430 setlocale (LC_ALL,
"");
435 GOptionEntry opts[] = {
436 {
"verbose",
'v', 0, G_OPTION_ARG_NONE, &verbose,
"Increase verbosity", NULL},
437 {
"quiet",
'q', 0, G_OPTION_ARG_NONE, &quiet,
"Decrease verbosity", NULL},
438 {
"version",
'V', 0, G_OPTION_ARG_NONE, &version,
"Print version", NULL},
439 {
"output",
'o', 0, G_OPTION_ARG_STRING, &outname,
"Use 'x' as output plugin",
"<x>"},
440 {
"ipc-socket",
'i', 0, G_OPTION_ARG_FILENAME, &ipcpath,
"Listen to socket 'url'",
"<url>"},
441 {
"plugindir",
'p', 0, G_OPTION_ARG_FILENAME, &ppath,
"Search for plugins in directory 'foo'",
"<foo>"},
442 {
"conf",
'c', 0, G_OPTION_ARG_FILENAME, &conffile,
"Specify alternate configuration file",
"<file>"},
443 {
"status-fd",
's', 0, G_OPTION_ARG_INT, &status_fd,
"Specify a filedescriptor to write to when started",
"fd"},
444 {
"yes-run-as-root", 0, 0, G_OPTION_ARG_NONE, &runasroot,
"Give me enough rope to shoot myself in the foot", NULL},
445 {
"show-help",
'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &showhelp,
"Use --help or -? instead", NULL},
450 if (glib_major_version != GLIB_MAJOR_VERSION ||
451 glib_minor_version < GLIB_MINOR_VERSION) {
452 g_print (
"xmms2d is build against version %d.%d,\n"
453 "but is (runtime) linked against %d.%d.\n"
454 "Refusing to start.\n",
455 GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION,
456 glib_major_version, glib_minor_version);
462 context = g_option_context_new (
"- XMMS2 Daemon");
463 g_option_context_add_main_entries (context, opts, NULL);
464 if (!g_option_context_parse (context, &argc, &argv, &error) || error) {
465 g_print (
"Error parsing options: %s\n", error->message);
466 g_clear_error (&error);
470 #if GLIB_CHECK_VERSION(2,14,0)
471 g_print (
"%s", g_option_context_get_help (context, TRUE, NULL));
474 g_print (
"Please use --help or -? for help\n");
478 g_option_context_free (context);
481 g_print (
"There were unknown options, aborting!\n");
487 g_print (
"***************************************\n");
488 g_print (
"Warning! You are running XMMS2D as root, this is a bad idea!\nBut I'll allow it since you asked nicely.\n");
489 g_print (
"***************************************\n\n");
491 g_print (
"PLEASE DON'T RUN XMMS2D AS ROOT!\n\n(if you really must, read the help)\n");
506 g_thread_init (NULL);
508 g_random_set_seed (time (NULL));
554 change_output, mainobj);
565 "output.plugin config variable to something useful");
569 if (!mainobj->output) {
575 if (status_fd != -1) {
576 write (status_fd,
"+", 1);
581 xmms_main_register_ipc_commands (
XMMS_OBJECT (mainobj));
584 mainobj->starttime = time (NULL);
587 g_strlcpy (default_path, ipcpath,
sizeof (default_path));
589 tmp = strchr (default_path,
';');
594 g_setenv (
"XMMS_PATH", default_path, TRUE);
597 g_setenv(
"XMMS_PATH_FULL", ipcpath, TRUE);
612 mainloop = g_main_loop_new (NULL, FALSE);
614 g_main_loop_run (mainloop);