Пример #1
0
static GFile *
create_uncompress_directory (GFile   *dest,
                             guint    strip_components,
                             GError **error)
{
  GFile *uncompress_dest = NULL;

  if (strip_components > 0)
    {
      g_autoptr(GFile) tmp_dir_template = g_file_get_child (dest, ".uncompressXXXXXX");
      g_autofree char *tmp_dir_path = g_file_get_path (tmp_dir_template);

      if (g_mkdtemp (tmp_dir_path) == NULL)
        {
          int saved_errno = errno;
          g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                       "Can't create uncompress directory: %s",
                       g_strerror (saved_errno));
          return NULL;
        }

      uncompress_dest = g_file_new_for_path (tmp_dir_path);
    }
  else
    {
      uncompress_dest = g_object_ref (dest);
    }

  return uncompress_dest;
}
void
test_setup_thetvdb (void)
{
  GrlConfig *config;
  GrlRegistry *registry;
  GError *error = NULL;

  if (tmp_dir == NULL) {
    /* Only create tmp dir and set the XDG_DATA_HOME once */
    tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL);
    tmp_dir = g_mkdtemp (tmp_dir);
    g_assert_nonnull (tmp_dir);

    g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE);
  }

  config = grl_config_new (THETVDB_ID, NULL);
  grl_config_set_api_key (config, "THETVDB_TEST_MOCK_API_KEY");

  registry = grl_registry_get_default ();
  grl_registry_add_config (registry, config, &error);
  g_assert_no_error (error);

  grl_registry_load_plugin_by_id (registry, THETVDB_ID, &error);
  g_assert_no_error (error);

  source = GRL_SOURCE (grl_registry_lookup_source (registry, THETVDB_ID));
  g_assert (source != NULL);

  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
}
Пример #3
0
Файл: tar.c Проект: ib/xarchiver
gboolean xa_tar_extract (XArchive *archive, GSList *file_list)
{
	GString *files;
	gchar *extract_to, *command;
	gboolean result;

	if (archive->do_full_path)
		extract_to = g_strdup(archive->extraction_dir);
	else
	{
		if (!xa_create_working_directory(archive))
			return FALSE;

		extract_to = g_strconcat(archive->working_dir, "/xa-tmp.XXXXXX", NULL);

		if (!g_mkdtemp(extract_to))
		{
			g_free(extract_to);
			return FALSE;
		}
	}

	files = xa_quote_filenames(file_list, NULL, TRUE);
	command = g_strconcat(archiver[XARCHIVETYPE_TAR].program[0],
	                      " -x --no-recursion --no-wildcards",
	                      " -f ", archive->path[2],
	                      archive->do_touch ? " -m" : "",
	                      archive->do_overwrite ? "" : (archive->do_update ? " --keep-newer-files" : " -k"),
	                      " -C ", extract_to, files->str, NULL);

	result = xa_run_command(archive, command);
	g_free(command);

	/* collect all files that have been extracted to move them without full path */
	if (result && !archive->do_full_path)
	{
		GString *all_files = xa_collect_files_in_dir(extract_to);

		archive->child_dir = g_strdup(extract_to);
		command = g_strconcat("mv",
		                      archive->do_overwrite ? " -f" : " -n",
		                      archive->do_update ? " -fu" : "",
		                      all_files->str, " ", archive->extraction_dir, NULL);
		g_string_free(all_files, TRUE);

		result = xa_run_command(archive, command);
		g_free(command);

		g_free(archive->child_dir);
		archive->child_dir = NULL;
	}

	g_free(extract_to);
	g_string_free(files, TRUE);

	return result;
}
Пример #4
0
gboolean xa_unar_extract (XArchive *archive, GSList *file_list)
{
	GString *files;
	gchar *extract_to, *password_str, *command;
	gboolean result;

	if (archive->do_full_path)
		extract_to = g_strdup(archive->extraction_dir);
	else
	{
		if (!xa_create_working_directory(archive))
			return FALSE;

		extract_to = g_strconcat(archive->working_dir, "/xa-tmp.XXXXXX", NULL);

		if (!g_mkdtemp(extract_to))
		{
			g_free(extract_to);
			return FALSE;
		}
	}

	files = xa_quote_filenames(file_list, "*?[]\"", TRUE);
	password_str = xa_unar_password_str(archive);
	command = g_strconcat(archiver[archive->type].program[1], " ",
	                      archive->path[1], password_str, " -D -q",
	                      archive->do_overwrite ? " -f" : "",
	                      " -o ", extract_to, files->str, NULL);

	result = xa_run_command(archive, command);
	g_free(command);

	/* collect all files that have been extracted to move them without full path */
	if (result && !archive->do_full_path)
	{
		GString *all_files = xa_collect_files_in_dir(extract_to);

		archive->child_dir = g_strdup(extract_to);
		command = g_strconcat("mv",
		                      archive->do_overwrite ? " -f" : " -n",
		                      all_files->str, " ", archive->extraction_dir, NULL);
		g_string_free(all_files, TRUE);

		result = xa_run_command(archive, command);
		g_free(command);

		g_free(archive->child_dir);
		archive->child_dir = NULL;
	}

	g_free(extract_to);
	g_free(password_str);
	g_string_free(files, TRUE);

	return result;
}
Пример #5
0
int
main (int argc, char *argv[])
{
  gchar *path;

  path = g_mkdtemp (g_strdup ("app_monitor_XXXXXX"));
  g_setenv ("XDG_DATA_DIRS", path, TRUE);
  g_setenv ("XDG_DATA_HOME", path, TRUE);

  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/monitor/app", test_app_monitor);

  return g_test_run ();
}
Пример #6
0
static char *
pack_files (GList *file_list)
{
	char *file_roller_cmd;
	const char *filename;
	GList *l;
	GString *cmd, *tmp;
	char *pack_type, *tmp_work_dir, *packed_file;

	file_roller_cmd = g_find_program_in_path ("file-roller");
	filename = pack_filename_from_names (file_list);

	g_assert (filename != NULL && *filename != '\0');

	tmp_work_dir = g_build_filename (g_get_tmp_dir (),
					 "nautilus-sendto-XXXXXX",
					 NULL);
	tmp_work_dir = g_mkdtemp (tmp_work_dir);

	pack_type = g_strdup (".zip");

	cmd = g_string_new ("");
	g_string_printf (cmd, "%s --add-to=\"%s/%s%s\"",
			 file_roller_cmd, tmp_work_dir,
			 filename,
			 pack_type);

	/* file-roller doesn't understand URIs */
	for (l = file_list ; l; l=l->next){
		char *file;

		file = g_filename_from_uri (l->data, NULL, NULL);
		g_string_append_printf (cmd," \"%s\"", file);
		g_free (file);
	}

	g_spawn_command_line_sync (cmd->str, NULL, NULL, NULL, NULL);
	g_string_free (cmd, TRUE);
	tmp = g_string_new("");
	g_string_printf (tmp,"%s/%s%s", tmp_work_dir,
			 filename,
			 pack_type);
	g_free (tmp_work_dir);
	packed_file = g_filename_to_uri (tmp->str, NULL, NULL);
	g_string_free(tmp, TRUE);

	return packed_file;
}
Пример #7
0
int main(int argc, char* argv[])
{
    int ret;
    MMSConfig config;
    const char* test_name = NULL;

    mms_lib_init(argv[0]);
    mms_lib_default_config(&config);
    mms_log_default.name = "test_read_ind";

    if (argc > 1 && !strcmp(argv[1], "-v")) {
        mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
        memmove(argv + 1, argv + 2, (argc-2)*sizeof(argv[0]));
        argc--;
    } else {
        mms_log_default.level = MMS_LOGLEVEL_INFO;
        mms_task_notification_log.level = MMS_LOGLEVEL_NONE;
        mms_log_stdout_timestamp = FALSE;
    }

    if (argc == 2 && argv[1][0] != '-') {
        test_name = argv[1];
    }

    if (argc == 1 || test_name) {
        char* tmpd = g_mkdtemp(g_strdup("/tmp/test_read_ind_XXXXXX"));
        MMS_VERBOSE("Temporary directory %s", tmpd);
        config.root_dir = tmpd;
        config.idle_secs = 0;
        config.attic_enabled = TRUE;
        ret = test_run(&config, test_name);
        remove(tmpd);
        g_free(tmpd);
    } else {
        printf("Usage: test_read_ind [-v] [TEST]\n");
        ret = RET_ERR;
    }

    mms_lib_deinit();
    return ret;
}
gboolean
rpmostree_builtin_upgrade (int             argc,
                           char          **argv,
                           GCancellable   *cancellable,
                           GError        **error)
{
  gboolean ret = FALSE;
  GOptionContext *context = g_option_context_new ("- Perform a system upgrade");
  gs_unref_object GFile *sysroot_path = NULL;
  gs_unref_object OstreeSysroot *sysroot = NULL;
  gs_unref_object OstreeSysrootUpgrader *upgrader = NULL;
  gs_unref_object OstreeAsyncProgress *progress = NULL;
  GSConsole *console = NULL;
  gboolean changed;
  OstreeSysrootUpgraderPullFlags upgraderpullflags = 0;

  gs_free char *origin_description = NULL;
  gs_unref_object OstreeRepo *repo = NULL; 

  g_option_context_add_main_entries (context, option_entries, NULL);

   if (!g_option_context_parse (context, &argc, &argv, error))
    goto out;

  sysroot_path = g_file_new_for_path (opt_sysroot);
  sysroot = ostree_sysroot_new (sysroot_path);
  if (!ostree_sysroot_load (sysroot, cancellable, error))
    goto out;

  upgrader = ostree_sysroot_upgrader_new_for_os (sysroot, opt_osname,
                                                 cancellable, error);
  if (!upgrader)
    goto out;

  origin_description = ostree_sysroot_upgrader_get_origin_description (upgrader);
  if (origin_description)
    g_print ("Updating from: %s\n", origin_description);

  if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
    goto out;

  console = gs_console_get ();
  if (console)
    {
      gs_console_begin_status_line (console, "", NULL, NULL);
      progress = ostree_async_progress_new_and_connect (_rpmostree_pull_progress, console);
    }

  if (opt_allow_downgrade)  
    upgraderpullflags |= OSTREE_SYSROOT_UPGRADER_PULL_FLAGS_ALLOW_OLDER;

  if (opt_check_diff)
    {
      if (!ostree_sysroot_upgrader_pull_one_dir (upgrader, "/usr/share/rpm", 0, 0, progress, &changed,
                                     cancellable, error))
        goto out;
    }

  else
    {
      if (!ostree_sysroot_upgrader_pull (upgrader, 0, 0, progress, &changed,
                                       cancellable, error))
        goto out;
    }

  if (console)
    {
      if (!gs_console_end_status_line (console, cancellable, error))
        {
          console = NULL;
          goto out;
        }
      console = NULL;
    }

  if (!changed)
    {
      g_print ("No updates available.\n");
    }
  else
    {
      if (!opt_check_diff)
        {
          if (!ostree_sysroot_upgrader_deploy (upgrader, cancellable, error))
                goto out;
        
          if (opt_reboot)
            gs_subprocess_simple_run_sync (NULL, GS_SUBPROCESS_STREAM_DISPOSITION_INHERIT,
                                           cancellable, error,
                                           "systemctl", "reboot", NULL);
          else
            {
#ifdef HAVE_PATCHED_HAWKEY_AND_LIBSOLV
              if (!rpmostree_print_treepkg_diff (sysroot, cancellable, error))
                goto out;
#endif

              g_print ("Updates prepared for next boot; run \"systemctl reboot\" to start a reboot\n");
            }
        }


      else
        {
          gs_unref_object GFile *rpmdbdir = NULL;
          _cleanup_rpmrev_ struct RpmRevisionData *rpmrev1 = NULL;
          _cleanup_rpmrev_ struct RpmRevisionData *rpmrev2 = NULL;

          gs_free char *tmpd = g_mkdtemp (g_strdup ("/tmp/rpm-ostree.XXXXXX"));

          gs_free char *ref = NULL; // location of this rev
          gs_free char *remote = NULL;

          if (!ostree_parse_refspec (origin_description, &remote, &ref, error))
             goto out;

          if (rpmReadConfigFiles (NULL, NULL))
            {
              g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                           "rpm failed to init: %s", rpmlogMessage());
              goto out;
            }

          rpmdbdir = g_file_new_for_path (tmpd);

          if (!(rpmrev1 = rpmrev_new (repo, rpmdbdir, 
                                      ostree_deployment_get_csum (ostree_sysroot_get_booted_deployment (sysroot)),
                                      NULL, cancellable, error)))
            goto out;

          if (!(rpmrev2 = rpmrev_new (repo, rpmdbdir, ref,
                                      NULL, cancellable, error)))
            goto out;

          rpmhdrs_diff_prnt_diff (rpmrev1->root, rpmrev2->root,
                            rpmhdrs_diff (rpmrev1->rpmdb, rpmrev2->rpmdb),
                            cancellable, error);
        }
    }
  
  ret = TRUE;
 out:
  if (console)
    (void) gs_console_end_status_line (console, NULL, NULL);

  return ret;
}
Пример #9
0
gboolean
rpmostree_db_option_context_parse (GOptionContext *context,
                                   const GOptionEntry *main_entries,
                                   int *argc, char ***argv,
                                   OstreeRepo **out_repo,
                                   GFile **out_rpmdbdir,
                                   gboolean *out_rpmdbdir_is_tmp,
                                   GCancellable *cancellable, GError **error)
{
  gs_unref_object OstreeRepo *repo = NULL;
  gs_unref_object GFile *rpmdbdir = NULL;
  gboolean rpmdbdir_is_tmp = FALSE;
  gboolean success = FALSE;

  /* Entries are listed in --help output in the order added.  We add the
   * main entries ourselves so that we can add the --repo entry first. */

  g_option_context_add_main_entries (context, global_entries, NULL);

  if (!rpmostree_option_context_parse (context, main_entries, argc, argv, error))
    goto out;

  if (opt_repo == NULL)
    {
      gs_unref_object OstreeSysroot *sysroot = NULL;

      sysroot = ostree_sysroot_new_default ();
      if (!ostree_sysroot_load (sysroot, cancellable, error))
        goto out;

      if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
        goto out;
    }
  else
    {
      gs_unref_object GFile *repo_file = g_file_new_for_path (opt_repo);

      repo = ostree_repo_new (repo_file);
      if (!ostree_repo_open (repo, cancellable, error))
        goto out;
    }

  if (rpmReadConfigFiles (NULL, NULL))
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                   "rpm failed to init: %s", rpmlogMessage ());
      goto out;
    }

  if (opt_rpmdbdir != NULL)
    {
      rpmdbdir = g_file_new_for_path (opt_rpmdbdir);
    }
  else
    {
      /* tmp on tmpfs is much faster than /var/tmp,
       * and the rpmdb itself shouldn't be too big. */
      gs_free char *tmpd = g_mkdtemp (g_strdup ("/tmp/rpm-ostree.XXXXXX"));
      rpmdbdir = g_file_new_for_path (tmpd);
      rpmdbdir_is_tmp = TRUE;
      ostree_repo_set_disable_fsync (repo, TRUE);
    }

  gs_transfer_out_value (out_repo, &repo);
  gs_transfer_out_value (out_rpmdbdir, &rpmdbdir);

  if (out_rpmdbdir_is_tmp != NULL)
    *out_rpmdbdir_is_tmp = rpmdbdir_is_tmp;

  success = TRUE;

