int
main (int argc, char *argv[])
{
	char *bad_domains = NULL;
	GError *error = NULL;
	gboolean wrote_pidfile = FALSE;
	gs_free char *pidfile = NULL;
	gs_unref_object NMDhcpClient *dhcp4_client = NULL;
	gs_unref_object NMRDisc *rdisc = NULL;
	GByteArray *hwaddr = NULL;
	size_t hwaddr_len = 0;
	gconstpointer tmp;
	gs_free NMUtilsIPv6IfaceId *iid = NULL;
	guint sd_id;

	nm_g_type_init ();

	setpgid (getpid (), getpid ());

	do_early_setup (&argc, &argv);

	if (global_opt.g_fatal_warnings) {
		GLogLevelFlags fatal_mask;

		fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
		fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
		g_log_set_always_fatal (fatal_mask);
	}

	if (global_opt.show_version) {
		fprintf (stdout, NM_DIST_VERSION "\n");
		exit (0);
	}

	nm_main_utils_ensure_root ();

	if (!global_opt.ifname || !global_opt.uuid) {
		fprintf (stderr, _("An interface name and UUID are required\n"));
		exit (1);
	}

	ifindex = if_nametoindex (global_opt.ifname);
	if (ifindex <= 0) {
		fprintf (stderr, _("Failed to find interface index for %s (%s)\n"), global_opt.ifname, strerror (errno));
		exit (1);
	}
	pidfile = g_strdup_printf (NMIH_PID_FILE_FMT, ifindex);
	nm_main_utils_ensure_not_running_pidfile (pidfile);

	nm_main_utils_ensure_rundir ();

	if (!nm_logging_setup (global_opt.opt_log_level,
	                       global_opt.opt_log_domains,
	                       &bad_domains,
	                       &error)) {
		fprintf (stderr,
		         _("%s.  Please use --help to see a list of valid options.\n"),
		         error->message);
		exit (1);
	} else if (bad_domains) {
		fprintf (stderr,
		         _("Ignoring unrecognized log domain(s) '%s' passed on command line.\n"),
		         bad_domains);
		g_clear_pointer (&bad_domains, g_free);
	}

	if (global_opt.become_daemon && !global_opt.debug) {
		if (daemon (0, 0) < 0) {
			int saved_errno;

			saved_errno = errno;
			fprintf (stderr, _("Could not daemonize: %s [error %u]\n"),
			         g_strerror (saved_errno),
			         saved_errno);
			exit (1);
		}
		if (nm_main_utils_write_pidfile (pidfile))
			wrote_pidfile = TRUE;
	}

	/* Set up unix signal handling - before creating threads, but after daemonizing! */
	main_loop = g_main_loop_new (NULL, FALSE);
	setup_signals ();

	nm_logging_syslog_openlog (global_opt.logging_backend
	                           ? global_opt.logging_backend
	                           : (global_opt.debug ? "debug" : NULL));

	nm_log_info (LOGD_CORE, "nm-iface-helper (version " NM_DIST_VERSION ") is starting...");

	/* Set up platform interaction layer */
	nm_linux_platform_setup ();

	tmp = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &hwaddr_len);
	if (tmp) {
		hwaddr = g_byte_array_sized_new (hwaddr_len);
		g_byte_array_append (hwaddr, tmp, hwaddr_len);
	}

	if (global_opt.iid_str) {
		GBytes *bytes;
		gsize ignored = 0;

		bytes = nm_utils_hexstr2bin (global_opt.iid_str);
		if (!bytes || g_bytes_get_size (bytes) != sizeof (*iid)) {
			fprintf (stderr, _("(%s): Invalid IID %s\n"), global_opt.ifname, global_opt.iid_str);
			exit (1);
		}
		iid = g_bytes_unref_to_data (bytes, &ignored);
	}

	if (global_opt.dhcp4_address) {
		nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip4_property_path (global_opt.ifname, "promote_secondaries"), "1");

		dhcp4_client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (),
		                                          global_opt.ifname,
		                                          ifindex,
		                                          hwaddr,
		                                          global_opt.uuid,
		                                          global_opt.priority_v4,
		                                          !!global_opt.dhcp4_hostname,
		                                          global_opt.dhcp4_hostname,
		                                          global_opt.dhcp4_fqdn,
		                                          global_opt.dhcp4_clientid,
		                                          45,
		                                          NULL,
		                                          global_opt.dhcp4_address);
		g_assert (dhcp4_client);
		g_signal_connect (dhcp4_client,
		                  NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
		                  G_CALLBACK (dhcp4_state_changed),
		                  NULL);
	}

	if (global_opt.slaac) {
		NMUtilsStableType stable_type = NM_UTILS_STABLE_TYPE_UUID;
		const char *stable_id = global_opt.uuid;

		nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, ifindex, TRUE);

		if (   global_opt.stable_id
		    && (global_opt.stable_id[0] >= '0' && global_opt.stable_id[0] <= '9')
		    && global_opt.stable_id[1] == ' ') {
			/* strict parsing of --stable-id, which is the numeric stable-type
			 * and the ID, joined with one space. For now, only support stable-types
			 * from 0 to 9. */
			stable_type = (global_opt.stable_id[0] - '0');
			stable_id = &global_opt.stable_id[2];
		}
		rdisc = nm_lndp_rdisc_new (NM_PLATFORM_GET, ifindex, global_opt.ifname,
		                           stable_type, stable_id,
		                           global_opt.addr_gen_mode, NULL);
		g_assert (rdisc);

		if (iid)
			nm_rdisc_set_iid (rdisc, *iid);

		nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra"), "1");
		nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_defrtr"), "0");
		nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_pinfo"), "0");
		nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (global_opt.ifname, "accept_ra_rtr_pref"), "0");

		g_signal_connect (NM_PLATFORM_GET,
		                  NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED,
		                  G_CALLBACK (ip6_address_changed),
		                  rdisc);
		g_signal_connect (rdisc,
		                  NM_RDISC_CONFIG_CHANGED,
		                  G_CALLBACK (rdisc_config_changed),
		                  NULL);
		g_signal_connect (rdisc,
		                  NM_RDISC_RA_TIMEOUT,
		                  G_CALLBACK (rdisc_ra_timeout),
		                  NULL);
		nm_rdisc_start (rdisc);
	}

	sd_id = nm_sd_event_attach_default ();

	g_main_loop_run (main_loop);

	g_clear_pointer (&hwaddr, g_byte_array_unref);

	if (pidfile && wrote_pidfile)
		unlink (pidfile);

	nm_log_info (LOGD_CORE, "exiting");

	nm_clear_g_source (&sd_id);
	exit (0);
}
Exemple #2
0
static void
parse_args (gint    *argc_p,
            gchar ***argv_p)
{
  guint argc = *argc_p;
  gchar **argv = *argv_p;
  guint i, e;
  /* parse known args */
  for (i = 1; i < argc; i++)
    {
      if (strcmp (argv[i], "--g-fatal-warnings") == 0)
        {
          GLogLevelFlags fatal_mask = (GLogLevelFlags) g_log_set_always_fatal ((GLogLevelFlags) G_LOG_FATAL_MASK);
          fatal_mask = (GLogLevelFlags) (fatal_mask | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL);
          g_log_set_always_fatal (fatal_mask);
          argv[i] = NULL;
        }
      else if (strcmp (argv[i], "--gtester-selftest") == 0)
        {
          gtester_selftest = TRUE;
          argv[i] = NULL;
          break;        /* stop parsing regular gtester arguments */
        }
      else if (strcmp (argv[i], "-h") == 0 || strcmp (argv[i], "--help") == 0)
        {
          usage (FALSE);
          exit (0);
          argv[i] = NULL;
        }
      else if (strcmp (argv[i], "-v") == 0 || strcmp (argv[i], "--version") == 0)
        {
          usage (TRUE);
          exit (0);
          argv[i] = NULL;
        }
      else if (strcmp (argv[i], "--keep-going") == 0 ||
               strcmp (argv[i], "-k") == 0)
        {
          subtest_mode_fatal = FALSE;
          argv[i] = NULL;
        }
      else if (strcmp ("-p", argv[i]) == 0 || strncmp ("-p=", argv[i], 3) == 0)
        {
          gchar *equal = argv[i] + 2;
          if (*equal == '=')
            subtest_paths = g_slist_prepend (subtest_paths, equal + 1);
          else if (i + 1 < argc)
            {
              argv[i++] = NULL;
              subtest_paths = g_slist_prepend (subtest_paths, argv[i]);
            }
          argv[i] = NULL;
        }
      else if (strcmp ("--test-arg", argv[i]) == 0 || strncmp ("--test-arg=", argv[i], 11) == 0)
        {
          gchar *equal = argv[i] + 10;
          if (*equal == '=')
            subtest_args = g_slist_prepend (subtest_args, equal + 1);
          else if (i + 1 < argc)
            {
              argv[i++] = NULL;
              subtest_args = g_slist_prepend (subtest_args, argv[i]);
            }
          argv[i] = NULL;
        }
      else if (strcmp ("-o", argv[i]) == 0 || strncmp ("-o=", argv[i], 3) == 0)
        {
          gchar *equal = argv[i] + 2;
          if (*equal == '=')
            output_filename = equal + 1;
          else if (i + 1 < argc)
            {
              argv[i++] = NULL;
              output_filename = argv[i];
            }
          argv[i] = NULL;
        }
      else if (strcmp ("-m", argv[i]) == 0 || strncmp ("-m=", argv[i], 3) == 0)
        {
          gchar *equal = argv[i] + 2;
          const gchar *mode = "";
          if (*equal == '=')
            mode = equal + 1;
          else if (i + 1 < argc)
            {
              argv[i++] = NULL;
              mode = argv[i];
            }
          if (strcmp (mode, "perf") == 0)
            subtest_mode_perf = TRUE;
          else if (strcmp (mode, "slow") == 0 || strcmp (mode, "thorough") == 0)
            subtest_mode_quick = FALSE;
          else if (strcmp (mode, "quick") == 0)
            {
              subtest_mode_quick = TRUE;
              subtest_mode_perf = FALSE;
            }
          else
            g_error ("unknown test mode: -m %s", mode);
          argv[i] = NULL;
        }
      else if (strcmp ("-q", argv[i]) == 0 || strcmp ("--quiet", argv[i]) == 0)
        {
          gtester_quiet = TRUE;
          gtester_verbose = FALSE;
          argv[i] = NULL;
        }
      else if (strcmp ("--verbose", argv[i]) == 0)
        {
          gtester_quiet = FALSE;
          gtester_verbose = TRUE;
          argv[i] = NULL;
        }
      else if (strcmp ("-l", argv[i]) == 0)
        {
          gtester_list_tests = TRUE;
          argv[i] = NULL;
        }
      else if (strcmp ("--seed", argv[i]) == 0 || strncmp ("--seed=", argv[i], 7) == 0)
        {
          gchar *equal = argv[i] + 6;
          if (*equal == '=')
            subtest_seedstr = equal + 1;
          else if (i + 1 < argc)
            {
              argv[i++] = NULL;
              subtest_seedstr = argv[i];
            }
          argv[i] = NULL;
        }
    }
  /* collapse argv */
  e = 1;
  for (i = 1; i < argc; i++)
    if (argv[i])
      {
        argv[e++] = argv[i];
        if (i >= e)
          argv[i] = NULL;
      }
  *argc_p = e;
}
Exemple #3
0
/**
 * This is where the story begins. It parses commandline options and
 * environment variables, sets up the screen, hands control off to
 * GTK, and cleans up afterwards.
 *
 * \param argc Number of arguments (as usual)
 * \param argv Array of arguments (as usual)
 *
 * \bug It's a bit long. It would be good to split it out into separate
 * functions.
 */
