static void ai_init(void) { set_enable_debug(enable_debug); if (server == NULL) server = g_strdup(PIONEERS_DEFAULT_GAME_HOST); if (port == NULL) port = g_strdup(PIONEERS_DEFAULT_GAME_PORT); printf("ai port is %s\n", port); g_random_set_seed(time(NULL) + getpid()); if (!name) { /* ai commandline error */ g_print(_("A name must be provided.\n")); exit(0); } if (ai != NULL) { gint i; for (i = 0; i < G_N_ELEMENTS(algorithms); i++) { if (!strcmp(algorithms[i].name, ai)) active_algorithm = i; } } log_message(MSG_INFO, _("Type of computer player: %s\n"), algorithms[active_algorithm].name); algorithms[active_algorithm].init_func(); }
static const char * select_theme (GSManager *manager) { const char *theme = NULL; g_return_val_if_fail (manager != NULL, NULL); g_return_val_if_fail (GS_IS_MANAGER (manager), NULL); if (manager->priv->saver_mode == GS_MODE_BLANK_ONLY) { return NULL; } if (manager->priv->themes) { int number = 0; if (manager->priv->saver_mode == GS_MODE_RANDOM) { g_random_set_seed (time (NULL)); number = g_random_int_range (0, g_slist_length (manager->priv->themes)); } theme = g_slist_nth_data (manager->priv->themes, number); } return theme; }
static void initrand(void) { struct timeval tv; gettimeofday(&tv,NULL); srand(tv.tv_usec); g_random_set_seed(tv.tv_usec); }
static void ai_init(int argc, char **argv) { GOptionContext *context; GError *error = NULL; /* Long description in the commandline for pioneersai: help */ context = g_option_context_new(_("- Computer player for Pioneers")); g_option_context_add_main_entries(context, commandline_entries, PACKAGE); g_option_context_parse(context, &argc, &argv, &error); if (error != NULL) { g_print("%s\n", error->message); g_error_free(error); exit(1); } if (show_version) { g_print(_("Pioneers version:")); g_print(" "); g_print(FULL_VERSION); g_print("\n"); exit(0); } set_enable_debug(enable_debug); if (server == NULL) server = g_strdup(PIONEERS_DEFAULT_GAME_HOST); if (port == NULL) port = g_strdup(PIONEERS_DEFAULT_GAME_PORT); printf("ai port is %s\n", port); g_random_set_seed(time(NULL) + getpid()); if (!name) { /* ai commandline error */ g_print(_("A name must be provided.\n")); exit(0); } set_ui_driver(&Glib_Driver); log_set_func_default(); if (ai != NULL) { gint i; for (i = 0; i < G_N_ELEMENTS(algorithms); i++) { if (!strcmp(algorithms[i].name, ai)) active_algorithm = i; } } log_message(MSG_INFO, _("Type of computer player: %s\n"), algorithms[active_algorithm].name); algorithms[active_algorithm].init_func(argc, argv); }
static void game_init (void) { g_random_set_seed ((guint) time (NULL)); vboard = veleng_init (); anim = ANIM_NONE; gameover = TRUE; player_active = FALSE; player = PLAYER1; winner = NOBODY; score[PLAYER1] = 0; score[PLAYER2] = 0; score[NOBODY] = 0; who_starts = PLAYER2; /* This gets reversed immediately. */ clear_board (); }
static void test_run (void) { FlowIPService *loopback_service; FlowIPAddr *ip_addr; gint i; g_random_set_seed (time (NULL)); /* Set up a buffer with random data */ buffer = g_malloc (BUFFER_SIZE); for (i = 0; i < BUFFER_SIZE; ) { guchar *p = buffer + i; if (i < BUFFER_SIZE - 4) { *((guint32 *) p) = g_random_int (); i += 4; } else { *p = (guchar) g_random_int (); i++; } } test_print ("Probability of pause is %d out of %d\n", PAUSE_PROBABILITY, PROBABILITY_MULTIPLIER); src_index = 0; dest_index = 0; finished_reading = FALSE; finished_writing = FALSE; reads_are_blocked = FALSE; writes_are_blocked = FALSE; loopback_service = flow_ip_service_new (); ip_addr = flow_ip_addr_new (); flow_ip_addr_set_string (ip_addr, "127.0.0.1"); flow_ip_service_set_port (loopback_service, 2533); flow_ip_service_add_address (loopback_service, ip_addr); g_object_unref (ip_addr); listener_shunt = flow_open_tcp_listener (loopback_service); flow_shunt_set_read_func (listener_shunt, read_from_listener, listener_shunt); sender_shunt = flow_connect_to_tcp (loopback_service, 0); flow_shunt_set_write_func (sender_shunt, write_to_shunt, sender_shunt); g_object_unref (loopback_service); /* Run */ test_run_main_loop (); /* Cleanup */ flow_shunt_destroy (listener_shunt); if (sender_shunt) flow_shunt_destroy (sender_shunt); if (recipient_shunt) flow_shunt_destroy (recipient_shunt); g_free (buffer); }
/** * The xmms2 daemon main initialisation function */ int main (int argc, char **argv) { xmms_output_plugin_t *o_plugin; xmms_config_property_t *cv; xmms_main_t *mainobj; int loglevel = 1; xmms_playlist_t *playlist; gchar default_path[XMMS_PATH_MAX + 16], *tmp; gboolean verbose = FALSE; gboolean quiet = FALSE; gboolean version = FALSE; gboolean nologging = FALSE; gboolean runasroot = FALSE; gboolean showhelp = FALSE; const gchar *outname = NULL; const gchar *ipcpath = NULL; gchar *ppath = NULL; int status_fd = -1; GOptionContext *context = NULL; GError *error = NULL; setlocale (LC_ALL, ""); /** * The options that the server accepts. */ GOptionEntry opts[] = { {"verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Increase verbosity", NULL}, {"quiet", 'q', 0, G_OPTION_ARG_NONE, &quiet, "Decrease verbosity", NULL}, {"version", 'V', 0, G_OPTION_ARG_NONE, &version, "Print version", NULL}, {"no-logging", 'n', 0, G_OPTION_ARG_NONE, &nologging, "Disable logging", NULL}, {"output", 'o', 0, G_OPTION_ARG_STRING, &outname, "Use 'x' as output plugin", "<x>"}, {"ipc-socket", 'i', 0, G_OPTION_ARG_FILENAME, &ipcpath, "Listen to socket 'url'", "<url>"}, {"plugindir", 'p', 0, G_OPTION_ARG_FILENAME, &ppath, "Search for plugins in directory 'foo'", "<foo>"}, {"conf", 'c', 0, G_OPTION_ARG_FILENAME, &conffile, "Specify alternate configuration file", "<file>"}, {"status-fd", 's', 0, G_OPTION_ARG_INT, &status_fd, "Specify a filedescriptor to write to when started", "fd"}, {"yes-run-as-root", 0, 0, G_OPTION_ARG_NONE, &runasroot, "Give me enough rope to shoot myself in the foot", NULL}, {"show-help", 'h', G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &showhelp, "Use --help or -? instead", NULL}, {NULL} }; /** Check that we are running against the correct glib version */ if (glib_major_version != GLIB_MAJOR_VERSION || glib_minor_version < GLIB_MINOR_VERSION) { g_print ("xmms2d is build against version %d.%d,\n" "but is (runtime) linked against %d.%d.\n" "Refusing to start.\n", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, glib_major_version, glib_minor_version); exit (EXIT_FAILURE); } xmms_signal_block (); context = g_option_context_new ("- XMMS2 Daemon"); g_option_context_add_main_entries (context, opts, NULL); if (!g_option_context_parse (context, &argc, &argv, &error) || error) { g_print ("Error parsing options: %s\n", error->message); g_clear_error (&error); exit (EXIT_FAILURE); } if (showhelp) { #if GLIB_CHECK_VERSION(2,14,0) g_print ("%s", g_option_context_get_help (context, TRUE, NULL)); exit (EXIT_SUCCESS); #else g_print ("Please use --help or -? for help\n"); exit (EXIT_FAILURE); #endif } g_option_context_free (context); if (argc != 1) { g_print ("There were unknown options, aborting!\n"); exit (EXIT_FAILURE); } if (xmms_checkroot ()) { if (runasroot) { g_print ("***************************************\n"); g_print ("Warning! You are running XMMS2D as root, this is a bad idea!\nBut I'll allow it since you asked nicely.\n"); g_print ("***************************************\n\n"); } else { g_print ("PLEASE DON'T RUN XMMS2D AS ROOT!\n\n(if you really must, read the help)\n"); exit (EXIT_FAILURE); } } if (verbose) { loglevel++; } else if (quiet) { loglevel--; } if (version) { print_version (); } g_thread_init (NULL); g_random_set_seed (time (NULL)); xmms_log_init (loglevel); xmms_ipc_init (); load_config (); cv = xmms_config_property_register ("core.logtsfmt", "%H:%M:%S ", NULL, NULL); xmms_log_set_format (xmms_config_property_get_string (cv)); xmms_fallback_ipcpath_get (default_path, sizeof (default_path)); cv = xmms_config_property_register ("core.ipcsocket", default_path, on_config_ipcsocket_change, NULL); if (!ipcpath) { /* * if not ipcpath is specifed on the cmd line we * grab it from the config */ ipcpath = xmms_config_property_get_string (cv); } if (!xmms_ipc_setup_server (ipcpath)) { xmms_ipc_shutdown (); xmms_log_fatal ("IPC failed to init!"); } if (!xmms_plugin_init (ppath)) { return 1; } playlist = xmms_playlist_init (); xform_obj = xmms_xform_object_init (); bindata_obj = xmms_bindata_init (); mainobj = xmms_object_new (xmms_main_t, xmms_main_destroy); /* find output plugin. */ cv = xmms_config_property_register ("output.plugin", XMMS_OUTPUT_DEFAULT, change_output, mainobj); if (outname) { xmms_config_property_set_data (cv, outname); } outname = xmms_config_property_get_string (cv); xmms_log_info ("Using output plugin: %s", outname); o_plugin = (xmms_output_plugin_t *)xmms_plugin_find (XMMS_PLUGIN_TYPE_OUTPUT, outname); if (!o_plugin) { xmms_log_error ("Baaaaad output plugin, try to change the" "output.plugin config variable to something usefull"); } mainobj->output = xmms_output_new (o_plugin, playlist); if (!mainobj->output) { xmms_log_fatal ("Failed to create output object!"); } mainobj->vis = xmms_visualization_new (mainobj->output); if (status_fd != -1) { write (status_fd, "+", 1); } xmms_signal_init (XMMS_OBJECT (mainobj)); xmms_ipc_object_register (XMMS_IPC_OBJECT_MAIN, XMMS_OBJECT (mainobj)); xmms_ipc_broadcast_register (XMMS_OBJECT (mainobj), XMMS_IPC_SIGNAL_QUIT); xmms_object_cmd_add (XMMS_OBJECT (mainobj), XMMS_IPC_CMD_QUIT, XMMS_CMD_FUNC (quit)); xmms_object_cmd_add (XMMS_OBJECT (mainobj), XMMS_IPC_CMD_HELLO, XMMS_CMD_FUNC (hello)); xmms_object_cmd_add (XMMS_OBJECT (mainobj), XMMS_IPC_CMD_PLUGIN_LIST, XMMS_CMD_FUNC (plugin_list)); xmms_object_cmd_add (XMMS_OBJECT (mainobj), XMMS_IPC_CMD_STATS, XMMS_CMD_FUNC (stats)); /* Save the time we started in order to count uptime */ mainobj->starttime = time (NULL); /* Dirty hack to tell XMMS_PATH a valid path */ g_strlcpy (default_path, ipcpath, sizeof (default_path)); tmp = strchr (default_path, ';'); if (tmp) { *tmp = '\0'; } g_setenv ("XMMS_PATH", default_path, TRUE); /* Also put the full path for clients that understands */ g_setenv("XMMS_PATH_FULL", ipcpath, TRUE); tmp = XMMS_BUILD_PATH ("shutdown.d"); cv = xmms_config_property_register ("core.shutdownpath", tmp, NULL, NULL); g_free (tmp); tmp = XMMS_BUILD_PATH ("startup.d"); cv = xmms_config_property_register ("core.startuppath", tmp, NULL, NULL); g_free (tmp); /* Startup dir */ do_scriptdir (xmms_config_property_get_string (cv), "start"); mainloop = g_main_loop_new (NULL, FALSE); g_main_loop_run (mainloop); return 0; }
int main (int argc, char *argv[]) { gchar *in_dir; GList *tmp; struct evhttp_uri *uri; struct timeval tv; log_level = LOG_debug; event_set_mem_functions (g_malloc, g_realloc, g_free); // init SSL libraries CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free); ENGINE_load_builtin_engines (); ENGINE_register_all_complete (); ERR_load_crypto_strings (); OpenSSL_add_all_algorithms (); SSL_load_error_strings (); SSL_library_init (); if (!RAND_poll ()) { fprintf(stderr, "RAND_poll() failed.\n"); return 1; } g_random_set_seed (time (NULL)); in_dir = g_dir_make_tmp (NULL, NULL); g_assert (in_dir); app = g_new0 (Application, 1); app->files_count = 10; app->evbase = event_base_new (); app->dns_base = evdns_base_new (app->evbase, 1); app->conf = conf_create (); conf_add_boolean (app->conf, "log.use_syslog", TRUE); conf_add_uint (app->conf, "auth.ttl", 85800); conf_add_int (app->conf, "pool.writers", 2); conf_add_int (app->conf, "pool.readers", 2); conf_add_int (app->conf, "pool.operations", 4); conf_add_uint (app->conf, "pool.max_requests_per_pool", 100); conf_add_int (app->conf, "connection.timeout", 20); conf_add_int (app->conf, "connection.retries", -1); conf_add_uint (app->conf, "filesystem.dir_cache_max_time", 5); conf_add_boolean (app->conf, "filesystem.cache_enabled", TRUE); conf_add_string (app->conf, "filesystem.cache_dir", "/tmp/hydrafs"); conf_add_string (app->conf, "filesystem.cache_dir_max_size", "1Gb"); conf_add_boolean (app->conf, "statistics.enabled", TRUE); conf_add_int (app->conf, "statistics.port", 8011); conf_add_string (app->conf, "auth.user", "test:tester"); conf_add_string (app->conf, "auth.key", "testing"); uri = evhttp_uri_parse ("https://10.0.0.104:8080/auth/v1.0"); app->ssl_ctx = SSL_CTX_new (TLSv1_client_method ()); app->stats = hfs_stats_srv_create (app); app->auth_client = auth_client_create (app, uri); app->http = http_client_create (app); // start server start_srv (app->evbase, in_dir); app->timeout = evtimer_new (app->evbase, on_output_timer, NULL); evutil_timerclear(&tv); tv.tv_sec = 0; tv.tv_usec = 500; event_add (app->timeout, &tv); event_base_dispatch (app->evbase); evhttp_uri_free (uri); event_del (app->timeout); event_free (app->timeout); evhttp_free (app->http_srv); auth_client_destroy (app->auth_client); evdns_base_free (app->dns_base, 0); event_base_free (app->evbase); conf_destroy (app->conf); g_free (app); return 0; }
void random_set_seed(unsigned int seed) { g_random_set_seed(seed); }
int main (int argc, char *argv[]) { GError *error = NULL; GOptionGroup *option_group; GOptionContext *context; const gchar *simulation_filename, *introspection_filename; gchar *simulation_code, *introspection_xml; MainData data; GPtrArray/*<DfsmObject>*/ *simulated_objects; const gchar *test_program_name; GPtrArray/*<string>*/ *test_program_argv; guint i; gchar *time_str, *command_line, *log_header, *seed_str; GDateTime *date_time; GFile *working_directory_file, *dbus_daemon_config_file; /* Set up localisation. */ setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #if !GLIB_CHECK_VERSION (2, 35, 0) g_type_init (); #endif g_set_application_name (_("D-Bus Simulator")); /* Take a copy of the command line, for use in printing the log headers later. */ command_line = g_strjoinv (" ", argv); /* Parse command line options */ context = g_option_context_new (_("[simulation code file] [introspection XML file] -- [executable-file] [arguments]")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); g_option_context_set_summary (context, _("Simulates the server in a D-Bus client–server conversation.")); g_option_context_add_main_entries (context, main_entries, GETTEXT_PACKAGE); /* Logging option group */ option_group = g_option_group_new ("logging", _("Logging Options:"), _("Show help options for output logging"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, logging_entries); g_option_context_add_group (context, option_group); /* Testing option group */ option_group = g_option_group_new ("testing", _("Testing Options:"), _("Show help options for test runs and timeouts"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, testing_entries); g_option_context_add_group (context, option_group); /* Test program option group */ option_group = g_option_group_new ("test-program", _("Test Program Options:"), _("Show help options for the program under test"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, test_program_entries); g_option_context_add_group (context, option_group); /* dbus-daemon option group */ option_group = g_option_group_new ("dbus-daemon", _("D-Bus Daemon Options:"), _("Show help options for the dbus-daemon"), NULL, NULL); g_option_group_set_translation_domain (option_group, GETTEXT_PACKAGE); g_option_group_add_entries (option_group, dbus_daemon_entries); g_option_context_add_group (context, option_group); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_printerr (_("Error parsing command line options: %s"), error->message); g_printerr ("\n"); print_help_text (context); g_error_free (error); g_option_context_free (context); g_free (command_line); exit (STATUS_INVALID_OPTIONS); } /* Extract the simulation and the introspection filenames. */ if (argc < 3) { g_printerr (_("Error parsing command line options: %s"), _("Simulation and introspection filenames must be provided")); g_printerr ("\n"); print_help_text (context); g_option_context_free (context); g_free (command_line); exit (STATUS_INVALID_OPTIONS); } simulation_filename = argv[1]; introspection_filename = argv[2]; /* Extract the remaining arguments */ if (argc < 4) { g_printerr (_("Error parsing command line options: %s"), _("Test program must be provided")); g_printerr ("\n"); print_help_text (context); g_option_context_free (context); g_free (command_line); exit (STATUS_INVALID_OPTIONS); } /* Work out where the test program's command line starts. g_option_context_parse() sometimes leaves the ‘--’ in argv. */ if (strcmp (argv[3], "--") == 0) { i = 4; } else { i = 3; } test_program_name = argv[i++]; test_program_argv = g_ptr_array_new_with_free_func (g_free); for (; i < (guint) argc; i++) { g_ptr_array_add (test_program_argv, g_strdup (argv[i])); } g_option_context_free (context); /* Set up logging. */ dsim_logging_init (test_program_log_file, test_program_log_fd, dbus_daemon_log_file, dbus_daemon_log_fd, simulator_log_file, simulator_log_fd, &error); if (error != NULL) { g_printerr (_("Error setting up logging: %s"), error->message); g_printerr ("\n"); g_error_free (error); g_free (command_line); exit (STATUS_LOGGING_PROBLEM); } /* Output a log header to each of the log streams. */ date_time = g_date_time_new_now_utc (); time_str = g_date_time_format (date_time, "%F %TZ"); g_date_time_unref (date_time); log_header = g_strdup_printf (_("Bendy Bus (number %s) left the depot at %s using command line: %s"), PACKAGE_VERSION, time_str, command_line); g_log (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, "%s", log_header); g_log (dsim_logging_get_domain_name (DSIM_LOG_DBUS_DAEMON), G_LOG_LEVEL_MESSAGE, "%s", log_header); g_log (dsim_logging_get_domain_name (DSIM_LOG_TEST_PROGRAM), G_LOG_LEVEL_MESSAGE, "%s", log_header); g_free (log_header); g_free (time_str); g_free (command_line); /* Set up the random number generator. */ if (random_seed == 0) { random_seed = g_get_real_time (); } seed_str = g_strdup_printf ("%" G_GINT64_FORMAT, random_seed); g_message (_("Note: Setting random number generator seed to %s."), seed_str); g_free (seed_str); g_random_set_seed ((guint32) random_seed); /* Load the files. */ g_file_get_contents (simulation_filename, &simulation_code, NULL, &error); if (error != NULL) { g_printerr (_("Error loading simulation code from file ‘%s’: %s"), simulation_filename, error->message); g_printerr ("\n"); g_error_free (error); exit (STATUS_UNREADABLE_FILE); } g_file_get_contents (introspection_filename, &introspection_xml, NULL, &error); if (error != NULL) { g_printerr (_("Error loading introspection XML from file ‘%s’: %s"), introspection_filename, error->message); g_printerr ("\n"); g_error_free (error); g_free (simulation_code); exit (STATUS_UNREADABLE_FILE); } /* Build the DfsmObjects. */ simulated_objects = dfsm_object_factory_from_data (simulation_code, introspection_xml, &error); g_free (introspection_xml); g_free (simulation_code); if (error != NULL) { g_printerr (_("Error creating simulated DFSMs: %s"), error->message); g_printerr ("\n"); g_error_free (error); exit (STATUS_INVALID_CODE); } /* Prepare the main data struct, which will last for the lifetime of the program. */ data.main_loop = g_main_loop_new (NULL, FALSE); data.exit_status = STATUS_SUCCESS; data.exit_signal = EXIT_SIGNAL_INVALID; data.test_program = NULL; data.connection = NULL; data.simulated_objects = g_ptr_array_ref (simulated_objects); data.outstanding_registration_callbacks = 0; data.test_run_inactivity_timeout_id = 0; data.test_program_spawn_end_signal = 0; data.test_program_process_died_signal = 0; data.test_program_sigkill_timeout_id = 0; if (run_infinitely == TRUE || (run_iters == 0 && run_time == 0)) { data.num_test_runs_remaining = -1; } else { data.num_test_runs_remaining = run_iters; } g_ptr_array_unref (simulated_objects); /* Store the test program name and argv, since we can only spawn it once we know the bus address. */ data.test_program_name = g_strdup (test_program_name); data.test_program_argv = g_ptr_array_ref (test_program_argv); g_ptr_array_unref (test_program_argv); /* Set up signal handlers for SIGINT and SIGTERM so that we can close gracefully. */ g_unix_signal_add (SIGINT, (GSourceFunc) sigint_handler_cb, &data); g_unix_signal_add (SIGTERM, (GSourceFunc) sigterm_handler_cb, &data); /* Create a working directory. */ prepare_dbus_daemon_working_directory (&(data.working_directory_file), &working_directory_file, &dbus_daemon_config_file, &error); if (error != NULL) { g_printerr (_("Error creating dbus-daemon working directory: %s"), error->message); g_printerr ("\n"); g_error_free (error); main_data_clear (&data); dsim_logging_finalise (); exit (STATUS_TMP_DIR_ERROR); } /* Start up our own private dbus-daemon instance. */ data.dbus_daemon = dsim_dbus_daemon_new (working_directory_file, dbus_daemon_config_file); data.dbus_address = NULL; g_object_unref (dbus_daemon_config_file); g_object_unref (working_directory_file); g_signal_connect (data.dbus_daemon, "process-died", (GCallback) dbus_daemon_died_cb, &data); g_signal_connect (data.dbus_daemon, "notify::bus-address", (GCallback) dbus_daemon_notify_bus_address_cb, &data); dsim_program_wrapper_spawn (DSIM_PROGRAM_WRAPPER (data.dbus_daemon), &error); if (error != NULL) { g_printerr (_("Error spawning private dbus-daemon instance: %s"), error->message); g_printerr ("\n"); g_error_free (error); main_data_clear (&data); dsim_logging_finalise (); exit (STATUS_DAEMON_SPAWN_ERROR); } /* Start the main loop and wait for the dbus-daemon to send us its address. */ g_main_loop_run (data.main_loop); /* Free the main data struct. */ main_data_clear (&data); dsim_logging_finalise (); if (data.exit_signal != EXIT_SIGNAL_INVALID) { struct sigaction action; /* Propagate the signal to the default handler. */ action.sa_handler = SIG_DFL; sigemptyset (&action.sa_mask); action.sa_flags = 0; sigaction (data.exit_signal, &action, NULL); kill (getpid (), data.exit_signal); } return data.exit_status; }
struct rspamd_worker * rspamd_fork_worker (struct rspamd_main *rspamd_main, struct rspamd_worker_conf *cf, guint index, struct event_base *ev_base) { struct rspamd_worker *wrk; gint rc; struct rlimit rlim; /* Starting worker process */ wrk = (struct rspamd_worker *) g_malloc0 (sizeof (struct rspamd_worker)); if (!rspamd_socketpair (wrk->control_pipe)) { msg_err ("socketpair failure: %s", strerror (errno)); exit (-errno); } if (!rspamd_socketpair (wrk->srv_pipe)) { msg_err ("socketpair failure: %s", strerror (errno)); exit (-errno); } wrk->srv = rspamd_main; wrk->type = cf->type; wrk->cf = cf; REF_RETAIN (cf); wrk->index = index; wrk->ctx = cf->ctx; wrk->finish_actions = g_ptr_array_new (); wrk->pid = fork (); switch (wrk->pid) { case 0: /* Update pid for logging */ rspamd_log_update_pid (cf->type, rspamd_main->logger); /* Init PRNG after fork */ rc = ottery_init (rspamd_main->cfg->libs_ctx->ottery_cfg); if (rc != OTTERY_ERR_NONE) { msg_err_main ("cannot initialize PRNG: %d", rc); g_assert (0); } rspamd_random_seed_fast (); g_random_set_seed (ottery_rand_uint32 ()); #ifdef HAVE_EVUTIL_RNG_INIT evutil_secure_rng_init (); #endif /* Remove the inherited event base */ event_reinit (rspamd_main->ev_base); event_base_free (rspamd_main->ev_base); /* Drop privilleges */ rspamd_worker_drop_priv (rspamd_main); /* Set limits */ rspamd_worker_set_limits (rspamd_main, cf); /* Re-set stack limit */ getrlimit (RLIMIT_STACK, &rlim); rlim.rlim_cur = 100 * 1024 * 1024; rlim.rlim_max = rlim.rlim_cur; setrlimit (RLIMIT_STACK, &rlim); setproctitle ("%s process", cf->worker->name); rspamd_pidfile_close (rspamd_main->pfh); /* Do silent log reopen to avoid collisions */ rspamd_log_close (rspamd_main->logger); rspamd_log_open (rspamd_main->logger); wrk->start_time = rspamd_get_calendar_ticks (); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) # if (GLIB_MINOR_VERSION > 20) /* Ugly hack for old glib */ if (!g_thread_get_initialized ()) { g_thread_init (NULL); } # else g_thread_init (NULL); # endif #endif msg_info_main ("starting %s process %P (%d)", cf->worker->name, getpid (), index); /* Close parent part of socketpair */ close (wrk->control_pipe[0]); close (wrk->srv_pipe[0]); rspamd_socket_nonblocking (wrk->control_pipe[1]); rspamd_socket_nonblocking (wrk->srv_pipe[1]); /* Execute worker */ cf->worker->worker_start_func (wrk); exit (EXIT_FAILURE); break; case -1: msg_err_main ("cannot fork main process. %s", strerror (errno)); rspamd_pidfile_remove (rspamd_main->pfh); exit (-errno); break; default: /* Close worker part of socketpair */ close (wrk->control_pipe[1]); close (wrk->srv_pipe[1]); rspamd_socket_nonblocking (wrk->control_pipe[0]); rspamd_socket_nonblocking (wrk->srv_pipe[0]); rspamd_srv_start_watching (wrk, ev_base); /* Insert worker into worker's table, pid is index */ g_hash_table_insert (rspamd_main->workers, GSIZE_TO_POINTER ( wrk->pid), wrk); break; } return wrk; }
/*{{{ main */ int main (int argc, char *argv[]) { Application *app; gboolean verbose = FALSE; gboolean version = FALSE; GError *error = NULL; GOptionContext *context; gchar **s_params = NULL; gchar **s_config = NULL; gboolean foreground = FALSE; gchar conf_str[1023]; struct stat st; gchar **cache_dir = NULL; gchar **s_fuse_opts = NULL; gchar **s_log_file = NULL; guint32 part_size = 0; gboolean disable_syslog = FALSE; gboolean disable_stats = FALSE; gboolean force_head_requests = FALSE; gint uid = -1; gint gid = -1; gint fmode = -1; gint dmode = -1; struct event_config *ev_config; srand (time (NULL)); app = g_new0 (Application, 1); app->conf_path = g_build_filename (SYSCONFDIR, "riofs.conf.xml", NULL); g_snprintf (conf_str, sizeof (conf_str), "Path to configuration file. Default: %s", app->conf_path); GOptionEntry entries[] = { { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &s_params, NULL, NULL }, { "config", 'c', 0, G_OPTION_ARG_FILENAME_ARRAY, &s_config, conf_str, NULL}, { "uid", 0, 0, G_OPTION_ARG_INT, &uid, "Set UID of filesystem owner.", NULL }, { "gid", 0, 0, G_OPTION_ARG_INT, &gid, "Set GID of filesystem owner.", NULL }, { "fmode", 0, 0, G_OPTION_ARG_INT, &fmode, "Set mode for all files.", NULL }, { "dmode", 0, 0, G_OPTION_ARG_INT, &dmode, "Set mode for all directories.", NULL }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Flag. Do not daemonize process.", NULL }, { "cache-dir", 0, 0, G_OPTION_ARG_STRING_ARRAY, &cache_dir, "Set cache directory.", NULL }, { "fuse-options", 'o', 0, G_OPTION_ARG_STRING_ARRAY, &s_fuse_opts, "Fuse options.", "\"opt[,opt...]\"" }, { "disable-syslog", 0, 0, G_OPTION_ARG_NONE, &disable_syslog, "Flag. Disable logging to syslog.", NULL }, { "disable-stats", 0, 0, G_OPTION_ARG_NONE, &disable_stats, "Flag. Disable Statistics HTTP interface.", NULL }, { "part-size", 0, 0, G_OPTION_ARG_INT, &part_size, "Set file part size (in bytes).", NULL }, { "log-file", 'l', 0, G_OPTION_ARG_STRING_ARRAY, &s_log_file, "File to write output.", NULL }, { "force-head-requests", 0, 0, G_OPTION_ARG_NONE, &force_head_requests, "Flag. Send HEAD request for each file.", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Verbose output.", NULL }, { "version", 'V', 0, G_OPTION_ARG_NONE, &version, "Show application version and exit.", NULL }, { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } }; // init libraries CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free); ENGINE_load_builtin_engines (); ENGINE_register_all_complete (); ERR_load_crypto_strings (); OpenSSL_add_all_algorithms (); #ifdef SSL_ENABLED SSL_load_error_strings (); SSL_library_init (); #endif g_random_set_seed (time (NULL)); // init main app structure ev_config = event_config_new (); #if defined(__APPLE__) // method select is the preferred method on OS X. kqueue and poll are not supported. event_config_avoid_method (ev_config, "kqueue"); event_config_avoid_method (ev_config, "poll"); #endif app->evbase = event_base_new_with_config (ev_config); event_config_free (ev_config); if (!app->evbase) { LOG_err (APP_LOG, "Failed to create event base !"); application_destroy (app); return -1; } app->dns_base = evdns_base_new (app->evbase, 1); if (!app->dns_base) { LOG_err (APP_LOG, "Failed to create DNS base !"); application_destroy (app); return -1; } app->f_log = NULL; app->log_file_name = NULL; /*{{{ cmd line args */ // parse command line options context = g_option_context_new ("[bucketname] [mountpoint]"); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_description (context, "Please set both AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables!"); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_fprintf (stderr, "Failed to parse command line options: %s\n", error->message); application_destroy (app); g_option_context_free (context); return -1; } g_option_context_free (context); // check if --version is specified if (version) { g_fprintf (stdout, "RioFS File System v%s\n", VERSION); g_fprintf (stdout, "Copyright (C) 2012-2014 Paul Ionkin <*****@*****.**>\n"); g_fprintf (stdout, "Copyright (C) 2012-2014 Skoobe GmbH. All rights reserved.\n"); g_fprintf (stdout, "Libraries:\n"); g_fprintf (stdout, " GLib: %d.%d.%d libevent: %s fuse: %d.%d", GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION, LIBEVENT_VERSION, FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION ); #if defined(__APPLE__) || defined(__FreeBSD__) || !defined(__GLIBC__) g_fprintf (stdout, "\n"); #else g_fprintf (stdout, " glibc: %s\n", gnu_get_libc_version ()); #endif g_fprintf (stdout, "Features:\n"); g_fprintf (stdout, " libevent backend method: %s\n", event_base_get_method(app->evbase)); #ifdef SSL_ENABLED g_fprintf (stdout, " SSL enabled\n"); #endif /* { int i; const char **methods = event_get_supported_methods (); g_fprintf (stdout, " Available libevent backend methods:\n"); for (i = 0; methods[i] != NULL; ++i) { g_fprintf (stdout, " %s\n", methods[i]); } } */ return 0; } if (!s_params || g_strv_length (s_params) != 2) { LOG_err (APP_LOG, "Wrong number of provided arguments!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } if (verbose) log_level = LOG_debug; else log_level = LOG_msg; /*}}}*/ /*{{{ parse config file */ // user provided alternative config path if (s_config && g_strv_length (s_config) > 0) { g_free (app->conf_path); app->conf_path = g_strdup (s_config[0]); g_strfreev (s_config); } app->conf = conf_create (); if (access (app->conf_path, R_OK) == 0) { LOG_debug (APP_LOG, "Using config file: %s", app->conf_path); if (!conf_parse_file (app->conf, app->conf_path)) { LOG_err (APP_LOG, "Failed to parse configuration file: %s", app->conf_path); application_destroy (app); return -1; } } else { LOG_err (APP_LOG, "Configuration file is not found !"); application_destroy (app); return -1; } if (!conf_check_keys (app->conf, conf_keys_str, conf_keys_len)) { LOG_err (APP_LOG, "Configuration file is missing keys, please re-check your configuration file: %s", app->conf_path); application_destroy (app); return -1; } if (disable_syslog) { conf_set_boolean (app->conf, "log.use_syslog", FALSE); } // update logging settings logger_set_syslog (conf_get_boolean (app->conf, "log.use_syslog")); logger_set_color (conf_get_boolean (app->conf, "log.use_color")); if (cache_dir && g_strv_length (cache_dir) > 0) { conf_set_string (app->conf, "filesystem.cache_dir", cache_dir[0]); g_strfreev (cache_dir); } if (!verbose) log_level = conf_get_int (app->conf, "log.level"); if (uid >= 0) conf_set_int (app->conf, "filesystem.uid", uid); if (gid >= 0) conf_set_int (app->conf, "filesystem.gid", gid); if (fmode >= 0) conf_set_int (app->conf, "filesystem.file_mode", fmode); if (dmode >= 0) conf_set_int (app->conf, "filesystem.dir_mode", dmode); /*}}}*/ // try to get access parameters from the environment if (getenv ("AWS_ACCESS_KEY_ID")) { conf_set_string (app->conf, "s3.access_key_id", getenv ("AWS_ACCESS_KEY_ID")); // else check if it's set it the config file } else { if (!conf_node_exists (app->conf, "s3.access_key_id")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } if (getenv ("AWS_SECRET_ACCESS_KEY")) { conf_set_string (app->conf, "s3.secret_access_key", getenv ("AWS_SECRET_ACCESS_KEY")); } else { if (!conf_node_exists (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } } // check if both strings are set if (!conf_get_string (app->conf, "s3.access_key_id") || !conf_get_string (app->conf, "s3.secret_access_key")) { LOG_err (APP_LOG, "Environment variables are not set!\nTry `%s --help' for more information.", argv[0]); application_destroy (app); return -1; } // foreground is set if (foreground) conf_set_boolean (app->conf, "app.foreground", foreground); if (part_size) conf_set_uint (app->conf, "s3.part_size", part_size); if (disable_stats) conf_set_boolean (app->conf, "statistics.enabled", FALSE); if (force_head_requests) conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", TRUE); else conf_set_boolean (app->conf, "s3.force_head_requests_on_lookup", FALSE); conf_set_string (app->conf, "s3.bucket_name", s_params[0]); if (!application_set_url (app, conf_get_string (app->conf, "s3.endpoint"))) { application_destroy (app); return -1; } if (s_fuse_opts && g_strv_length (s_fuse_opts) > 0) { app->fuse_opts = g_strdup (s_fuse_opts[0]); g_strfreev (s_fuse_opts); } if (s_log_file && g_strv_length (s_log_file) > 0) { app->log_file_name = g_strdup (s_log_file[0]); app->f_log = fopen (s_log_file[0], "a+"); if (!app->f_log) { LOG_err (APP_LOG, "Failed to open log file: %s Error: %s", s_log_file[0], strerror (errno)); application_destroy (app); return -1; } LOG_debug (APP_LOG, "Using %s for storing application logs.", s_log_file[0]); logger_set_file (app->f_log); g_strfreev (s_log_file); } conf_set_string (app->conf, "app.mountpoint", s_params[1]); // check if directory exists if (stat (conf_get_string (app->conf, "app.mountpoint"), &st) == -1) { LOG_err (APP_LOG, "Mountpoint %s does not exist! Please check directory permissions!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } // check if it's a directory if (!S_ISDIR (st.st_mode)) { LOG_err (APP_LOG, "Mountpoint %s is not a directory!", conf_get_string (app->conf, "app.mountpoint")); application_destroy (app); return -1; } g_strfreev (s_params); #ifdef SSL_ENABLED app->ssl_ctx = SSL_CTX_new (SSLv23_client_method ()); if (!app->ssl_ctx) { LOG_err (APP_LOG, "Failed to initialize SSL engine !"); application_exit (app); return -1; } SSL_CTX_set_options (app->ssl_ctx, SSL_OP_ALL); #endif #ifdef MAGIC_ENABLED app->magic_ctx = magic_open(MAGIC_MIME_TYPE); if (!app->magic_ctx) { LOG_err(APP_LOG, "Failed to initialize magic library\n"); return -1; } if (magic_load(app->magic_ctx, NULL)) { LOG_err(APP_LOG, "Failed to load magic database: %s\n", magic_error(app->magic_ctx)); magic_close(app->magic_ctx); return -1; } #endif app->stat_srv = stat_srv_create (app); if (!app->stat_srv) { application_exit (app); return -1; } // perform the initial request to get bucket ACL (handles redirect as well) app->service_con = http_connection_create (app); if (!app->service_con) { application_destroy (app); return -1; } bucket_client_get (app->service_con, "/?acl", application_on_bucket_acl_cb, app); // start the loop event_base_dispatch (app->evbase); application_destroy (app); return 0; }
struct rspamd_worker * rspamd_fork_worker (struct rspamd_main *rspamd_main, struct rspamd_worker_conf *cf, guint index) { struct rspamd_worker *cur; /* Starting worker process */ cur = (struct rspamd_worker *) g_malloc0 (sizeof (struct rspamd_worker)); if (!rspamd_socketpair (cur->control_pipe)) { msg_err ("socketpair failure: %s", strerror (errno)); exit (-errno); } cur->srv = rspamd_main; cur->type = cf->type; cur->cf = g_malloc (sizeof (struct rspamd_worker_conf)); memcpy (cur->cf, cf, sizeof (struct rspamd_worker_conf)); cur->index = index; cur->ctx = cf->ctx; cur->pid = fork (); switch (cur->pid) { case 0: /* Update pid for logging */ rspamd_log_update_pid (cf->type, rspamd_main->logger); /* Lock statfile pool if possible XXX */ /* Init PRNG after fork */ ottery_init (NULL); g_random_set_seed (ottery_rand_uint32 ()); /* Drop privilleges */ rspamd_worker_drop_priv (rspamd_main); /* Set limits */ rspamd_worker_set_limits (rspamd_main, cf); setproctitle ("%s process", cf->worker->name); rspamd_pidfile_close (rspamd_main->pfh); /* Do silent log reopen to avoid collisions */ rspamd_log_close (rspamd_main->logger); rspamd_log_open (rspamd_main->logger); cur->start_time = rspamd_get_calendar_ticks (); #if ((GLIB_MAJOR_VERSION == 2) && (GLIB_MINOR_VERSION <= 30)) # if (GLIB_MINOR_VERSION > 20) /* Ugly hack for old glib */ if (!g_thread_get_initialized ()) { g_thread_init (NULL); } # else g_thread_init (NULL); # endif #endif msg_info_main ("starting %s process %P", cf->worker->name, getpid ()); /* Close parent part of socketpair */ close (cur->control_pipe[0]); rspamd_socket_nonblocking (cur->control_pipe[1]); /* Execute worker */ cf->worker->worker_start_func (cur); break; case -1: msg_err_main ("cannot fork main process. %s", strerror (errno)); rspamd_pidfile_remove (rspamd_main->pfh); exit (-errno); break; default: /* Close worker part of socketpair */ close (cur->control_pipe[1]); rspamd_socket_nonblocking (cur->control_pipe[0]); /* Insert worker into worker's table, pid is index */ g_hash_table_insert (rspamd_main->workers, GSIZE_TO_POINTER ( cur->pid), cur); break; } return cur; }
int main (int argc, char **argv) { state *st; GtkWidget *window; GtkWidget *drawing_area; GError *error = NULL; DBusError dbus_error; gtk_set_locale(); gtk_init_with_args(&argc, &argv, parameter_string, options, "gnome-screensaver", &error); if (error != NULL) { g_printerr ("%s. See --help for usage information.\n", error->message); g_error_free (error); return EX_SOFTWARE; } copy_gifs(); get_time_str(); window = gs_theme_window_new(); drawing_area = gtk_drawing_area_new(); st = clock_init(window, drawing_area); init_weather(st); gtk_widget_show(drawing_area); gtk_container_add(GTK_CONTAINER (window), drawing_area); gtk_widget_show(window); loop = g_main_loop_new (NULL, FALSE); dbus_error_init (&dbus_error); bus = dbus_bus_get (DBUS_BUS_SESSION, &dbus_error); if (!bus) { g_warning ("Failed to connect to the D-BUS daemon: %s", dbus_error.message); dbus_error_free (&dbus_error); return 1; } dbus_connection_setup_with_g_main (bus, NULL); /* listening to messages from all objects as no path is specified */ dbus_bus_add_match (bus, "type='signal',interface='org.freedesktop.MediaPlayer'", &dbus_error); dbus_bus_add_match (bus, "type='signal',interface='org.freedesktop.DBus.Properties'", &dbus_error); dbus_connection_add_filter (bus, signal_filter, loop, NULL); g_signal_connect(G_OBJECT (window), "delete-event", GTK_SIGNAL_FUNC(quit_app), loop); g_signal_connect(GTK_OBJECT (drawing_area), "configure_event", GTK_SIGNAL_FUNC (configure_event), st); g_signal_connect(GTK_OBJECT (drawing_area), "expose_event", GTK_SIGNAL_FUNC (expose_event), st); g_signal_connect(GTK_OBJECT (window), "configure_event", GTK_SIGNAL_FUNC (w_configure_event), st); g_random_set_seed(time (NULL)); st->timer_id = g_timeout_add_seconds(1, clock_timer, st); g_main_loop_run (loop); clock_free (st); return EX_OK; }
int main (int argc, char **argv) { RBShell *shell; gboolean autostarted; char *desktop_file_path; int new_argc; char **new_argv; /* disable multidevice so clutter-gtk events work. * this needs to be done before gtk_open, so the visualizer * plugin can't do it. */ gdk_disable_multidevice (); g_thread_init (NULL); g_type_init (); g_random_set_seed (time (0)); autostarted = (g_getenv ("DESKTOP_AUTOSTART_ID") != NULL); #ifdef USE_UNINSTALLED_DIRS desktop_file_path = g_build_filename (SHARE_UNINSTALLED_BUILDDIR, "rhythmbox.desktop", NULL); g_setenv ("GSETTINGS_SCHEMA_DIR", SHARE_UNINSTALLED_BUILDDIR, TRUE); #else desktop_file_path = g_build_filename (DATADIR, "applications", "rhythmbox.desktop", NULL); #endif egg_set_desktop_file (desktop_file_path); g_free (desktop_file_path); setlocale (LC_ALL, NULL); #ifdef ENABLE_NLS /* initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif #if defined(USE_UNINSTALLED_DIRS) g_irepository_prepend_search_path (SHARE_UNINSTALLED_BUILDDIR "/../bindings/gi"); #endif /* TODO: kill this function */ rb_threads_init (); if (glib_check_version (2, 31, 1) != NULL) { gdk_threads_enter (); } new_argc = argc; new_argv = argv; shell = rb_shell_new (autostarted, &argc, &argv); g_application_run (G_APPLICATION (shell), new_argc, new_argv); g_object_unref (shell); if (glib_check_version (2, 31, 1) != NULL) { gdk_threads_leave (); } exit (0); }
int main (int argc, char **argv) { DBusGConnection *session_bus; GError *error = NULL; RBShell *rb_shell; gboolean activated; gboolean autostarted; char *accel_map_file = NULL; char *desktop_file_path; GOptionContext *context; static const GOptionEntry options [] = { { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug, N_("Enable debug output"), NULL }, { "debug-match", 'D', 0, G_OPTION_ARG_STRING, &debug_match, N_("Enable debug output matching a specified string"), NULL }, { "no-update", 0, 0, G_OPTION_ARG_NONE, &no_update, N_("Do not update the library with file changes"), NULL }, { "no-registration", 'n', 0, G_OPTION_ARG_NONE, &no_registration, N_("Do not register the shell"), NULL }, { "dry-run", 0, 0, G_OPTION_ARG_NONE, &dry_run, N_("Don't save any data permanently (implies --no-registration)"), NULL }, { "disable-plugins", 0, 0, G_OPTION_ARG_NONE, &disable_plugins, N_("Disable loading of plugins"), NULL }, { "rhythmdb-file", 0, 0, G_OPTION_ARG_STRING, &rhythmdb_file, N_("Path for database file to use"), NULL }, { "playlists-file", 0, 0, G_OPTION_ARG_STRING, &playlists_file, N_("Path for playlists file to use"), NULL }, { "quit", 'q', 0, G_OPTION_ARG_NONE, &quit, N_("Quit Rhythmbox"), NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &remaining_args, NULL, N_("[URI...]") }, { NULL } }; g_thread_init (NULL); rb_profile_start ("starting rhythmbox"); autostarted = (g_getenv ("DESKTOP_AUTOSTART_ID") != NULL); #ifdef USE_UNINSTALLED_DIRS desktop_file_path = g_build_filename (SHARE_UNINSTALLED_BUILDDIR, "rhythmbox.desktop", NULL); g_setenv ("GSETTINGS_SCHEMA_DIR", SHARE_UNINSTALLED_BUILDDIR, TRUE); #else desktop_file_path = g_build_filename (DATADIR, "applications", "rhythmbox.desktop", NULL); #endif egg_set_desktop_file (desktop_file_path); g_free (desktop_file_path); context = g_option_context_new (NULL); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); rb_profile_start ("initializing gstreamer"); g_option_context_add_group (context, gst_init_get_option_group ()); rb_profile_end ("initializing gstreamer"); g_option_context_add_group (context, egg_sm_client_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); setlocale (LC_ALL, NULL); rb_profile_start ("parsing command line options"); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print (_("%s\nRun '%s --help' to see a full list of available command line options.\n"), error->message, argv[0]); g_error_free (error); g_option_context_free (context); exit (1); } g_option_context_free (context); rb_profile_end ("parsing command line options"); g_random_set_seed (time (0)); #ifdef ENABLE_NLS /* initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); /* ask for utf-8 message text from GStreamer too, * since it doesn't do that itself. */ bind_textdomain_codeset ("gstreamer-0.10", "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif if (!debug && debug_match) rb_debug_init_match (debug_match); else rb_debug_init (debug); rb_debug ("initializing Rhythmbox %s", VERSION); #if defined(USE_UNINSTALLED_DIRS) g_irepository_prepend_search_path (SHARE_UNINSTALLED_BUILDDIR "/../bindings/gi"); #endif /* TODO: kill this function */ rb_threads_init (); gdk_threads_enter (); activated = FALSE; rb_debug ("going to create DBus object"); dbus_g_thread_init (); session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (session_bus == NULL) { g_warning ("couldn't connect to session bus: %s", (error) ? error->message : "(null)"); g_clear_error (&error); } else if (!no_registration) { guint request_name_reply; int flags; #ifndef DBUS_NAME_FLAG_DO_NOT_QUEUE flags = DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT; #else flags = DBUS_NAME_FLAG_DO_NOT_QUEUE; #endif DBusGProxy *bus_proxy; bus_proxy = dbus_g_proxy_new_for_name (session_bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error, G_TYPE_STRING, "org.gnome.Rhythmbox", G_TYPE_UINT, flags, G_TYPE_INVALID, G_TYPE_UINT, &request_name_reply, G_TYPE_INVALID)) { g_warning ("Failed to invoke RequestName: %s", error->message); } g_object_unref (bus_proxy); if (request_name_reply == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER || request_name_reply == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER) activated = FALSE; else if (request_name_reply == DBUS_REQUEST_NAME_REPLY_EXISTS || request_name_reply == DBUS_REQUEST_NAME_REPLY_IN_QUEUE) activated = TRUE; else { g_warning ("Got unhandled reply %u from RequestName", request_name_reply); activated = FALSE; } } if (!activated) { if (quit) { rb_debug ("was asked to quit, but no instance was running"); gdk_notify_startup_complete (); exit (0); } #ifdef WITH_RHYTHMDB_GDA gda_init (PACKAGE, VERSION, argc, argv); #endif rb_refstring_system_init (); #ifdef USE_UNINSTALLED_DIRS rb_file_helpers_init (TRUE); #else rb_file_helpers_init (FALSE); #endif /* XXX not sure what to do with this. should we move it to * the config dir, or leave it where it is? */ accel_map_file = g_build_filename (g_get_home_dir (), ".gnome2", "accels", "rhythmbox", NULL); gtk_accel_map_load (accel_map_file); rb_debug ("Going to create a new shell"); rb_stock_icons_init (); g_setenv ("PULSE_PROP_media.role", "music", TRUE); rb_shell = rb_shell_new (no_registration, no_update, dry_run, autostarted, disable_plugins, rhythmdb_file, playlists_file); g_object_weak_ref (G_OBJECT (rb_shell), main_shell_weak_ref_cb, NULL); if (!no_registration && session_bus != NULL) { dbus_g_object_type_install_info (RB_TYPE_SHELL, &dbus_glib_rb_shell_object_info); dbus_g_connection_register_g_object (session_bus, "/org/gnome/Rhythmbox/Shell", G_OBJECT (rb_shell)); g_signal_connect (G_OBJECT (rb_shell), "database-load-complete", G_CALLBACK (database_load_complete), NULL); } } else if (!no_registration && session_bus != NULL) { DBusGProxy *shell_proxy; guint32 current_time; current_time = gdk_x11_display_get_user_time (gdk_display_get_default ()); shell_proxy = dbus_g_proxy_new_for_name_owner (session_bus, "org.gnome.Rhythmbox", "/org/gnome/Rhythmbox/Shell", "org.gnome.Rhythmbox.Shell", &error); if (!shell_proxy) { g_warning ("Couldn't create proxy for Rhythmbox shell: %s", error->message); } else { if (quit) { dbus_g_proxy_call_no_reply (shell_proxy, "quit", G_TYPE_INVALID); } else { load_uri_args ((const char **) remaining_args, (GFunc) dbus_load_uri, shell_proxy); dbus_g_proxy_call_no_reply (shell_proxy, "present", G_TYPE_UINT, current_time, G_TYPE_INVALID); } g_object_unref (G_OBJECT (shell_proxy)); } } if (activated) { gdk_notify_startup_complete (); } else { rb_profile_start ("mainloop"); #ifdef ENABLE_PYTHON if (rb_python_init_successful ()) { pyg_begin_allow_threads; gtk_main (); pyg_end_allow_threads; } else { gtk_main (); } #else gtk_main (); #endif rb_profile_end ("mainloop"); rb_debug ("out of toplevel loop"); rb_file_helpers_shutdown (); rb_stock_icons_shutdown (); rb_refstring_system_shutdown (); } gst_deinit (); rb_debug ("THE END"); rb_profile_end ("starting rhythmbox"); if (accel_map_file != NULL) { gtk_accel_map_save (accel_map_file); } gdk_threads_leave (); exit (0); }
/** * main: **/ int main (int argc, char **argv) { GOptionContext *context; const gchar *subsystems[] = { "usb", NULL }; gboolean verbose = FALSE; int status = EXIT_SUCCESS; _cleanup_object_unref_ GUdevClient *udev_client = NULL; g_autoptr(GError) error = NULL; g_autoptr(GCancellable) cancellable = NULL; const GOptionEntry options[] = { { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, /* TRANSLATORS: command line option */ _("Show extra debugging information"), NULL }, { NULL} }; /* make this predictable */ g_random_set_seed (0xdead); /* TRANSLATORS: A program to copy the LiveUSB image onto USB hardware */ context = g_option_context_new (NULL); g_option_context_add_main_entries (context, options, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { status = EXIT_FAILURE; g_print ("Failed to parse command line: %s\n", error->message); goto out; } if (verbose) g_setenv ("G_MESSAGES_DEBUG", "all", TRUE); /* valid arguments */ if (argc != 2 || !gmw_probe_is_block_device_valid (argv[1])) { status = EXIT_FAILURE; g_print ("Block device required as argument\n"); goto out; } /* already mounted */ if (gmw_probe_is_block_device_mounted (argv[1])) { status = EXIT_FAILURE; g_print ("Partition mounted from block device\n"); goto out; } /* probe device */ cancellable = g_cancellable_new (); udev_client = g_udev_client_new (subsystems); if (!gmw_probe_use_device (udev_client, argv[1], cancellable, &error)) { status = EXIT_FAILURE; if (g_error_matches (error, GMW_ERROR, GMW_ERROR_IS_FAKE)) { g_print ("Device is FAKE: %s\n", error->message); } else { g_print ("Failed to scan device: %s\n", error->message); } goto out; } g_print ("Device is GOOD\n"); out: g_option_context_free (context); return status; }