out:
  return success;
}
Пример #10
0
static void
kms_image_overlay_load_image_to_overlay (KmsImageOverlay * imageoverlay)
{
  gchar *url = NULL;
  IplImage *costumeAux = NULL;
  gboolean fields_ok = TRUE;

  fields_ok = fields_ok
      && gst_structure_get (imageoverlay->priv->image_to_overlay,
      "offsetXPercent", G_TYPE_DOUBLE, &imageoverlay->priv->offsetXPercent,
      NULL);
  fields_ok = fields_ok
      && gst_structure_get (imageoverlay->priv->image_to_overlay,
      "offsetYPercent", G_TYPE_DOUBLE, &imageoverlay->priv->offsetYPercent,
      NULL);
  fields_ok = fields_ok
      && gst_structure_get (imageoverlay->priv->image_to_overlay,
      "widthPercent", G_TYPE_DOUBLE, &imageoverlay->priv->widthPercent, NULL);
  fields_ok = fields_ok
      && gst_structure_get (imageoverlay->priv->image_to_overlay,
      "heightPercent", G_TYPE_DOUBLE, &imageoverlay->priv->heightPercent, NULL);
  fields_ok = fields_ok
      && gst_structure_get (imageoverlay->priv->image_to_overlay, "url",
      G_TYPE_STRING, &url, NULL);

  if (!fields_ok) {
    GST_WARNING_OBJECT (imageoverlay, "Invalid image structure received");
    goto end;
  }

  if (url == NULL) {
    GST_DEBUG ("Unset the image overlay");
    goto end;
  }

  if (!imageoverlay->priv->dir_created) {
    gchar *d = g_strdup (TEMP_PATH);

    imageoverlay->priv->dir = g_mkdtemp (d);
    imageoverlay->priv->dir_created = TRUE;
  }

  costumeAux = cvLoadImage (url, CV_LOAD_IMAGE_UNCHANGED);

  if (costumeAux != NULL) {
    GST_DEBUG ("Image loaded from file");
    goto end;
  }

  if (kms_image_overlay_is_valid_uri (url)) {
    gchar *file_name =
        g_strconcat (imageoverlay->priv->dir, "/image.png", NULL);
    load_from_url (file_name, url);
    costumeAux = cvLoadImage (file_name, CV_LOAD_IMAGE_UNCHANGED);
    g_remove (file_name);
    g_free (file_name);
  }

  if (costumeAux == NULL) {
    GST_DEBUG ("Image not loaded");
  } else {
    GST_DEBUG ("Image loaded from URL");
  }

end:

  if (imageoverlay->priv->costume != NULL) {
    cvReleaseImage (&imageoverlay->priv->costume);
    imageoverlay->priv->costume = NULL;
  }

  if (costumeAux != NULL) {
    imageoverlay->priv->costume = costumeAux;
  }

  g_free (url);
}
Пример #11
0
Файл: erln8.c Проект: mkb/erln8
// THIS FUNCTION NEEDS TO BE BROKEN UP INTO SMALLER PIECES!
void build_erlang(gchar* repo, gchar* tag, gchar* id, gchar* build_config) {
  // check to see if the ID has already been used
  GHashTable* otps = get_erlangs();
  gboolean has_otp = g_hash_table_contains(otps, id);
  g_hash_table_destroy(otps);
  if(has_otp) {
    g_error("A version of Erlang already exists with this id: %s\n", id);
  }
  // check to see if the repo exists
  GHashTable* repos   = get_repos();
  gboolean has_repo = g_hash_table_contains(repos, repo);
  g_hash_table_destroy(repos);
  if(!has_repo) {
    g_error("Unconfigured repo: %s\n", repo);
  }
  // check for a valid build config if one is specified
  GHashTable* configs = get_configs();
  if(build_config) {
    if(!g_hash_table_contains(configs, build_config)) {
      g_hash_table_destroy(configs);
      g_error("Unconfigured build config: %s\n", build_config);
    }
  } else {
    // check the default
    GHashTable* e8 = get_erln8();
    if(g_hash_table_contains(e8, "default_config")) {
      build_config = strdup((gchar*)g_hash_table_lookup(e8, "default_config"));
      printf("%sUsing default config %s%s\n", build_config, yellow(), color_reset());
    }
    g_hash_table_destroy(e8);
  }
  gchar pattern[] = "/tmp/erln8.buildXXXXXX";
  gchar* tmp = g_mkdtemp(pattern);
  g_debug("building in %s\n", tmp);
  gchar* output_root = get_config_subdir_file_name("otps",id);
  gchar* output_path = g_strconcat(output_root, "/dist", NULL);
  gchar* source_path = get_config_subdir_file_name("repos", repo);
  GTimeVal t;
  g_get_current_time(&t);
  gchar* ts = g_time_val_to_iso8601(&t);
  gchar* ld = g_strconcat("logs/build_", id, "_", ts, NULL);
  gchar* log_path    = get_configdir_file_name(ld);
  // check that the branch or tag exists in the specified repo
  gchar* check_obj = g_strconcat("cd ", source_path, "&& git show-ref ", tag, " > /dev/null", NULL);
  if(system(check_obj) != 0) {
    g_free(check_obj);
    g_error("branch or tag %s does not exist in %s Git repo\n",
            tag,
            repo);
  }
  g_free(check_obj);
  /// check that the repo has been cloned
  if(!g_file_test(source_path, G_FILE_TEST_EXISTS |
                  G_FILE_TEST_IS_REGULAR)) {
    g_error("Missing repo for %s, which should be in %s.\nDid you forget to `erln8 --clone <repo_name>?`\n", repo, source_path);
  }
  gchar* bc = NULL;
  gchar* env = NULL;
  if(build_config != NULL) {
    bc = (gchar*)g_hash_table_lookup(configs, build_config);
    // don't drop a NULL into the middle of the command string
    if(bc == NULL) {
      bc = "";
    } else {
      gchar* env_name = g_strconcat(build_config, "_env", NULL);
      env = (gchar*)g_hash_table_lookup(configs, env_name);
      if(env == NULL) {
        env = "";
      }
      g_free(env_name);
    }
  } else {
    if(env == NULL) {
      env = "";
    }
  }
  g_free(ld);
  g_debug("Output path = %s\n", output_path);
  g_debug("Source path = %s\n", source_path);
  g_debug("Log path = %s\n", log_path);
  printf("Building %s from tag/branch %s of repo %s\n", id, tag, repo);
  printf("Custom build config: %s\n", bc);
  printf("Custom build env: %s\n", env);
  printf("Build log: %s\n", log_path);
  gchar* buildcmd0 = g_strconcat(env,
                                " cd ",
                                source_path,
                                " && git archive ",
                                tag,
                                " | (cd ", tmp, "; tar -f - -x)", NULL);
  gchar* buildcmd1 = g_strconcat(env, " cd ", tmp,
                                " && ./otp_build autoconf > ", log_path, " 2>&1", NULL);
  gchar* buildcmd2 = g_strconcat(env, " cd ", tmp,
                                " && ./configure --prefix=", output_path," ",
                                bc == NULL ? "" : bc,
                                " >> ", log_path, " 2>&1",
                                NULL);
  gchar* buildcmd3 = g_strconcat(env, " cd ", tmp,
                                " && make >> ", log_path,  " 2>&1", NULL);
  gchar* buildcmd4 = g_strconcat(env, " cd ", tmp,
                                " && make install >> ", log_path, " 2>&1", NULL);
  gchar* build_cmds[] = {
    buildcmd0,
    buildcmd1,
    buildcmd2,
    buildcmd3,
    buildcmd4,
    NULL
  };
  int result = 0;
  int i = 0;
  for(i = 0; i < step_count; i++) {
    show_build_progress(i, result);
    if(result != 0) {
      g_debug("STATUS = %d\n", result);
      printf("Here are the last 10 lines of the log file:\n");
      gchar* tail = g_strconcat("tail -10 ", log_path, NULL);
      int tailresult = system(tail);
      if(tailresult != 0) {
        g_error("Cannot run tail -10 on %s\n", log_path);
      }
      g_free(tail);
      printf("---------------------------------------------------------\n");
      g_error("Build error, please check the build logs for more details\n");
    }
    g_debug("running %s\n", build_cmds[i]);
    if(!opt_dryrun) {
      result = system(build_cmds[i]);
    } else {
      result = 0;
      printf("%s\n", build_cmds[i]);
    }
  }
  show_build_progress(step_count, result);
  printf("Registering Erlang installation\n");
  if(!opt_dryrun) {
    set_config_kv("Erlangs", id, output_root);
  }
  printf("Generating links\n");
  setup_binaries(id);
  printf("%sBuild complete%s\n", green(), color_reset() );
  g_free(buildcmd0);
  g_free(buildcmd1);
  g_free(buildcmd2);
  g_free(buildcmd3);
  g_free(buildcmd4);
  g_free(log_path);
  g_free(source_path);
  g_free(output_path);
  g_free(output_root);
  // destroy close to the end so the string isn't freed before it's used
  g_hash_table_destroy(configs);
}
Пример #12
0
int main(int argc, char* argv[])
{
    int ret = RET_ERR;
    gboolean debug = FALSE;
    gboolean verbose = FALSE;
    GError* error = NULL;
    GOptionContext* options;
    GOptionEntry entries[] = {
        { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
          "Enable verbose output", NULL },
        { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
          "Disable timeout for debugging", NULL },
        { NULL }
    };

    options = g_option_context_new("[TEST] - MMS read report test");
    g_option_context_add_main_entries(options, entries, NULL);
    if (g_option_context_parse(options, &argc, &argv, &error)) {
        MMSConfig config;
        char* tmpd = g_mkdtemp(g_strdup("/tmp/test_read_report_XXXXXX"));
        char* msgdir = g_strconcat(tmpd, "/msg", NULL);

        mms_lib_init(argv[0]);
        mms_lib_default_config(&config);
        config.idle_secs = 0;
        config.root_dir = tmpd;
        mms_log_default.name = "test_read_report";
        if (verbose) {
            mms_log_default.level = MMS_LOGLEVEL_VERBOSE;
        } else {
            mms_log_default.level = MMS_LOGLEVEL_INFO;
            mms_task_decode_log.level =
            mms_task_retrieve_log.level =
            mms_task_notification_log.level = MMS_LOGLEVEL_NONE;
            mms_log_stdout_timestamp = FALSE;
        }

        MMS_VERBOSE("Temporary directory %s", tmpd);
        if (argc < 2) {
            ret = test_read_report(&config, NULL, debug);
        } else {
            int i;
            for (i=1, ret = RET_OK; i<argc; i++) {
                int test_status =  test_read_report(&config, argv[i], debug);
                if (ret == RET_OK && test_status != RET_OK) ret = test_status;
            }
        }
        rmdir(msgdir);
        rmdir(tmpd);
        remove(tmpd);
        g_free(tmpd);
        g_free(msgdir);
        mms_lib_deinit();
    } else {
        fprintf(stderr, "%s\n", MMS_ERRMSG(error));
        g_error_free(error);
        ret = RET_ERR;
    }
    g_option_context_free(options);
    return ret;
}
Пример #13
0
static gboolean
git_mirror_submodules (const char     *repo_location,
                       gboolean        update,
                       GFile          *mirror_dir,
                       const char     *revision,
                       BuilderContext *context,
                       GError        **error)
{
  g_autofree char *mirror_dir_path = NULL;

  g_autoptr(GFile) checkout_dir_template = NULL;
  g_autoptr(GFile) checkout_dir = NULL;
  g_autofree char *checkout_dir_path = NULL;
  g_autofree char *submodule_status = NULL;

  mirror_dir_path = g_file_get_path (mirror_dir);

  checkout_dir_template = g_file_get_child (builder_context_get_state_dir (context),
                                            "tmp-checkout-XXXXXX");
  checkout_dir_path = g_file_get_path (checkout_dir_template);

  if (g_mkdtemp (checkout_dir_path) == NULL)
    {
      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Can't create temporary checkout directory");
      return FALSE;
    }

  checkout_dir = g_file_new_for_path (checkout_dir_path);

  if (!git (NULL, NULL, error,
            "clone", "-q", "--no-checkout", mirror_dir_path, checkout_dir_path, NULL))
    return FALSE;

  if (!git (checkout_dir, NULL, error, "checkout", "-q", "-f", revision, NULL))
    return FALSE;

  if (!git (checkout_dir, &submodule_status, error,
            "submodule", "status", NULL))
    return FALSE;

  if (submodule_status)
    {
      int i;
      g_auto(GStrv) lines = g_strsplit (submodule_status, "\n", -1);
      for (i = 0; lines[i] != NULL; i++)
        {
          g_autofree char *url = NULL;
          g_autofree char *option = NULL;
          g_autofree char *old = NULL;
          g_auto(GStrv) words = NULL;
          if (*lines[i] == 0)
            continue;
          words = g_strsplit (lines[i] + 1, " ", 3);

          option = g_strdup_printf ("submodule.%s.url", words[1]);
          if (!git (checkout_dir, &url, error,
                    "config", "-f", ".gitmodules", option, NULL))
            return FALSE;
          /* Trim trailing whitespace */
          g_strchomp (url);

          old = url;
          url = make_absolute (repo_location, old, error);
          if (url == NULL)
            return FALSE;

          if (!git_mirror_repo (url, update, words[0], context, error))
            return FALSE;
        }
    }

  if (!gs_shutil_rm_rf (checkout_dir, NULL, error))
    return FALSE;

  return TRUE;
}
static void
kms_pointer_detector_init (KmsPointerDetector * pointerdetector)
{
  pointerdetector->cvImage = NULL;
  int h_bins = 30, s_bins = 32;
  int hist_size[] = { h_bins, s_bins };
  float h_ranges[] = { 0, 180 };
  float s_ranges[] = { 0, 255 };
  float *ranges[] = { h_ranges, s_ranges };
  pointerdetector->histModel =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histModel);

  pointerdetector->histCompare =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histCompare);

  pointerdetector->histSetUp1 =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histSetUp1);

  pointerdetector->histSetUp2 =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histSetUp2);

  pointerdetector->histSetUpRef =
      cvCreateHist (2, hist_size, CV_HIST_ARRAY, ranges, 1);
  cvClearHist (pointerdetector->histSetUpRef);

  pointerdetector->upCornerFinalRect.x = 20;
  pointerdetector->upCornerFinalRect.y = 10;
  pointerdetector->downCornerFinalRect.x = 40;
  pointerdetector->downCornerFinalRect.y = 30;
  pointerdetector->upCornerRect1.x = 20;
  pointerdetector->upCornerRect1.y = 10;
  pointerdetector->downCornerRect1.x = 40;
  pointerdetector->downCornerRect1.y = 30;
  pointerdetector->upCornerRect2.x = 50;
  pointerdetector->upCornerRect2.y = 10;
  pointerdetector->downCornerRect2.x = 70;
  pointerdetector->downCornerRect2.y = 30;
  pointerdetector->upRightButtonCorner.x = 0;
  pointerdetector->upRightButtonCorner.y = 0;
  pointerdetector->downLeftButtonCorner.x = 0;
  pointerdetector->downLeftButtonCorner.y = 0;
  pointerdetector->windowScaleRef = 5;
  pointerdetector->numOfRegions = 150;
  pointerdetector->windowScale = pointerdetector->windowScaleRef;
  pointerdetector->iteration = 0;
  pointerdetector->state = START;
  pointerdetector->histRefCapturesCounter = 0;
  pointerdetector->secondHistCapturesCounter = 0;
  pointerdetector->trackinRectSize.width =
      abs (pointerdetector->upCornerRect1.x -
      pointerdetector->downCornerRect1.x);
  pointerdetector->trackinRectSize.height =
      abs (pointerdetector->upCornerRect1.y -
      pointerdetector->downCornerRect1.y);
  pointerdetector->colorRect1 = WHITE;
  pointerdetector->colorRect2 = WHITE;
  pointerdetector->show_debug_info = FALSE;
  pointerdetector->buttonsLayout = NULL;
  pointerdetector->buttonsLayoutList = NULL;
  pointerdetector->putMessage = TRUE;
  pointerdetector->show_windows_layout = TRUE;

  gchar d[] = TEMP_PATH;
  gchar *aux = g_mkdtemp (d);

  pointerdetector->images_dir = g_strdup (aux);
}
gboolean take_filesystem_ownership (const gchar *device,
                                    const gchar *fstype,
                                    uid_t caller_uid,
                                    gid_t caller_gid,
                                    gboolean recursive,
                                    GError **error)