int
main (int argc, char **argv)
{
  struct sigaction act;
  sigset_t empty_mask;
  MetaArguments meta_args;
  const gchar *log_domains[] = {
    NULL, G_LOG_DOMAIN, "Gtk", "Gdk", "GLib",
    "Pango", "GLib-GObject", "GThread"
  };
  guint i;
  GIOChannel *channel;

#if GLIB_CHECK_VERSION (2, 32, 0)
  /* g_thread_init () deprecated */
#else
  if (!g_thread_supported ())
    g_thread_init (NULL);
#endif

  if (setlocale (LC_ALL, "") == NULL)
    meta_warning ("Locale not understood by C library, internationalization will not work\n");

  g_type_init ();

  sigemptyset (&empty_mask);
  act.sa_handler = SIG_IGN;
  act.sa_mask    = empty_mask;
  act.sa_flags   = 0;
  if (sigaction (SIGPIPE,  &act, NULL) < 0)
    g_printerr ("Failed to register SIGPIPE handler: %s\n",
                g_strerror (errno));
#ifdef SIGXFSZ
  if (sigaction (SIGXFSZ,  &act, NULL) < 0)
    g_printerr ("Failed to register SIGXFSZ handler: %s\n",
                g_strerror (errno));
#endif

  if (pipe (sigterm_pipe_fds) != 0)
    g_printerr ("Failed to create SIGTERM pipe: %s\n",
                g_strerror (errno));

  channel = g_io_channel_unix_new (sigterm_pipe_fds[0]);
  g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
  g_io_add_watch (channel, G_IO_IN, (GIOFunc) on_sigterm, NULL);
  g_io_channel_set_close_on_unref (channel, TRUE);
  g_io_channel_unref (channel);

  act.sa_handler = &sigterm_handler;
  if (sigaction (SIGTERM, &act, NULL) < 0)
    g_printerr ("Failed to register SIGTERM handler: %s\n",
		g_strerror (errno));

  if (g_getenv ("MARCO_VERBOSE"))
    meta_set_verbose (TRUE);
  if (g_getenv ("MARCO_DEBUG"))
    meta_set_debugging (TRUE);

  if (g_get_home_dir ())
    if (chdir (g_get_home_dir ()) < 0)
      meta_warning ("Could not change to home directory %s.\n",
                    g_get_home_dir ());

  meta_print_self_identity ();

  bindtextdomain (GETTEXT_PACKAGE, MARCO_LOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  /* Parse command line arguments.*/
  meta_parse_options (&argc, &argv, &meta_args);

  meta_set_syncing (meta_args.sync || (g_getenv ("MARCO_SYNC") != NULL));

  if (meta_args.print_version)
    version ();

  meta_select_display (meta_args.display_name);

  if (meta_args.replace_wm)
    meta_set_replace_current_wm (TRUE);

  if (meta_args.save_file && meta_args.client_id)
    meta_fatal ("Can't specify both SM save file and SM client id\n");

  meta_main_loop = g_main_loop_new (NULL, FALSE);

  meta_ui_init (&argc, &argv);

  /* must be after UI init so we can override GDK handlers */
  meta_errors_init ();

  /* Load prefs */
  meta_prefs_init ();
  meta_prefs_add_listener (prefs_changed_callback, NULL);


#if 1

  for (i=0; i<G_N_ELEMENTS(log_domains); i++)
    g_log_set_handler (log_domains[i],
                       G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL | G_LOG_FLAG_RECURSION,
                       log_handler, NULL);

#endif

  if (g_getenv ("MARCO_G_FATAL_WARNINGS") != NULL)
    g_log_set_always_fatal (G_LOG_LEVEL_MASK);

  meta_ui_set_current_theme (meta_prefs_get_theme (), FALSE);

  /* Try to find some theme that'll work if the theme preference
   * doesn't exist.  First try Simple (the default theme) then just
   * try anything in the themes directory.
   */
  if (!meta_ui_have_a_theme ())
    meta_ui_set_current_theme ("Simple", FALSE);

  if (!meta_ui_have_a_theme ())
    {
      const char *dir_entry = NULL;
      GError *err = NULL;
      GDir   *themes_dir = NULL;

      if (!(themes_dir = g_dir_open (MARCO_DATADIR"/themes", 0, &err)))
        {
          meta_fatal (_("Failed to scan themes directory: %s\n"), err->message);
          g_error_free (err);
        }
      else
        {
          while (((dir_entry = g_dir_read_name (themes_dir)) != NULL) &&
                 (!meta_ui_have_a_theme ()))
            {
              meta_ui_set_current_theme (dir_entry, FALSE);
            }

          g_dir_close (themes_dir);
        }
    }

  if (!meta_ui_have_a_theme ())
    meta_fatal (_("Could not find a theme! Be sure %s exists and contains the usual themes.\n"),
                MARCO_DATADIR"/themes");

  /* Connect to SM as late as possible - but before managing display,
   * or we might try to manage a window before we have the session
   * info
   */
  if (!meta_args.disable_sm)
    {
      if (meta_args.client_id == NULL)
        {
          const gchar *desktop_autostart_id;

          desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");

          if (desktop_autostart_id != NULL)
            meta_args.client_id = g_strdup (desktop_autostart_id);
        }

      /* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to
       * use the same client id. */
      g_unsetenv ("DESKTOP_AUTOSTART_ID");

      meta_session_init (meta_args.client_id, meta_args.save_file);
    }
  /* Free memory possibly allocated by the argument parsing which are
   * no longer needed.
   */
  g_free (meta_args.save_file);
  g_free (meta_args.display_name);
  g_free (meta_args.client_id);

  if (meta_args.composite || meta_args.no_composite)
    meta_prefs_set_compositing_manager (meta_args.composite);

  if (meta_args.no_force_fullscreen)
    meta_prefs_set_force_fullscreen (FALSE);

  if (!meta_display_open ())
    meta_exit (META_EXIT_ERROR);

  g_main_loop_run (meta_main_loop);

  meta_finalize ();

  if (meta_restart_after_quit)
    {
      GError *err;

      err = NULL;
      if (!g_spawn_async (NULL,
                          argv,
                          NULL,
                          G_SPAWN_SEARCH_PATH,
                          NULL,
                          NULL,
                          NULL,
                          &err))
        {
          meta_fatal (_("Failed to restart: %s\n"),
                      err->message);
          g_error_free (err); /* not reached anyhow */
          meta_exit_code = META_EXIT_ERROR;
        }
    }

  return meta_exit_code;
}
Exemple #4
0
int
main (int argc, char **argv)
{
  GOptionContext *context;
  GError *err;
  SwfdecPlayer *player;
  SwfdecURL *url;
  guint i;
  cairo_surface_t *surface;
  cairo_t *cr;
  gboolean aborts;
  glong play_per_file = 30;
  glong max_per_file = 60;
  glong max_per_advance = 10;
  GTimer *timer;
  char **filenames = NULL;
  const GOptionEntry entries[] = {
    {
      "play-time", 'p', 0, G_OPTION_ARG_INT, &play_per_file,
      "How many seconds will be played from each file (default 30)", NULL
    },
    {
      "max-per-file", '\0', 0, G_OPTION_ARG_INT, &max_per_file,
      "Maximum runtime in seconds allowed for each file (default 60)", NULL
    },
    {
      "max-per-advance", '\0', 0, G_OPTION_ARG_INT, &max_per_advance,
      "Maximum runtime in seconds allowed for each advance (default 10)", NULL
    },
    {
      G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
      NULL, "<INPUT FILE> <OUTPUT FILE>"
    },
    {
      NULL
    }
  };

  // catch asserts and don't spew debug output by default
  g_log_set_always_fatal (G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
  g_setenv ("SWFDEC_DEBUG", "0", FALSE);

  // init
  swfdec_init ();

  // read command line params
  context = g_option_context_new ("Run a Flash file trying to crash Swfdec");
  g_option_context_add_main_entries (context, entries, NULL);

  if (g_option_context_parse (context, &argc, &argv, &err) == FALSE) {
    g_printerr ("Couldn't parse command-line options: %s\n", err->message);
    g_error_free (err);
    return 1;
  }

  if (filenames == NULL || g_strv_length (filenames) < 1) {
    g_printerr ("At least one input filename is required\n");
    return 1;
  }

  // make them milliseconds
  play_per_file *= 1000;
  max_per_file *= 1000;
  max_per_advance *= 1000;

  // create surface
  surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
  cr = cairo_create (surface);

  aborts = FALSE;
  for (i = 0; i < g_strv_length (filenames); i++)
  {
    glong played, advance, elapsed;

    g_print ("Running: %s\n", filenames[i]);

    // start timer
    timer = g_timer_new ();

    player = swfdec_player_new (NULL);
    url = swfdec_url_new_from_input (filenames[i]);
    swfdec_player_set_url (player, url);
    swfdec_url_free (url);

    // loop until we have played what we wanted, or timelimit is hit
    played = 0;
    elapsed = 0;
    while (played < play_per_file &&
	!swfdec_as_context_is_aborted (SWFDEC_AS_CONTEXT (player)))
    {
      elapsed = (glong)(g_timer_elapsed (timer, NULL) * 1000);
      if (elapsed >= max_per_file)
	break;
      swfdec_player_set_maximum_runtime (player,
	  MIN (max_per_advance, max_per_file - elapsed));

      advance = swfdec_player_get_next_event (player);
      if (advance == -1)
	break;
      played += swfdec_player_advance (player, advance);

      swfdec_player_render (player, cr);
    }

    if (elapsed >= max_per_file ||
	swfdec_as_context_is_aborted (SWFDEC_AS_CONTEXT (player))) {
      g_print ("*** Aborted ***\n");
      aborts = TRUE;
    }

    // clean up
    g_object_unref (player);
    g_timer_destroy (timer);
  }

  cairo_destroy (cr);
  cairo_surface_destroy (surface);

  if (aborts) {
    return 1;
  } else {
    return 0;
  }
}
Exemple #5
0
int main(int argc, char **argv)
{
    GError *error = NULL;
    ZCloudStore *store;
    char *spec;

    zcloud_init(&error);
    gerror_is_clear(&error, "initialize libzcloud");

    /* die on anything worse than a message */
    g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);

    spec = "s3:";
    store = zcloud_store_new(spec, &error, NULL);
    is_null(store, "creating S3 store with no parameters returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with no parameters triggers an error");

    store = zcloud_store_new(spec, &error, "access-key", "a", NULL);
    is_null(store, "creating S3 store with only access key return NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with only access key triggers an error");

    store = zcloud_store_new(spec, &error, "secret-key", "a", NULL);
    is_null(store, "creating S3 store with only access key return NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with only secret key triggers an error");

    store = zcloud_store_new(spec, &error, "product-token", "a", NULL);
    is_null(store, "creating S3 store with only access key return NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with only product token triggers an error");

    store = zcloud_store_new(spec, &error, "user-token", "a", NULL);
    is_null(store, "creating S3 store with only user token return NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with only user token triggers an error");

    store = zcloud_store_new(spec, &error, "access-key", "a", "product-token", "b", NULL);
    is_null(store, "creating S3 store with access key and product token returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with access key and product token triggers an error");

    store = zcloud_store_new(spec, &error, "access-key", "a", "user-token", "b", NULL);
    is_null(store, "creating S3 store with access key and product token returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with access key and product token triggers an error");

    store = zcloud_store_new(spec, &error, "access-key", "a", "user-token", "b", NULL);
    is_null(store, "creating S3 store with access key and user token returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with access key and user token triggers an error");

    store = zcloud_store_new(spec, &error, "access-key", "a", "user-token", "b", NULL);
    is_null(store, "creating S3 store with access key and user token returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with access key and user token triggers an error");

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "secret-key", "b", NULL);
    isnt_null(store, "creating S3 store with both access and secret keys returns non-NULL");
    ok(ZCLOUD_IS_STORE(store), "creating S3 store with both access and secret keys returns a store");
    gerror_is_clear(&error, "creating S3 store with both access and secret keys is okay");
    g_object_unref(store);

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "secret-key", "", NULL);
    is_null(store, "creating S3 store with access key and empty secret key returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with access key and empty secret key triggers an error");

    store = zcloud_store_new(spec, &error,
        "access-key", "", "secret-key", "b", NULL);
    is_null(store, "creating S3 store with access key and empty secret key returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                   "creating S3 store with access key and empty secret key triggers an error");

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "user-token", "b", "product-token", "c", NULL);
    is_null(store, "creating S3 store with access key, user token, and "
            "product token (but not secret key) return NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                  "creating S3 store with access key, user token, and "
                  "product token (but not secret key) triggers an error");

    store = zcloud_store_new(spec, &error,
        "secret-key", "a", "user-token", "b", "product-token", "c", NULL);
    is_null(store, "creating S3 store with secret key, user token, and "
            "product token (but not secret key) return NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                  "creating S3 store with access key, user token, and "
                  "product token (but not secret key) triggers an error");

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "secret-key", "b", "user-token", "c", NULL);
    is_null(store, "creating S3 store with access key, secret key, and "
            "user token (but not product token) return NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                  "creating S3 store with access key, secret key, and "
                  "user token (but not product token) triggers an error");

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "secret-key", "b", "product-token", "c", NULL);
    isnt_null(store, "creating S3 store with access key, secret key, and "
            "product token (but not user token) returns non-NULL");
    ok(ZCLOUD_IS_STORE(store), "creating S3 store with access key, secret key, and "
            "product token (but not user token) returns a store");
    gerror_is_clear(&error, "creating S3 store with access key, secret key, and "
                  "product token (but not user token) is okay");
    g_object_unref(store);

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "secret-key", "b", "user-token", "c", "product-token", "d", NULL);
    isnt_null(store, "creating S3 store with access key, secret key, "
              "user token, and product token returns non-NULL");
    ok(ZCLOUD_IS_STORE(store), "creating S3 store with access key, secret key, "
       "user token, and product token returns a store");
    gerror_is_clear(&error, "creating S3 store with access key, secret key, "
                    "user token, and product token is okay");
    g_object_unref(store);

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "secret-key", "b", "user-token", "", "product-token", "d", NULL);
    isnt_null(store, "creating S3 store with access key, secret key, "
              "empty user token, and product token returns non-NULL");
    ok(ZCLOUD_IS_STORE(store), "creating S3 store with access key, secret key, "
       "empty user token, and product token returns a store");
    gerror_is_clear(&error, "creating S3 store with access key, secret key, "
                    "empty user token, and product token is okay");
    g_object_unref(store);

    store = zcloud_store_new(spec, &error,
        "access-key", "a", "secret-key", "b", "user-token", "c", "product-token", "", NULL);
    is_null(store, "creating S3 store with access key, secret key, "
              "user token, and empty product token returns NULL");
    gerror_is_set(&error, "must set a non-empty*", ZCERR_PARAMETER,
                  "creating S3 store with access key, secret key, and "
                  "user token, and empty product token triggers an error");

    {
        char *test_bucket, *test_bucket_spec,
            *access_key, *secret_key, *user_token, *product_token;
        const char *test_key = "test-key";
        ZCloudStore *test_store;
        gboolean op_ok;
        access_key = getenv("S3_ACCESS_KEY");
        secret_key = getenv("S3_SECRET_KEY");
        user_token = getenv("S3_USER_TOKEN");
        product_token = getenv("S3_PRODUCT_TOKEN");

        if (!access_key || !secret_key) {
            fprintf(stderr, "set environment variables S3_ACCESS_KEY and S3_SECRET_KEY to run full tests.\n"
                    "optionally set S3_USER_TOKEN and S3_PRODUCT_TOKEN too.\n");
            goto end;
        }

        {
            char host_buf[512];
            const size_t host_buf_size = sizeof(host_buf)/sizeof(char);
            gchar *tmp;
            if (gethostname(host_buf, host_buf_size) < 0) {
                g_error("error getting hostname: %s", strerror(errno));
            }
            host_buf[host_buf_size-1] = '\0';
            tmp = g_strconcat(access_key, "-s3test-", host_buf, NULL);
            test_bucket = g_ascii_strup(tmp, -1);
            test_bucket_spec = g_strconcat("s3:", test_bucket, NULL);
            g_free(tmp);
        }

        test_store = zcloud_store_new(test_bucket_spec, &error,
            "access-key", access_key, "secret-key", secret_key,
            "user-token", user_token, "product-token", product_token, NULL);
        isnt_null(test_store, "creating S3 store with credentials from env returns non-NULL");
        ok(ZCLOUD_IS_STORE(test_store), "creating S3 store with credentials from env returns a store");
        gerror_is_clear(&error, "creating S3 store with from env credentials is okay");

        store = zcloud_store_new(spec, &error,
            "access-key", access_key, "secret-key", secret_key,
            "user-token", user_token, "product-token", product_token, NULL);
        isnt_null(test_store, "creating S3 store with credentials from env returns non-NULL");
        ok(ZCLOUD_IS_STORE(test_store), "creating S3 store with credentials from env returns a store");
        gerror_is_clear(&error, "creating S3 store with from env credentials is okay");

        op_ok = zcloud_store_exists(store, test_bucket, NULL, &error);
        if (op_ok) {
            fprintf(stderr, "Test bucket (%s) seems to already exist. "
                    "Stopping early to avoid data loss\n", test_bucket);
            goto end;
        }
        /* error may be unexpected, but run the tests to learn more */
        g_clear_error(&error);

        op_ok = zcloud_store_create(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "create test bucket returned ok");
        gerror_is_clear(&error, "create test bucket didn't cause error");

        op_ok = zcloud_store_exists(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "test bucket exists now");
        gerror_is_clear(&error, "test bucket exist check didn't cause error");

        op_ok = zcloud_store_create(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "create test bucket (again) returned ok");
        gerror_is_clear(&error, "create test bucket (again) didn't cause error");

        op_ok = zcloud_store_delete(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "delete test bucket returned ok");
        gerror_is_clear(&error, "delete test bucket didn't cause error");

        /* would like to call exists (and expect to get FALSE w/o error), but
           the delete might not be visible */

        op_ok = zcloud_store_delete(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "delete test bucket (again) returned ok");
        gerror_is_clear(&error, "delete test bucket (again) didn't cause error");

        /* TODO: list buckets, should NOT have test bucket */

        op_ok = zcloud_store_create(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "create test bucket (after delete) returned ok");
        gerror_is_clear(&error, "create test bucket (after delete) didn't cause error");

        /* TODO: list buckets, should have test_bucket */

        op_ok = zcloud_store_create(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "create test bucket (again after delete) returned ok");
        gerror_is_clear(&error, "create test bucket (again after delete) didn't cause error");

        /* try some operations within the test bucket... */
        spec = test_bucket_spec;

        op_ok = zcloud_store_exists(test_store, test_key, NULL, &error);
        is_gboolean(op_ok, FALSE, "test key doesn't exist in empty bucket");
        gerror_is_set(&error, NULL, ZCERR_MISSING,
            "testing for existence of test key (w/ empty bucket) caused the expected error");

        {
            ZCloudSListListConsumer *list_con = zcloud_slist_list_consumer();
            GSList *l;

            op_ok = zcloud_store_list(test_store, "%s", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket");
            gerror_is_clear(&error, "listing keys for empty bucket didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            is_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "didn't find (as expected) the test key in the empty bucket listing");

            g_object_unref(list_con);
        }

        op_ok = zcloud_store_create(test_store, test_key, NULL, &error);
        is_gboolean(op_ok, TRUE, "create test key returned ok");
        gerror_is_clear(&error, "create test key didn't cause error");

        op_ok = zcloud_store_exists(test_store, test_key, NULL, &error);
        is_gboolean(op_ok, TRUE, "test key now exists");
        gerror_is_clear(&error, "testing for existence of test key didn't cause error");

        op_ok = zcloud_store_delete(test_store, test_key, NULL, &error);
        is_gboolean(op_ok, TRUE, "delete test key returned ok");
        gerror_is_clear(&error, "delete test key didn't cause error");

        op_ok = zcloud_store_delete(test_store, test_key, NULL, &error);
        is_gboolean(op_ok, TRUE, "delete test key (again) returned ok");
        gerror_is_clear(&error, "delete test key (again) didn't cause error");

        op_ok = zcloud_store_create(test_store, test_key, NULL, &error);
        is_gboolean(op_ok, TRUE, "create test key (after delete) returned ok");
        gerror_is_clear(&error, "create test key (after delete) didn't cause error");

        {
            ZCloudSListListConsumer *list_con;
            GSList *l;

            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, test_key, ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (exact)");
            gerror_is_clear(&error, "listing keys for empty bucket (exact) didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            isnt_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "found the test key in the bucket listing (exact)");

            g_object_unref(list_con);
            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, "%s", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (wild)");
            gerror_is_clear(&error, "listing keys for empty bucket didn't cause error (wild)");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            isnt_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "found the test key in the bucket listing (wild)");

            g_object_unref(list_con);
            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, "te%s", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (pre)");
            gerror_is_clear(&error, "listing keys for empty bucket (pre) didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            isnt_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "found the test key in the bucket listing (w/ pre)");

            g_object_unref(list_con);
            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, "%sey", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (suf)");
            gerror_is_clear(&error, "listing keys for empty bucket (suf) didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            isnt_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "found the test key in the bucket listing (w/ suf)");

            g_object_unref(list_con);
            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, "t%sy", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (mid)");
            gerror_is_clear(&error, "listing keys for empty bucket (mid) didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            isnt_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "found the test key in the bucket listing (w/ mid)");

            g_object_unref(list_con);
            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, "%%s", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (escaped)");
            gerror_is_clear(&error, "listing keys for empty bucket (escaped) didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            is_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "didn't find (as expected) the test key in the bucket listing (escaped)");

            g_object_unref(list_con);
            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, "te", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (pre no wild)");
            gerror_is_clear(&error, "listing keys for empty bucket (pre no wild) didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            is_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "didn't find (as expected) the test key in the bucket listing (pre no wild)");

            g_object_unref(list_con);
            list_con = zcloud_slist_list_consumer();

            op_ok = zcloud_store_list(test_store, "", ZCLOUD_LIST_CONSUMER(list_con), NULL, &error);
            is_gboolean(op_ok, TRUE, "listing keys for empty bucket (empty)");
            gerror_is_clear(&error, "listing keys for empty bucket (empty) didn't cause error");

            l = zcloud_slist_list_consumer_grab_contents(list_con);
            is_null(g_slist_find_custom(l, test_key, (GCompareFunc) strcmp),
                "didn't find the test key in the bucket listing (w/ empty)");

            g_object_unref(list_con);
        }

        /* upload and download tests */
        {
            const gchar *data_str = "The quick brown fox jumps over the lazy dog";
            gsize data_str_len;
            /* note: doesn't include NULL */
            data_str_len = strlen(data_str);

            /* upload */
            {
                ZCloudUploadProducer *up_prod;
                up_prod = ZCLOUD_UPLOAD_PRODUCER(
                    zcloud_memory_upload_producer(data_str, data_str_len));

                op_ok = zcloud_store_upload(test_store, test_key, up_prod, NULL, &error);
                is_gboolean(op_ok, TRUE, "uploading to test key returned ok");
                gerror_is_clear(&error, "uploading to test key didn't cause error");

                g_object_unref(up_prod);
            }

            /* download */
            {
                ZCloudGrowingMemoryDownloadConsumer *gm_down_con;
                ZCloudDownloadConsumer *down_con;
                guint8 *down_buf;
                gsize down_buf_size;

                gm_down_con = zcloud_growing_memory_download_consumer(data_str_len*2);
                down_con = ZCLOUD_DOWNLOAD_CONSUMER(gm_down_con);

                op_ok = zcloud_store_download(test_store, test_key,
                    ZCLOUD_DOWNLOAD_CONSUMER(down_con), NULL, &error);
                is_gboolean(op_ok, TRUE, "downloading from test key returned ok");
                gerror_is_clear(&error, "downloading from test key didn't cause error");

                down_buf = zcloud_growing_memory_download_consumer_get_contents(gm_down_con, &down_buf_size);
                {
                    GByteArray got = {down_buf, down_buf_size};
                    GByteArray exp = {(guint8 *)data_str, data_str_len};
                    is_byte_array(&got, &exp, "downloaded data matches uploaded data");
                }

                g_object_unref(down_con);
            }

            /* TODO test progress listener */
        }

        /* try to delete non-empty bucket, get error */
        op_ok = zcloud_store_delete(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, FALSE, "deleting non-empty bucket returned not ok (as expected)");
        gerror_is_set(&error, "*BucketNotEmpty*",
            ZCERR_LASTING, "deleting non-empty bucket caused the expected error");

        /* delete test key */
        op_ok = zcloud_store_delete(test_store, test_key, NULL, &error);
        is_gboolean(op_ok, TRUE, "delete test key (after roundtrip) returned ok");
        gerror_is_clear(&error, "delete test key (after roundtrip) didn't cause error");

        /* try to delete empty bucket */
        op_ok = zcloud_store_delete(store, test_bucket, NULL, &error);
        is_gboolean(op_ok, TRUE, "deleting now-empty bucket returned ok");
        gerror_is_clear(&error, "deleting now-empty bucket didn't cause error");

        /* try to upload a bucket, get error */
        {
            ZCloudUploadProducer *up_prod;
            up_prod = ZCLOUD_UPLOAD_PRODUCER(
                zcloud_memory_upload_producer("", 0));

            op_ok = zcloud_store_upload(store, test_bucket, up_prod, NULL, &error);
            is_gboolean(op_ok, FALSE, "uploading test bucket returned not ok (as expected)");
            gerror_is_set(&error, NULL,
                ZCERR_PARAMETER, "uploading test bucket caused the expected error");

            g_object_unref(up_prod);
        }

        /* try to download a bucket, get error */
        {
            ZCloudDownloadConsumer *down_con;
            down_con = ZCLOUD_DOWNLOAD_CONSUMER(
                zcloud_growing_memory_download_consumer(1));

            op_ok = zcloud_store_download(store, test_bucket, down_con, NULL, &error);
            is_gboolean(op_ok, FALSE, "downloading test bucket returned not ok (as expected)");
            gerror_is_set(&error, NULL,
                ZCERR_PARAMETER, "downloading test bucket caused the expected error");

            g_object_unref(down_con);
        }

        g_object_unref(store);
        g_object_unref(test_store);
        g_free(test_bucket);
        g_free(test_bucket_spec);
    }

end:
    fprintf(stderr, tests_failed? "One or more tests FAILED\n" : "SUCCESS\n");
    return tests_failed? 1 : 0;
}
int
main (int argc, char **argv)
{
  int i;
  char *endptr;

  if (argc <= 2)
    usage();
  
  max_allocation = strtol (argv[1], &endptr, 10);
  if (endptr == argv[1])
    usage();

  /* Set a malloc which emulates low mem */
  g_mem_set_vtable (&limited_table);
  
  g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
  
  /* memory tests */

  /* How do the loaders behave when memory is low?
     It depends on the state the above tests left the 
     memory in.

     - Sometimes the png loader tries to report an 
       "out of memory", but then g_strdup_printf() calls
       g_malloc(), which fails.
       
     - There are unchecked realloc()s inside libtiff, which means it
       will never work with low memory, unless something drastic is
       done, like allocating a lot of memory upfront and release it
       before entering libtiff.  Also, some TIFFReadRGBAImage calls
       returns successfully, even though they have called the error
       handler with an 'out of memory' message.
  */

  almost_exhaust_memory ();

  g_print ("Allocated %dK of %dK, %dK free during tests\n",
           current_allocation / 1024, max_allocation / 1024,
           (max_allocation - current_allocation) / 1024);

  for (i = 2; i < argc; ++i)
    {
      gchar *contents;
      gsize size;
      GError *err = NULL;

      if (!g_file_get_contents (argv[i], &contents, &size, &err))
	{
	  g_print ("couldn't read %s: %s\n", argv[i], err->message);
	  exit (EXIT_FAILURE);
	}
      else
	{
	  g_print ("%-40s memory            ", argv[i]);
	  fflush (stdout);
	  mem_test (contents, size);
	  g_print ("\tpassed\n");
	  g_free (contents);
	}
    }
  
  return 0;
}
Exemple #7
0
int main()
{
  FILE *f;
  GPtrArray *examinees;
  OscatsSpace *contSpace, *binSpace;
  OscatsItemBank *bank;
  OscatsExaminee *e;
  OscatsDim dim;
  OscatsPoint *initTheta, *initAlpha;
  const guint num_tests = 4;
  const gchar *test_names[] = { "random", "FI", "KL.3PL", "KL.DINA" };
  OscatsTest *test[num_tests];
  OscatsAlgExposureCounter *exposure[num_tests];
  OscatsAlgClassRates *rates[num_tests];
  guint i, j, k;
  
  g_type_init();
  g_log_set_always_fatal(G_LOG_LEVEL_CRITICAL);         // For debugging
  
  /* In the previous examples, we had only one latent space; but, here we
   * want to use two different models from *different* latent spaces.  The
   * first latent space is a unidimensional continuous space (for the 3PL
   * model); the second is an N_ATTR-dimensional binary space (for the DINA
   * model).  If appropriate to the simulation (e.g. to compare 2PL vs. 3PL)
   * we could have created two different models from the same space.
   *
   * Note: Even though OscatsSpace accommodates mixed-type (continuous and
   * binary) latent spaces, the models we use here are either only
   * continuous or only binary, so they come from different latent spaces. 
   * A mixed-type model would be something like the Fusion model, which has
   * both binary and continuous components.
   */
  contSpace = g_object_new(OSCATS_TYPE_SPACE, "numCont", 1, NULL);
  binSpace = g_object_new(OSCATS_TYPE_SPACE, "numBin", N_ATTR, NULL);
  initTheta = oscats_point_new_from_space(contSpace);
  initAlpha = oscats_point_new_from_space(binSpace);

  printf("Reading examinees.\n");
  f = fopen("ex03-person.dat", "r");
  examinees = read_examinees(f, contSpace, binSpace);
  fclose(f);
  printf("Reading items.\n");
  f = fopen("ex03-items.dat", "r");
  bank = read_items(f, contSpace, binSpace);
  fclose(f);

  printf("Creating tests.\n");
  for (j=0; j < num_tests; j++)
  {
    // Create a new test with the given properties
    // Be sure to end calls to g_object_new() with NULL!
    test[j] = g_object_new(OSCATS_TYPE_TEST, "id", test_names[j],
                           "itembank", bank, "length_hint", LEN, NULL);

    // Register the common CAT algorithms for this test.
    
    // Here, we always simulate from the DINA model.
    oscats_algorithm_register(
      g_object_new(OSCATS_TYPE_ALG_SIMULATE,
                   "modelKey", "DINA", "thetaKey", "trueAlpha", NULL),
      test[j]);

    // Usually we would only have one estimate algorithm, but here, we need
    // to estimate both the continuous ability and the latent class, each
    // based on a separate model.
    oscats_algorithm_register(
      g_object_new(OSCATS_TYPE_ALG_ESTIMATE,
                   "modelKey", "3PL", "thetaKey", "estTheta", NULL),
      test[j]);
    oscats_algorithm_register(
      g_object_new(OSCATS_TYPE_ALG_ESTIMATE,
                   "modelKey", "DINA", "thetaKey", "estAlpha", NULL),
      test[j]);

    exposure[j] = oscats_algorithm_register(g_object_new(OSCATS_TYPE_ALG_EXPOSURE_COUNTER, NULL), test[j]);
    g_object_ref(exposure[j]);
    rates[j] = oscats_algorithm_register(
      g_object_new(OSCATS_TYPE_ALG_CLASS_RATES, "simKey", "trueAlpha",
                   "estKey", "estAlpha", NULL), test[j]);
    g_object_ref(rates[j]);

    oscats_algorithm_register(g_object_new(OSCATS_TYPE_ALG_FIXED_LENGTH,
                                           "len", LEN, NULL), test[j]);
  }
  
  // Register the item selection criteria for the different tests:
  // Since we aren't just using the default model for everything, we have to
  // tell each algorithm which model/theta to use for selection.
  oscats_algorithm_register(g_object_new(OSCATS_TYPE_ALG_PICK_RAND, NULL), test[0]);
  oscats_algorithm_register(
    g_object_new(OSCATS_TYPE_ALG_MAX_FISHER, "num", 5,
                 "modelKey", "3PL", "thetaKey", "estTheta", NULL), test[1]);
  oscats_algorithm_register(
    g_object_new(OSCATS_TYPE_ALG_MAX_KL, "num", 5,
                 "modelKey", "3PL", "thetaKey", "estTheta", NULL), test[2]);
  oscats_algorithm_register(
    g_object_new(OSCATS_TYPE_ALG_MAX_KL, "num", 5,
                 "modelKey", "DINA", "thetaKey", "estAlpha", NULL), test[3]);
  
  printf("Administering.\n");
  f = fopen("ex03-person-results.dat", "w");
  fprintf(f, "ID\ttrue.theta\ttrue.alpha\tinit.theta\tinit.alpha");
  for (j=0; j < num_tests; j++)
    fprintf(f, "\t%s.theta\t%s.alpha", test_names[j], test_names[j]);
  fprintf(f, "\n");
  for (i=0; i < N_EXAMINEES; i++)
  {
    OscatsPoint *tmp;
    e = g_ptr_array_index(examinees, i);
    tmp = oscats_examinee_get_theta_by_name(e, "trueTheta");
    dim = OSCATS_DIM_CONT+0;	// first continuous dimension
    fprintf(f, "%s\t%g\t", e->id, oscats_point_get_cont(tmp, dim));
    tmp = oscats_examinee_get_theta_by_name(e, "trueAlpha");
    dim = OSCATS_DIM_BIN+0;	// first binary dimension
    for (k=0; k < N_ATTR; k++, dim++)
      fprintf(f, oscats_point_get_bin(tmp, dim) ? "1" : "0");

    // Choose initial theta and alpha for this examinee
    // We'll use the same initial abilities for all four tests
    dim = OSCATS_DIM_CONT+0;	// first continuous dimension
    oscats_point_set_cont(initTheta, dim, oscats_rnd_normal(sqrt(0.05))-0.37);
    dim = OSCATS_DIM_BIN+0;	// first binary dimension
    for (k=0; k < N_ATTR; k++, dim++)
      oscats_point_set_bin(initAlpha, dim, oscats_rnd_uniform() < 0.5);
    
    // Initialize ability estimates for this examinee
    // (Examinee takes references for the new OscatsPoint objects)
    oscats_examinee_set_theta_by_name(e, "estTheta",
                                      oscats_point_new_from_space(contSpace));
    oscats_examinee_set_theta_by_name(e, "estAlpha",
                                      oscats_point_new_from_space(binSpace));

    for (j=0; j < num_tests; j++)
    {
      // Reset initial latent ability for this test
      oscats_point_copy(
        oscats_examinee_get_theta_by_name(e, "estTheta"), initTheta);
      oscats_point_copy(
        oscats_examinee_get_theta_by_name(e, "estAlpha"), initAlpha);

      // Do the administration!
      oscats_test_administer(test[j], e);

      // Output the resulting theta.hat and alpha.hat
      tmp = oscats_examinee_get_theta_by_name(e, "estTheta");
      dim = OSCATS_DIM_CONT+0;	// first continuous dimension
      fprintf(f, "\t%g\t", oscats_point_get_cont(tmp, dim));
      tmp = oscats_examinee_get_theta_by_name(e, "estAlpha");
      dim = OSCATS_DIM_BIN+0;	// first binary dimension
      for (k=0; k < N_ATTR; k++, dim++)
        fprintf(f, oscats_point_get_bin(tmp, dim) ? "1" : "0");
    }
    fprintf(f, "\n");
  }
  fclose(f);
  
  f = fopen("ex03-exposure.dat", "w");
  fprintf(f, "ID");
  for (j=0; j < num_tests; j++)
    fprintf(f, "\t%s", test_names[j]);
  fprintf(f, "\n");
  for (i=0; i < N_ITEMS; i++)
  {
    OscatsItem *item = OSCATS_ITEM(oscats_item_bank_get_item(bank, i));
    fprintf(f, "%d", i+1);
    // Get the exposure rate for this item in each test
    for (j=0; j < num_tests; j++)
      fprintf(f, "\t%g",
            oscats_alg_exposure_counter_get_rate(exposure[j], item));
    fprintf(f, "\n");
  }
  fclose(f);

  f = fopen("ex03-rates.dat", "w");
  fprintf(f, "Rate");
  for (j=0; j < num_tests; j++)
    fprintf(f, "\t%s", test_names[j]);
  fprintf(f, "\nPattern");
  for (j=0; j < num_tests; j++)
    fprintf(f, "\t%g", oscats_alg_class_rates_get_pattern_rate(rates[j]));
  for (k=0; k < N_ATTR; k++)
  {
    fprintf(f, "\nattr.%d", k+1);
    for (j=0; j < num_tests; j++)
      fprintf(f, "\t%g",
              oscats_alg_class_rates_get_attribute_rate(rates[j], k));
  }
  for (k=0; k <= N_ATTR; k++)
  {
    fprintf(f, "\nfreq.%d", k);
    for (j=0; j < num_tests; j++)
      fprintf(f, "\t%g",
              oscats_alg_class_rates_get_misclassify_freq(rates[j], k));
  }
  fprintf(f, "\n");
  fclose(f);

  // Clean up
  printf("Done.\n");
  for (j=0; j < num_tests; j++)
  {
    g_object_unref(exposure[j]);
    g_object_unref(rates[j]);
    g_object_unref(test[j]);
  }
  g_object_unref(bank);
  g_ptr_array_free(examinees, TRUE);
  g_object_unref(initTheta);
  g_object_unref(initAlpha);
  g_object_unref(contSpace);
  g_object_unref(binSpace);
  
  return 0;
}
static void
parse_args (gint    *argc_p,
	    gchar ***argv_p)
{
  guint argc = *argc_p;
  gchar **argv = *argv_p;
  guint i, e;

  for (i = 1; i < argc; i++)
    {
      if (strcmp ("--macros", argv[i]) == 0)
	{
	  gen_type = GDK_PIXDATA_DUMP_MACROS;
	  argv[i] = NULL;
	}
      else if (strcmp ("--struct", argv[i]) == 0)
	{
	  gen_type = GDK_PIXDATA_DUMP_PIXDATA_STRUCT;
	  argv[i] = NULL;
	}
      else if (strcmp ("--stream", argv[i]) == 0)
	{
	  gen_type = GDK_PIXDATA_DUMP_PIXDATA_STREAM;
	  argv[i] = NULL;
	}
      else if (strcmp ("--rle", argv[i]) == 0)
	{
	  use_rle = TRUE;
	  argv[i] = NULL;
	}
      else if (strcmp ("--raw", argv[i]) == 0)
	{
	  use_rle = FALSE;
	  argv[i] = NULL;
	}
      else if (strcmp ("--extern", argv[i]) == 0)
	{
	  gen_ctype &= ~GDK_PIXDATA_DUMP_STATIC;
	  argv[i] = NULL;
	}
      else if (strcmp ("--static", argv[i]) == 0)
	{
	  gen_ctype |= GDK_PIXDATA_DUMP_STATIC;
	  argv[i] = NULL;
	}
      else if (strcmp ("--decoder", argv[i]) == 0)
	{
	  with_decoder = TRUE;
	  argv[i] = NULL;
	}
      else if ((strcmp ("--name", argv[i]) == 0) ||
	       (strncmp ("--name=", argv[i], 7) == 0))
	{
	  gchar *equal = argv[i] + 6;

	  if (*equal == '=')
	    image_name = g_strdup (equal + 1);
	  else if (i + 1 < argc)
	    {
	      image_name = g_strdup (argv[i + 1]);
	      argv[i] = NULL;
	      i += 1;
	    }
	  argv[i] = NULL;
	}
      else if (strcmp ("--build-list", argv[i]) == 0)
	{
	  build_list = TRUE;
	  argv[i] = NULL;
	}
      else if (strcmp ("-h", argv[i]) == 0 ||
	       strcmp ("--help", argv[i]) == 0)
	{
	  print_blurb (stderr, TRUE);
	  argv[i] = NULL;
	  exit (0);
	}
      else if (strcmp ("-v", argv[i]) == 0 ||
	       strcmp ("--version", argv[i]) == 0)
	{
	  print_blurb (stderr, FALSE);
	  argv[i] = NULL;
	  exit (0);
	}
      else if (strcmp (argv[i], "--g-fatal-warnings") == 0)
	{
	  GLogLevelFlags fatal_mask;

	  fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK);
	  fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL;
	  g_log_set_always_fatal (fatal_mask);

	  argv[i] = NULL;
	}
    }

  e = 0;
  for (i = 1; i < argc; i++)
    {
      if (e)
	{
	  if (argv[i])
	    {
	      argv[e++] = argv[i];
	      argv[i] = NULL;
	    }
	}
      else if (!argv[i])
	e = i;
    }
  if (e)
    *argc_p = e;
}
Exemple #9
0
int
main (int argc, char *argv[])
{
	GMainContext *ctx;
	GMainLoop *loop;

	/*
	 * The mate-keyring startup is not as simple as I wish it could be.
	 *
	 * It's often started in the primordial stages of a session, where
	 * there's no DBus, and no proper X display. This is the strange world
	 * of PAM.
	 *
	 * When started with the --login option, we do as little initialization
	 * as possible. We expect a login password on the stdin, and unlock
	 * or create the login keyring.
	 *
	 * Then later we expect mate-keyring-dameon to be run again with the
	 * --start option. This second mate-keyring-daemon will hook the
	 * original daemon up with environment variables necessary to initialize
	 * itself and bring it into the session. This second daemon usually exits.
	 *
	 * Without either of these options, we follow a more boring and
	 * predictable startup.
	 */

	/*
	 * Before we do ANYTHING, we drop privileges so we don't become
	 * a security issue ourselves.
	 */
	gkd_capability_obtain_capability_and_drop_privileges ();

#ifdef WITH_TESTS
	g_setenv ("DBUS_FATAL_WARNINGS", "1", FALSE);
	if (!g_getenv ("G_DEBUG"))
		g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
#endif

	g_type_init ();
	g_thread_init (NULL);

#ifdef HAVE_LOCALE_H
	/* internationalisation */
	setlocale (LC_ALL, "");
#endif

#ifdef HAVE_GETTEXT
	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
	textdomain (GETTEXT_PACKAGE);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif

	egg_libgcrypt_initialize ();

	/* Send all warning or error messages to syslog */
	prepare_logging ();

	parse_arguments (&argc, &argv);

	/* The --version option. This is machine parseable output */
	if (run_version) {
		g_print ("mate-keyring-daemon: %s\n", VERSION);
		g_print ("testing: %s\n",
#ifdef WITH_TESTS
		         "enabled");
#else
		         "disabled");
#endif
		exit (0);
	}

	/* The --start option */
	if (run_for_start) {
		if (discover_other_daemon (initialize_daemon_at, TRUE)) {
			/*
			 * Another daemon was initialized, print out environment
			 * for any callers, and quit or go comatose.
			 */
			print_environment (0);
			if (run_foreground)
				while (sleep(0x08000000) == 0);
			cleanup_and_exit (0);
		}

	/* The --replace option */
	} else if (run_for_replace) {
		discover_other_daemon (replace_daemon_at, FALSE);
		if (control_directory)
			g_message ("replacing daemon at: %s", control_directory);
	}

	/* Initialize the main directory */
	gkd_util_init_master_directory (control_directory);

	/* Initialize our daemon main loop and threading */
	loop = g_main_loop_new (NULL, FALSE);
	ctx = g_main_loop_get_context (loop);

	/* Initialize our control socket */
	if (!gkd_control_listen ())
		return FALSE;

	/* The --login option. Delayed initialization */
	if (run_for_login) {
		login_password = read_login_password (STDIN);
		atexit (clear_login_password);
		timeout_id = g_timeout_add_seconds (LOGIN_TIMEOUT, (GSourceFunc) on_login_timeout, NULL);

	/* Not a login daemon. Startup stuff now.*/
	} else {
		/* These are things that can run before forking */
		if (!gkr_daemon_startup_steps (run_components))
			cleanup_and_exit (1);
	}

	/* The whole forking and daemonizing dance starts here. */
	fork_and_print_environment();

	setup_signal_handling (loop);

	/* Prepare logging a second time, since we may be in a different process */
	prepare_logging();

	/* Remainder initialization after forking, if initialization not delayed */
	if (!run_for_login) {
		gkr_daemon_initialize_steps (run_components);
	}

	g_main_loop_run (loop);

	/* This wraps everything up in order */
	egg_cleanup_perform ();

	/* Wrap up signal handling here */
	cleanup_signal_handling ();

	g_free (control_directory);

	return 0;
}
Exemple #10
0
gint
main (gint argc, gchar **argv)
{
  GOptionContext   *context;
  PanelApplication *application;
  GError           *error = NULL;
  PanelDBusService *dbus_service;
  gboolean          succeed = FALSE;
  gboolean          remote_succeed;
  guint             i;
  const gint        signums[] = { SIGINT, SIGQUIT, SIGTERM, SIGABRT, SIGUSR1 };
  const gchar      *error_msg;
  XfceSMClient     *sm_client;

  panel_debug (PANEL_DEBUG_MAIN,
               "version %s on gtk+ %d.%d.%d (%d.%d.%d), glib %d.%d.%d (%d.%d.%d)",
               LIBXFCE4PANEL_VERSION,
               gtk_major_version, gtk_minor_version, gtk_micro_version,
               GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION,
               glib_major_version, glib_minor_version, glib_micro_version,
               GLIB_MAJOR_VERSION, GLIB_MINOR_VERSION, GLIB_MICRO_VERSION);

  /* inform the user about usage of gdb/valgrind */
  panel_debug_notify_proxy ();

  /* set translation domain */
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

#ifdef G_ENABLE_DEBUG
  /* do NOT remove this line for now, If something doesn't work,
   * fix your code instead! */
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
#endif

  /* parse context options */
  context = g_option_context_new (_("[ARGUMENTS...]"));
  g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  g_option_context_add_group (context, xfce_sm_client_get_option_group (argc, argv));
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_print ("%s: %s.\n", PACKAGE_NAME, error->message);
      g_print (_("Type \"%s --help\" for usage."), G_LOG_DOMAIN);
      g_print ("\n");
      g_error_free (error);

      return EXIT_FAILURE;
    }
  g_option_context_free (context);

  gtk_init (&argc, &argv);

  if (opt_version)
    {
      /* print version information */
      if (opt_arguments != NULL && *opt_arguments != NULL)
        g_print ("%s (%s)", *opt_arguments, PACKAGE_NAME);
      else
        g_print ("%s", PACKAGE_NAME);
      g_print (" %s (Xfce %s)\n\n", PACKAGE_VERSION, xfce_version_string ());
      g_print ("%s\n", "Copyright (c) 2004-2011");
      g_print ("\t%s\n\n", _("The Xfce development team. All rights reserved."));
      g_print (_("Please report bugs to <%s>."), PACKAGE_BUGREPORT);
      g_print ("\n");

      return EXIT_SUCCESS;
    }
  else if (opt_preferences >= 0)
    {
      /* send a signal to the running instance to show the preferences dialog */
      succeed = panel_dbus_client_display_preferences_dialog (opt_preferences, opt_socket_id, &error);
      goto dbus_return;
    }
  else if (opt_add_items >= 0)
    {
      /* send a signal to the running instance to show the add items dialog */
      succeed = panel_dbus_client_display_items_dialog (opt_add_items, &error);
      goto dbus_return;
    }
  else if (opt_save)
    {
      /* send a save signal to the running instance */
      succeed = panel_dbus_client_save (&error);
      goto dbus_return;
    }
  else if (opt_add != NULL)
    {
      /* send a add-new-item signal to the running instance */
      succeed = panel_dbus_client_add_new_item (opt_add, opt_arguments, &error);
      goto dbus_return;
    }
  else if (opt_restart || opt_quit)
    {
      /* send a terminate signal to the running instance */
      succeed = panel_dbus_client_terminate (opt_restart, &error);
      goto dbus_return;
    }
  else if (opt_plugin_event != NULL)
    {
      /* send the plugin event to the running instance */
      remote_succeed = FALSE;
      succeed = panel_dbus_client_plugin_event (opt_plugin_event, &remote_succeed, &error);

      /* the panel returns EXIT_FAILURE if the dbus event succeeds, but
       * no suitable plugin was found on the service side */
      if (succeed && !remote_succeed)
        succeed = FALSE;

      goto dbus_return;
    }

  launch_panel:

  /* start dbus service */
  dbus_service = panel_dbus_service_get ();
  if (!panel_dbus_service_is_owner (dbus_service))
    {
      /* quit without error if an instance is running */
      succeed = TRUE;

      g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("There is already a running instance"));
      goto dbus_return;
    }

  /* start session management */
  sm_client = xfce_sm_client_get ();
  xfce_sm_client_set_restart_style (sm_client, XFCE_SM_CLIENT_RESTART_IMMEDIATELY);
  xfce_sm_client_set_priority (sm_client, XFCE_SM_CLIENT_PRIORITY_CORE);
  g_signal_connect (G_OBJECT (sm_client), "quit",
      G_CALLBACK (panel_sm_client_quit), NULL);
  if (!xfce_sm_client_connect (sm_client, &error))
    {
      g_printerr ("%s: Failed to connect to session manager: %s\n",
                  G_LOG_DOMAIN, error->message);
      g_clear_error (&error);
    }

  /* setup signal handlers to properly quit the main loop */
  for (i = 0; i < G_N_ELEMENTS (signums); i++)
    signal (signums[i], panel_signal_handler);

  application = panel_application_get ();
  panel_application_load (application, opt_disable_wm_check);

  /* open dialog if we started from launch_panel */
  if (opt_preferences >= 0)
    panel_preferences_dialog_show_from_id (opt_preferences, opt_socket_id);

  gtk_main ();

  /* make sure there are no incomming events when we close */
  g_object_unref (G_OBJECT (dbus_service));

  /* destroy all the opened dialogs */
  panel_application_destroy_dialogs (application);

  g_object_unref (G_OBJECT (application));
  g_object_unref (G_OBJECT (sm_client));

  if (panel_dbus_service_get_restart ())
    {
      /* spawn ourselfs again */
      g_print ("%s: %s\n\n", G_LOG_DOMAIN, _("Restarting..."));
      g_spawn_command_line_async (argv[0], NULL);
    }

  return EXIT_SUCCESS;

dbus_return:

  /* stop any running startup notification */
  gdk_notify_startup_complete ();

  if (G_UNLIKELY (error != NULL))
    {
      /* get suitable error message */
      if (opt_preferences >= 0)
        error_msg = _("Failed to show the preferences dialog");
      else if (opt_add_items >= 0)
        error_msg = _("Failed to show the add new items dialog");
      else if (opt_save)
        error_msg = _("Failed to save the panel configuration");
      else if (opt_add)
        error_msg = _("Failed to add a plugin to the panel");
      else if (opt_restart)
        error_msg = _("Failed to restart the panel");
      else if (opt_quit)
        error_msg = _("Failed to quit the panel");
      else
        error_msg = _("Failed to send D-Bus message");

      /* show understandable message for this common error */
      if (error->code == DBUS_GERROR_NAME_HAS_NO_OWNER)
        {
          /* normally start the panel */
          if (opt_preferences >= 0 || opt_restart)
            {
              g_clear_error (&error);

              if (xfce_dialog_confirm (NULL, GTK_STOCK_EXECUTE, NULL,
                                       _("Do you want to start the panel? If you do, make sure "
                                         "you save the session on logout, so the panel is "
                                         "automatically started the next time you login."),
                                       _("No running instance of %s was found"), G_LOG_DOMAIN))
                {
                  panel_debug (PANEL_DEBUG_MAIN, "user confirmed to start the panel");
                  goto launch_panel;
                }
              else
                {
                  return EXIT_FAILURE;
                }
            }
          else
            {
              /* I18N: %s is replaced with xfce4-panel */
              g_clear_error (&error);
              g_set_error (&error, 0, 0, _("No running instance of %s was found"), G_LOG_DOMAIN);
            }
        }

      /* show error dialog */
      xfce_dialog_show_error (NULL, error, "%s", error_msg);
      g_error_free (error);
    }

  return succeed ? EXIT_SUCCESS : EXIT_FAILURE;
}
Exemple #11
0
gpointer
cockpit_polkit_agent_register (CockpitTransport *transport,
                               GCancellable *cancellable)
{
  PolkitAgentListener *listener = NULL;
  PolkitAuthority *authority = NULL;
  PolkitSubject *subject = NULL;
  GVariant *options;
  GLogLevelFlags fatal;
  GError *error = NULL;
  gpointer handle = NULL;
  guint handler = 0;
  gchar *string;

  authority = polkit_authority_get_sync (cancellable, &error);
  if (authority == NULL)
    {
      g_message ("couldn't get polkit authority: %s", error->message);
      goto out;
    }

  subject = polkit_unix_session_new_for_process_sync (getpid (), cancellable, &error);
  if (subject == NULL)
    {
      g_warning ("couldn't create polkit session subject: %s", error->message);
      goto out;
    }

  listener = g_object_new (COCKPIT_TYPE_POLKIT_AGENT,
                           "transport", transport,
                           NULL);
  options = NULL;

  /*
   * HACK: Work around polkitagent warning:
   *
   * https://bugs.freedesktop.org/show_bug.cgi?id=78193
   */

  fatal = g_log_set_always_fatal (0);
  handler = g_log_set_handler (NULL, G_LOG_LEVEL_WARNING, cockpit_null_log_handler, NULL);

  handle = polkit_agent_listener_register_with_options (listener,
                                                        POLKIT_AGENT_REGISTER_FLAGS_NONE,
                                                        subject, NULL, options, cancellable, &error);

  g_log_set_always_fatal (fatal);
  g_log_remove_handler (NULL, handler);

  if (error != NULL)
    {
      if ((g_error_matches (error, POLKIT_ERROR, POLKIT_ERROR_FAILED) &&
           error->message && strstr (error->message, "already exists")) ||
          g_error_matches (error, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN))
        {
          g_debug ("couldn't register polkit agent: %s", error->message);
        }
      else
        {
          g_dbus_error_strip_remote_error (error);
          g_message ("couldn't register polkit authentication agent: %s", error->message);
        }
      goto out;
    }

  string = polkit_subject_to_string (subject);

  g_debug ("registered polkit authentication agent for subject: %s", string);
  g_free (string);

out:
  if (subject)
    g_object_unref (subject);
  if (authority)
    g_object_unref (authority);
  if (listener)
    g_object_unref (listener);
  g_clear_error (&error);
  return handle;
}