{

  gchar *mountpoint = NULL;
  GError *local_error = NULL;
  gboolean unmount = FALSE;
  gboolean success = TRUE;

  mountpoint = bd_fs_get_mountpoint (device, &local_error);
  if (mountpoint == NULL)
    {
      if (local_error != NULL)
        {
          g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
                       "Error when getting mountpoint for %s: %s.",
                       device, local_error->message);
          g_clear_error (&local_error);
          success = FALSE;
          goto out;
        }
      else
        {
          /* device is not mounted, we need to mount it */
          mountpoint = g_mkdtemp (g_strdup (PACKAGE_LOCALSTATE_DIR "/run/udisks2/temp-mount-XXXXXX"));
          if (mountpoint == NULL)
            {
              g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
                           "Cannot create temporary mountpoint.");
              success = FALSE;
              goto out;
            }

          if (!bd_fs_mount (device, mountpoint, fstype, NULL, NULL, &local_error))
            {
              g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
                           "Cannot mount %s at %s: %s",
                           device, mountpoint, local_error->message);
              g_clear_error (&local_error);
              if (g_rmdir (mountpoint) != 0)
                  udisks_warning ("Error removing temporary mountpoint directory %s.", mountpoint);
              success = FALSE;
              goto out;
            }
          else
            unmount = TRUE;  // unmount during cleanup
        }
    }

  if (recursive)
    {
      if (!recursive_chown (mountpoint, caller_uid, caller_gid))
        {
            g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
                         "Cannot recursively chown %s to uid=%u and gid=%u: %m",
                         mountpoint, caller_uid, caller_gid);

          success = FALSE;
          goto out;
        }
    }
  else
    {
      if (chown (mountpoint, caller_uid, caller_gid) != 0)
        {
          g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
                       "Cannot chown %s to uid=%u and gid=%u: %m",
                       mountpoint, caller_uid, caller_gid);
          success = FALSE;
          goto out;
        }
    }

  if (chmod (mountpoint, 0700) != 0)
    {
      g_set_error (error, UDISKS_ERROR, UDISKS_ERROR_FAILED,
                   "Cannot chmod %s to mode 0700: %m",
                   mountpoint);
      success = FALSE;
      goto out;
    }

 out:
  if (unmount)
    {
      if (! bd_fs_unmount (mountpoint, FALSE, FALSE, NULL, &local_error))
        {
          udisks_warning ("Error unmounting temporary mountpoint %s: %s",
                          mountpoint, local_error->message);
          g_clear_error (&local_error);
        }
      if (g_rmdir (mountpoint) != 0)
          udisks_warning ("Error removing temporary mountpoint directory %s.", mountpoint);
    }

  g_free (mountpoint);

  return success;
}