Example #1
0
int main(int argc, char **argv)
{
    int ret;
    TestState ts = { 0 };

    ts.src_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
    ts.dst_tpm_path = g_dir_make_tmp("qemu-tpm-tis-swtpm-test.XXXXXX", NULL);
    ts.uri = g_strdup_printf("unix:%s/migsocket", ts.src_tpm_path);

    module_call_init(MODULE_INIT_QOM);
    g_test_init(&argc, &argv, NULL);

    qtest_add_data_func("/tpm/tis-swtpm/test", &ts, tpm_tis_swtpm_test);
    qtest_add_data_func("/tpm/tis-swtpm-migration/test", &ts,
                        tpm_tis_swtpm_migration_test);
    ret = g_test_run();

    g_rmdir(ts.dst_tpm_path);
    g_free(ts.dst_tpm_path);
    g_rmdir(ts.src_tpm_path);
    g_free(ts.src_tpm_path);
    g_free(ts.uri);

    return ret;
}
Example #2
0
static
void
test_inotify_common(
    TestInotify* test,
    gboolean (*init)(TestInotify* test),
    void (*deinit)(TestInotify* test))
{
    const int mask = IN_ALL_EVENTS | IN_ONLYDIR | IN_EXCL_UNLINK;

    test->ok = FALSE;
    test->dir1 = g_dir_make_tmp(TMP_DIR_TEMPLATE, NULL);
    test->dir2 = g_dir_make_tmp(TMP_DIR_TEMPLATE, NULL);
    test->watch1 = gutil_inotify_watch_new(test->dir1, mask);
    test->watch2 = gutil_inotify_watch_new(test->dir2, mask);

    GDEBUG("%s: directory 1: %s", test->name, test->dir1);
    GDEBUG("%s: directory 2: %s", test->name, test->dir2);

    /* Initialize the event loop */
    test->loop = g_main_loop_new(NULL, TRUE);
    if (!(test_opt.flags & TEST_FLAG_DEBUG)) {
        test->timeout_id = g_timeout_add_seconds(TEST_TIMEOUT,
            test_inotify_timeout, test);
    }

    if (init) {
        init(test);
    }

    /* Run the event loop */
    g_main_loop_run(test->loop);

    if (deinit) {
        deinit(test);
    }

    g_assert(test->ok);
    if (!(test_opt.flags & TEST_FLAG_DEBUG)) {
        g_assert(test->timeout_id);
        g_source_remove(test->timeout_id);
    }

    g_main_loop_unref(test->loop);
    gutil_inotify_watch_destroy(test->watch1);
    gutil_inotify_watch_destroy(test->watch2);
    remove(test->dir1);
    remove(test->dir2);
    g_free(test->dir1);
    g_free(test->dir2);
}
Example #3
0
static
void
test_inotify_basic(
    void)
{
    char* dir = g_dir_make_tmp(TMP_DIR_TEMPLATE, NULL);
    GUtilInotifyWatch* watch = gutil_inotify_watch_new(dir, IN_ALL_EVENTS);

    /* These have no effect, just testing NULL-telerance */
    g_assert(!gutil_inotify_watch_new(NULL, 0));
    g_assert(!gutil_inotify_watch_ref(NULL));
    gutil_inotify_watch_unref(NULL);
    gutil_inotify_watch_destroy(NULL);
    gutil_inotify_watch_remove_handler(NULL, 0);
    gutil_inotify_watch_remove_handler(watch, 0);

    g_assert(!gutil_inotify_watch_callback_new(NULL, 0, NULL, NULL));
    g_assert(!gutil_inotify_watch_add_handler(NULL, NULL, NULL));
    g_assert(!gutil_inotify_watch_add_handler(watch, NULL, NULL));

    gutil_inotify_watch_destroy(watch);

    /* Remove the directory and try to watch it. That should fail */
    remove(dir);
    g_assert(!gutil_inotify_watch_new(dir, IN_ALL_EVENTS));
    g_free(dir);
}
Example #4
0
static char *
copy_db (void)
{
  GFile *src, *dest;
  char *url, *path;
  GError *error = NULL;
  gboolean ret;

  db_dir_path = g_dir_make_tmp("test-gom-find-XXXXXXX", &error);
  g_assert(db_dir_path);
  g_assert_no_error(error);

  src = g_file_new_for_commandline_arg (DB);
  path = g_build_filename(db_dir_path, "gom-db-test.db", NULL);
  dest = g_file_new_for_path (path);
  g_free (path);

  ret = g_file_copy (src, dest, G_FILE_COPY_TARGET_DEFAULT_PERMS, NULL, NULL, NULL, &error);
  g_assert_no_error(error);
  g_assert (ret);
  g_object_unref (src);

  url = g_file_get_uri(dest);
  g_object_unref (dest);

  return url;
}
Example #5
0
static void
cache_up (GrlNetWc *self)
{
  SoupCache *cache;
  GrlNetWcPrivate *priv = self->priv;
  gchar *dir;

  GRL_DEBUG ("cache up");

  dir = g_dir_make_tmp ("grilo-plugin-cache-XXXXXX", NULL);
  if (!dir)
    return;

  cache = soup_cache_new (dir, SOUP_CACHE_SINGLE_USER);
  g_free (dir);

  soup_session_add_feature (priv->session,
                            SOUP_SESSION_FEATURE (cache));

  if (priv->cache_size) {
    soup_cache_set_max_size (cache, priv->cache_size * 1024 * 1024);
  }

  g_object_unref (cache);
}
Example #6
0
int main(int argc, char** argv)
{
    g_unsetenv("DBUS_SESSION_BUS_ADDRESS");
    gtk_test_init(&argc, &argv, 0);
    g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
    g_setenv("WEBKIT_INJECTED_BUNDLE_PATH", WEBKIT_INJECTED_BUNDLE_PATH, FALSE);
    g_setenv("LC_ALL", "C", TRUE);
    g_setenv("GIO_USE_VFS", "local", TRUE);
    g_setenv("GSETTINGS_BACKEND", "memory", TRUE);
    g_test_bug_base("https://bugs.webkit.org/");

    registerGResource();

    GOwnPtr<char> diskCacheTempDirectory(g_dir_make_tmp("WebKit2TestsDiskCache-XXXXXX", 0));
    g_assert(diskCacheTempDirectory.get());
    webkit_web_context_set_disk_cache_directory(webkit_web_context_get_default(), diskCacheTempDirectory.get());

    beforeAll();
    int returnValue = g_test_run();
    afterAll();

    removeNonEmptyDirectory(diskCacheTempDirectory.get());

    return returnValue;
}
Example #7
0
static void
ide_worker_manager_constructed (GObject *object)
{
  IdeWorkerManager *self = (IdeWorkerManager *)object;
  g_autofree gchar *guid = NULL;
  g_autofree gchar *address = NULL;
  GError *error = NULL;

  g_assert (IDE_IS_WORKER_MANAGER (self));

  G_OBJECT_CLASS (ide_worker_manager_parent_class)->constructed (object);

  if (g_unix_socket_address_abstract_names_supported ())
    {
      address = g_strdup_printf ("unix:abstract=/tmp/gnome-builder-%u", (int)getpid ());
    }
  else
    {
      g_autofree gchar *tmpdir = NULL;

      tmpdir = g_dir_make_tmp ("gnome-builder-worker-XXXXXX", NULL);

      if (tmpdir == NULL)
        {
          g_error ("Failed to determine temporary directory for DBus.");
          exit (EXIT_FAILURE);
        }

      address = g_strdup_printf ("unix:tmpdir=%s", tmpdir);
    }

  guid = g_dbus_generate_guid ();

  self->dbus_server = g_dbus_server_new_sync (address,
                                              G_DBUS_SERVER_FLAGS_NONE,
                                              guid,
                                              NULL,
                                              NULL,
                                              &error);

  if (error != NULL)
    {
      g_error ("%s", error->message);
      exit (EXIT_FAILURE);
    }

  g_signal_connect_object (self->dbus_server,
                           "new-connection",
                           G_CALLBACK (ide_worker_manager_new_connection_cb),
                           self,
                           G_CONNECT_SWAPPED);

  IDE_TRACE_MSG ("GDBusServer listening at %s", address);

  g_dbus_server_start (self->dbus_server);

  g_assert (g_dbus_server_is_active (self->dbus_server));
}
Example #8
0
int has_efi_directory(PedPartition* part)
{
    int is_busy = ped_partition_is_busy(part);

    GError* error = NULL;

    char* mount_point = NULL;
    char *path = ped_partition_get_path(part);

    if (!is_busy) {
        mount_point = g_dir_make_tmp("efi_detectorXXXXXX", &error);
        if (error != NULL) {
            g_warning("[%s] create efi_detector failed :%s\n", __func__,
                      error->message);
            g_error_free(error);
            error = NULL;
        }
        char* cmd = g_strdup_printf ("mount -t vfat %s %s", path, mount_point);
        g_spawn_command_line_sync (cmd, NULL, NULL, NULL, &error);
        g_free(cmd);
        if (error != NULL) {
            g_warning("[%s] Can't detect whether is $ESP, cmd: %s, error: %s",
                      __func__, cmd, error->message);
            g_error_free(error);
            error = NULL;
            return FALSE;
        }
    }

    if (mount_point == NULL) {
        mount_point = get_partition_mount_point(path);
    }
    g_free(path);

    char* esp_path = g_build_filename(mount_point, "EFI", NULL);
    int is_esp = g_file_test (esp_path, G_FILE_TEST_IS_DIR);
    g_free(esp_path);

    if (!is_busy) {
        char* cmd = g_strdup_printf ("umount -l %s", mount_point);
        g_spawn_command_line_sync (cmd, NULL, NULL, NULL, &error);
        g_free(cmd);
        if (error != NULL) {
            g_warning("[%s] Can't detect whether is $ESP, cmd: %s, error: %s",
                      __func__, cmd, error->message);
            g_error_free(error);
            g_free(mount_point);
            return is_esp;
        }

        //don't rm the dir if umount failed.
        g_rmdir(mount_point);
        g_free(mount_point);
    }

    return is_esp;
}
Example #9
0
static const char *fs_uae_temp_dir(void)
{
    static const char *path = NULL;
    if (path == NULL) {
        path = g_dir_make_tmp("fs-uae-TEMP-XXXXXX", NULL);
        fs_log("FS-UAE $TEMP = %s\n", path);
    }
    return path;
}
Example #10
0
static gboolean
test_buffer_path (void)
{
  gboolean         result = TRUE;
  gchar           *tmpdir = NULL;
  gchar           *buf_a_path = NULL;
  gchar           *buf_a_real_path = NULL;
  GeglBuffer      *buf_a = NULL;
  GeglTileBackend *backend_a = NULL;
  GeglRectangle    roi = {0, 0, 128, 128};

  tmpdir = g_dir_make_tmp ("test-backend-file-XXXXXX", NULL);
  g_return_val_if_fail (tmpdir, FALSE);

  buf_a_path = g_build_filename (tmpdir, "buf_a.gegl", NULL);

  buf_a = g_object_new (GEGL_TYPE_BUFFER,
                        "format", babl_format ("R'G'B'A u8"),
                        "path", buf_a_path,
                        "x", roi.x,
                        "y", roi.y,
                        "width", roi.width,
                        "height", roi.height,
                        NULL);

  g_object_get (buf_a,
                "path", &buf_a_real_path,
                "backend", &backend_a,
                NULL);

  if (!GEGL_IS_TILE_BACKEND_FILE (backend_a))
    {
      printf ("Buffer did not use the file backend.\n");
      result = FALSE;
    }

  if (g_strcmp0 (buf_a_path, buf_a_real_path))
    {
      printf ("Paths do not match:\n%s\n%s\n",
              buf_a_path,
              buf_a_real_path);
      result = FALSE;
    }

  g_object_unref (buf_a);
  g_object_unref (backend_a);
  g_free (buf_a_real_path);

  g_unlink (buf_a_path);
  g_remove (tmpdir);

  g_free (tmpdir);
  g_free (buf_a_path);

  return result;
}
Example #11
0
int main (int argc, char *argv[])
{
    ClientPool *pool;
    struct event *timeout;
    struct timeval tv;
    GList *l_files = NULL;
    CBData *cb;
    gchar *in_dir;

    log_level = LOG_debug;

    event_set_mem_functions (g_malloc, g_realloc, g_free);

    in_dir = g_dir_make_tmp (NULL, NULL);
    g_assert (in_dir);

    l_files = populate_file_list (100, l_files, in_dir);
    g_assert (l_files);

    
    
    app = app_create ();
    
    
    
    app->h_clients_freq = g_hash_table_new (g_direct_hash, g_direct_equal);
    app->l_files = l_files;
    // start server
    start_srv (app->evbase, in_dir);
    
    /*
    pool = client_pool_create (app, 12,
        http_client_create,
        http_client_destroy,
        http_client_set_on_released_cb,
        http_client_check_rediness
    );
    */

    cb = g_new (CBData, 1);
    cb->pool = pool;
    cb->l_files = l_files;
    
    timeout = evtimer_new (app->evbase, on_output_timer, cb);

    evutil_timerclear(&tv);
    tv.tv_sec = 0;
    tv.tv_usec = 500;
    event_add (timeout, &tv);

    event_base_dispatch (app->evbase);

    g_hash_table_foreach (app->h_clients_freq, (GHFunc)print_foreach, NULL);

    return 0;
}
Example #12
0
/* pass NULL to allow any mechanism */
static GDBusServer *
server_new_for_mechanism (const gchar *allowed_mechanism)
{
  gchar *addr;
  gchar *guid;
  GDBusServer *server;
  GDBusAuthObserver *auth_observer;
  GError *error;
  GDBusServerFlags flags;

  guid = g_dbus_generate_guid ();

#ifdef G_OS_UNIX
  if (g_unix_socket_address_abstract_names_supported ())
    {
      addr = g_strdup ("unix:tmpdir=/tmp/gdbus-test-");
    }
  else
    {
      gchar *tmpdir;
      tmpdir = g_dir_make_tmp ("gdbus-test-XXXXXX", NULL);
      addr = g_strdup_printf ("unix:tmpdir=%s", tmpdir);
      g_free (tmpdir);
    }
#else
  addr = g_strdup ("nonce-tcp:");
#endif

  auth_observer = g_dbus_auth_observer_new ();

  flags = G_DBUS_SERVER_FLAGS_NONE;
  if (g_strcmp0 (allowed_mechanism, "ANONYMOUS") == 0)
    flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS;

  error = NULL;
  server = g_dbus_server_new_sync (addr,
                                   flags,
                                   guid,
                                   auth_observer,
                                   NULL, /* cancellable */
                                   &error);
  g_assert_no_error (error);
  g_assert (server != NULL);

  g_signal_connect (auth_observer,
                    "allow-mechanism",
                    G_CALLBACK (server_on_allow_mechanism),
                    (gpointer) allowed_mechanism);

  g_free (addr);
  g_free (guid);
  g_object_unref (auth_observer);

  return server;
}
Example #13
0
static void
setup (Fixture       *fixture,
       gconstpointer  user_data)
{
  GError *error = NULL;

  fixture->tmp_dir = g_dir_make_tmp ("gio-test-file-monitor_XXXXXX", &error);
  g_assert_no_error (error);

  g_test_message ("Using temporary directory: %s", fixture->tmp_dir);
}
Example #14
0
static void set_fake_cookie_dir()
{
	char *ctx_dir = NULL;
	ctx_dir = g_dir_make_tmp(NULL, NULL);
	g_assert_nonnull(ctx_dir);
	g_test_queue_free(ctx_dir);

	g_test_queue_destroy((GDestroyNotify) rm_rf_tmp, ctx_dir);
	g_test_queue_destroy((GDestroyNotify) set_cookie_dir, SC_COOKIE_DIR);

	set_cookie_dir(ctx_dir);
}
Example #15
0
static void
temp_dbus_keyrings_setup (void)
{
  GError *error = NULL;

  g_assert (temp_dbus_keyrings_dir == NULL);
  temp_dbus_keyrings_dir = g_dir_make_tmp ("gdbus-test-dbus-keyrings-XXXXXX", &error);
  g_assert_no_error (error);
  g_assert (temp_dbus_keyrings_dir != NULL);
  g_setenv ("G_DBUS_COOKIE_SHA1_KEYRING_DIR", temp_dbus_keyrings_dir, TRUE);
  g_setenv ("G_DBUS_COOKIE_SHA1_KEYRING_DIR_IGNORE_PERMISSION", "1", TRUE);
}
void beforeAll()
{
    // Start a soup server for testing.
    kServer = new WebKitTestServer();
    kServer->run(serverCallback);

    kTempDirectory = g_dir_make_tmp("WebKit2Tests-XXXXXX", 0);
    g_assert(kTempDirectory);

    // Add tests to the suite.
    FaviconDatabaseTest::add("WebKitFaviconDatabase", "favicon-database-test", testFaviconDatabase);
}
Example #17
0
// create max_files and fill with random data
// return list of {file name, content md5}
static GList *populate_file_list (gint max_files, GList *l_files, gchar *in_dir)
{
    gint i;
    gchar *out_dir;
    GError *error = NULL;
    FileData *fdata;
    gchar *name;
    FILE *f;

    out_dir = g_dir_make_tmp (NULL, &error);
    g_assert (out_dir);


    LOG_debug (POOL_TEST, "In dir: %s   Out dir: %s", in_dir, out_dir);

    for (i = 0; i < max_files; i++) {
        char *bytes;
        size_t bytes_len;

        fdata = g_new0 (FileData, 1);
        fdata->checked = FALSE;
        bytes_len = g_random_int_range (100000, 1000000);
        bytes = g_malloc (bytes_len + 1);
        RAND_pseudo_bytes ((unsigned char *)bytes, bytes_len);
        *(bytes + bytes_len) = '\0';
        
        name = get_random_string (15, TRUE);
        fdata->in_name = g_strdup_printf ("%s/%s", in_dir, name);
        f = fopen (fdata->in_name, "w");
        fwrite (bytes, 1, bytes_len + 1, f);
        fclose (f);

        fdata->out_name = g_strdup_printf ("%s/%s", out_dir, name);
        get_md5_sum (bytes, bytes_len + 1, &fdata->md5, NULL);
        
        fdata->fout = fopen (fdata->out_name, "w");
        g_assert (fdata->fout);

        fdata->url = g_strdup_printf ("http://127.0.0.1:8011/%s", name);
        g_assert (fdata->url);
        
        LOG_debug (POOL_TEST, "%s -> %s, size: %u", fdata->in_name, fdata->md5, bytes_len);
        
        l_files = g_list_append (l_files, fdata);
    }

    return l_files;
}
Example #18
0
static void test_fetch_git(void) {
    Recipe recipe = {"1","1","1","RHEL-6.0","RedHatEnterpriseLinux6","Server","x86_64",NULL,NULL,NULL};
    Task task = {
        "456",
        &recipe,
        soup_uri_new("http://localhost:8000/recipes/123/tasks/456/"),
        "/distribution/install",
        g_dir_make_tmp("restraint_test_task_XXXXXX", NULL),
        TASK_FETCH_UNPACK,
        { .url = soup_uri_new("git://localhost/repo1?master#restraint/sanity/fetch_git") },
        NULL,
        NULL,
        FALSE,
        FALSE,
        NULL,
        FALSE,
        NULL,
        0,
    };
    restraint_task_run(&task);

    // assert it's on disk
    GFile *base = g_file_new_for_path(task.path);
    GFile *file = g_file_get_child(base, "Makefile");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "PURPOSE");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "metadata");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    file = g_file_get_child(base, "runtest.sh");
    g_assert(g_file_query_exists (file, NULL) != FALSE);
    g_object_unref(file);
    g_object_unref(base);

    // assert this is not rhts_compat task
    g_assert(task.rhts_compat == FALSE);

    soup_uri_free(task.task_uri);
    g_free(task.path);
    g_strfreev(task.entry_point);
    g_list_free_full(task.dependencies, (GDestroyNotify) g_free);
    soup_uri_free(task.fetch.url);
}
Example #19
0
} END_TEST

START_TEST(test_cc_oci_create_pidfile) {
	gchar *tmpdir = g_dir_make_tmp (NULL, NULL);
	gchar *tmpfile = g_build_path ("/", tmpdir, "foo.pid", NULL);
	gchar *contents;
	gboolean ret;

	ck_assert (! cc_oci_create_pidfile (NULL, 0));
	ck_assert (! cc_oci_create_pidfile ("", 0));
	ck_assert (! cc_oci_create_pidfile (NULL, -1));
	ck_assert (! cc_oci_create_pidfile ("", -1));

	ck_assert (! cc_oci_create_pidfile ("foo", 0));
	ck_assert (! cc_oci_create_pidfile ("foo", -1));

	ck_assert (! cc_oci_create_pidfile ("no-leading-slash", 123));
	ck_assert (! cc_oci_create_pidfile (tmpfile, -1));

	ck_assert (cc_oci_create_pidfile (tmpfile, 123));

	/* check contents */
	ret = g_file_get_contents (tmpfile, &contents, NULL, NULL);
	ck_assert (ret);
	ck_assert (! g_strcmp0 (contents, "123"));
	g_free (contents);

	/* Ensure existing file overwritten */
	ck_assert (cc_oci_create_pidfile (tmpfile, 456));

	/* check contents */
	ret = g_file_get_contents (tmpfile, &contents, NULL, NULL);
	ck_assert (ret);
	ck_assert (! g_strcmp0 (contents, "456"));
	g_free (contents);

	ck_assert (! g_remove (tmpfile));
	ck_assert (! g_remove (tmpdir));

	g_free (tmpfile);
	g_free (tmpdir);

} END_TEST
Example #20
0
static void test_fetch_git_negative(void) {
    // test-data/git-remote/repo2 has uploadarch=false in .git/config
    ExpectHttpServer *expect_http = expect_http_start();
    ExpectHttpRequest request = { "POST", "/recipes/123/tasks/456/status",
            "status=Aborted&message=Error+from+remote+git+daemon%3A+"
            "access+denied+or+repository+not+exported%3A+%2Frepo2",
            204 };
    expect_http_add_request(expect_http, &request);

    Recipe recipe = {"1","1","1","RHEL-6.0","RedHatEnterpriseLinux6","Server","x86_64",NULL,NULL,NULL};
    Task task = {
        "456",
        &recipe,
        soup_uri_new("http://localhost:8000/recipes/123/tasks/456/"),
        "/distribution/install",
        g_dir_make_tmp("restraint_test_task_XXXXXX", NULL),
        TASK_FETCH_UNPACK,
        { .url = soup_uri_new("git://localhost/repo2?master#restraint/sanity/fetch_git") },
        NULL,
        NULL,
        FALSE,
        FALSE,
        NULL,
        FALSE,
        NULL,
        0,
    };
    restraint_task_run(&task);

    expect_http_finish(expect_http);
    GFile *base = g_file_new_for_path(task.path);
    GFile *file = g_file_get_child(base, "Makefile");
    g_assert(g_file_query_exists (file, NULL) == FALSE);
    g_object_unref(file);
    g_object_unref(base);

    soup_uri_free(task.task_uri);
    g_free(task.path);
    soup_uri_free(task.fetch.url);
}
Example #21
0
gchar *
gedit_utils_set_direct_save_filename (GdkDragContext *context)
{
	gchar *uri;
	gchar *filename;

	uri = NULL;
	filename = get_direct_save_filename (context);

	if (filename != NULL)
	{
		gchar *tempdir;
		gchar *path;

		tempdir = g_dir_make_tmp ("gedit-drop-XXXXXX", NULL);
		if (tempdir == NULL)
		{
			tempdir = g_strdup (g_get_tmp_dir ());
		}

		path = g_build_filename (tempdir,
					filename,
					NULL);

		uri = g_filename_to_uri (path, NULL, NULL);

		/* Change the property */
		gdk_property_change (gdk_drag_context_get_source_window (context),
				     gdk_atom_intern ("XdndDirectSave0", FALSE),
				     gdk_atom_intern ("text/plain", FALSE), 8,
				     GDK_PROP_MODE_REPLACE, (const guchar *) uri,
				     strlen (uri));

		g_free (tempdir);
		g_free (path);
		g_free (filename);
	}

	return uri;
}
Example #22
0
// Use temporary directory for namespace groups.
//
// The directory is automatically reset to the real value at the end of the
// test.
static const char *sc_test_use_fake_ns_dir()
{
	char *ns_dir = NULL;
	if (g_test_subprocess()) {
		// Check if the environment variable is set. If so then someone is already
		// managing the temporary directory and we should not create a new one.
		ns_dir = getenv("SNAP_CONFINE_NS_DIR");
		g_assert_nonnull(ns_dir);
	} else {
		ns_dir = g_dir_make_tmp(NULL, NULL);
		g_assert_nonnull(ns_dir);
		g_test_queue_free(ns_dir);
		g_assert_cmpint(setenv("SNAP_CONFINE_NS_DIR", ns_dir, 0), ==,
				0);
		g_test_queue_destroy((GDestroyNotify) unsetenv,
				     "SNAP_CONFINE_NS_DIR");
		g_test_queue_destroy((GDestroyNotify) rm_rf_tmp, ns_dir);
	}
	g_test_queue_destroy((GDestroyNotify) sc_set_ns_dir, SC_NS_DIR);
	sc_set_ns_dir(ns_dir);
	return ns_dir;
}
Example #23
0
gboolean
synce_app_man_install(IRAPISession *session, const gchar *filepath, SynceAppManBusyFunc busy_func, gpointer busy_data, GError **error)
{
  gchar *install_path = NULL;
  SYSTEM_INFO system;
  gboolean result;
  WCHAR* wide_program = NULL;
  PROCESS_INFORMATION info;
  BOOL rapi_res;
  HRESULT hr;
  DWORD last_error;
  gchar *tmpdir = NULL;
  GList *cab_list = NULL;

  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);

  if (busy_func)
    (*busy_func)(busy_data);

  memset(&system, 0, sizeof(system));
  IRAPISession_CeGetSystemInfo(session, &system);

#if GLIB_CHECK_VERSION(2,30,0)
  tmpdir = g_dir_make_tmp("sti_XXXXXX", error);
  if (!tmpdir) {
    g_prefix_error(error, _("Failed to create temp directory '%s': "), tmpdir);
    result = FALSE;
    goto exit;
  }
  g_chmod(tmpdir, 0700);
#else
  tmpdir = tempnam(g_get_tmp_dir(), "sti");
  if (g_mkdir(tmpdir, 0700) != 0) {
    g_set_error(error,
		G_FILE_ERROR,
		g_file_error_from_errno(errno),
		_("Failed to create temp directory '%s': %s"),
                tmpdir,
		g_strerror(errno));
    result = FALSE;
    goto exit;
  }
#endif

  cab_list = extract_with_orange(filepath, tmpdir, system.dwProcessorType);
  if (!cab_list) {
    g_set_error(error,
		SYNCE_APP_MAN_ERROR,
		SYNCE_APP_MAN_ERROR_INVALID_INSTALL_FILE,
		_("No CAB files found"));
    return FALSE;
  }

  /* Do some install things */

  install_path = get_install_dir(session, error);
  if (!install_path) {
    result = FALSE;
    goto exit;
  }

  GList *tmplist = g_list_first(cab_list);
  while(tmplist) {
    gchar *cabname = tmplist->data;
    g_debug("%s: copying file %s to device", G_STRFUNC, cabname);

    if (!copy_to_device(session, cabname, install_path, busy_func, busy_data, error)) {
      result = FALSE;
      goto exit;
    }

    tmplist = g_list_next(tmplist);
  }

  wide_program = wstr_from_utf8("wceload.exe");
  memset(&info, 0, sizeof(info));

  rapi_res = IRAPISession_CeCreateProcess(session, wide_program, NULL, 
			     NULL, NULL, false, 0,
			     NULL, NULL, NULL, 
			     &info);
  wstr_free_string(wide_program);
  IRAPISession_CeCloseHandle(session, info.hProcess);
  IRAPISession_CeCloseHandle(session, info.hThread);

  if (!rapi_res) {
    if (FAILED(hr = IRAPISession_CeRapiGetError(session))) {
      g_set_error(error,
		  SYNCE_APP_MAN_ERROR,
		  SYNCE_APP_MAN_ERROR_RAPI_TERM,
		  _("Failed to execute installer: %s"),
		  synce_strerror(hr));
      result = FALSE;
      goto exit;
    }

    last_error = IRAPISession_CeGetLastError(session);
    g_set_error(error,
		SYNCE_APP_MAN_ERROR,
		SYNCE_APP_MAN_ERROR_RAPI,
		_("Failed to execute installer: %s"),
		synce_strerror(last_error));
    result = FALSE;
    goto exit;
  }

  g_debug("%s: successfully installed %s on device", G_STRFUNC, filepath);
  result = TRUE;

exit:

  tmplist = g_list_first(cab_list);
  while(tmplist)
    {
      g_unlink((gchar *)(tmplist->data));
      tmplist = g_list_next(tmplist);
    }

  if (tmpdir) {
          g_rmdir(tmpdir);
          g_free(tmpdir);
  }

  return result;
}
Example #24
0
/**
 * Tests creation, getting info from and destruction of
 * program wrapper objects.
 * */
static void create_info_destroy_test() {

	/* Test variables. */
	CCLContext* ctx = NULL;
	CCLProgram* prg = NULL;
	CCLProgram* prg2 = NULL;
	CCLKernel* krnl = NULL;
	CCLWrapperInfo* info = NULL;
	CCLDevice* d = NULL;
	CCLQueue* cq = NULL;
	size_t gws;
	size_t lws;
	cl_uint a_h[CCL_TEST_PROGRAM_BUF_SIZE];
	cl_uint b_h[CCL_TEST_PROGRAM_BUF_SIZE];
	cl_uint c_h[CCL_TEST_PROGRAM_BUF_SIZE];
	cl_uint d_h ;
	CCLBuffer* a_w;
	CCLBuffer* b_w;
	CCLBuffer* c_w;
	CCLEvent* evt_w1;
	CCLEvent* evt_w2;
	CCLEvent* evt_kr;
	CCLEvent* evt_r1;
	CCLEventWaitList ewl = NULL;
	GError* err = NULL;
	gchar* tmp_dir_name;
	gchar* tmp_file_prefix;

	/* Get a temp. dir. */
	tmp_dir_name = g_dir_make_tmp("test_program_XXXXXX", &err);
	g_assert_no_error(err);

	/* Get a temp file prefix. */
	tmp_file_prefix = g_strdup_printf("%s%c%s",
		tmp_dir_name, G_DIR_SEPARATOR, CCL_TEST_PROGRAM_SUM_FILENAME);

	/* Create a temporary kernel file. */
	g_file_set_contents(
		tmp_file_prefix, CCL_TEST_PROGRAM_SUM_CONTENT, -1, &err);
	g_assert_no_error(err);

	/* Create a context with devices from first available platform. */
	ctx = ccl_test_context_new(&err);
	g_assert_no_error(err);

	/* Create a new program from kernel file. */
	prg = ccl_program_new_from_source_file(
		ctx, tmp_file_prefix, &err);
	g_assert_no_error(err);

	ccl_program_destroy(prg);

	const char* file_pref = (const char*) tmp_file_prefix;
	prg = ccl_program_new_from_source_files(ctx, 1, &file_pref, &err);
	g_assert_no_error(err);

	g_free(tmp_file_prefix);

	/* Get some program info, compare it with expected info. */
	info = ccl_program_get_info(prg, CL_PROGRAM_CONTEXT, &err);
	g_assert_no_error(err);
	g_assert(*((cl_context*) info->value) == ccl_context_unwrap(ctx));

	/* Get number of devices from program info, check that this is the
	 * same value as the number of devices in context. */
	info = ccl_program_get_info(prg, CL_PROGRAM_NUM_DEVICES, &err);
	g_assert_no_error(err);
	g_assert_cmpuint(*((cl_uint*) info->value),
		==, ccl_context_get_num_devices(ctx, &err));
	g_assert_no_error(err);

	/* Get program source from program info, check that it is the
	 * same as the passed source. */
	info = ccl_program_get_info(prg, CL_PROGRAM_SOURCE, &err);
	g_assert_no_error(err);
	g_assert_cmpstr((char*) info->value,
		==, CCL_TEST_PROGRAM_SUM_CONTENT);

	/* Get first device in context (and in program). */
	d = ccl_context_get_device(ctx, 0, &err);
	g_assert_no_error(err);

	/* Check that no build was performed yet. */
	info = ccl_program_get_build_info(
		prg, d, CL_PROGRAM_BUILD_STATUS, &err);
	g_assert_no_error(err);
	g_assert_cmpint(*((cl_build_status*) info->value), ==, CL_BUILD_NONE);

	/* **** BUILD PROGRAM **** */
	ccl_program_build(prg, NULL, &err);
	g_assert_no_error(err);

	/* Get some program build info, compare it with expected values. */
	info = ccl_program_get_build_info(
		prg, d, CL_PROGRAM_BUILD_STATUS, &err);
	g_assert_no_error(err);
	g_assert((*((cl_build_status*) info->value) == CL_BUILD_SUCCESS)
		|| (*((cl_build_status*) info->value) == CL_BUILD_IN_PROGRESS));

	/* Get the build log, check that no error occurs. */
	info = ccl_program_get_build_info(prg, d, CL_PROGRAM_BUILD_LOG, &err);
	g_assert_no_error(err);

	/* Get kernel wrapper object. */
	krnl = ccl_program_get_kernel(
		prg, CCL_TEST_PROGRAM_SUM, &err);
	g_assert_no_error(err);

	/* Get some kernel info, compare it with expected info. */

	/* Get kernel function name from kernel info, compare it with the
	 * expected value. */
	info = ccl_kernel_get_info(krnl, CL_KERNEL_FUNCTION_NAME, &err);
	g_assert_no_error(err);
	g_assert_cmpstr(
		(gchar*) info->value, ==, CCL_TEST_PROGRAM_SUM);

	/* Check if the kernel context is the same as the initial context
	 * and the program context. */
	info = ccl_kernel_get_info(krnl, CL_KERNEL_CONTEXT, &err);
	g_assert_no_error(err);
	g_assert(*((cl_context*) info->value) == ccl_context_unwrap(ctx));

	info = ccl_kernel_get_info(krnl, CL_KERNEL_PROGRAM, &err);
	g_assert_no_error(err);
	g_assert(*((cl_program*) info->value) == ccl_program_unwrap(prg));

#ifndef OPENCL_STUB
#ifdef CL_VERSION_1_2

	cl_kernel_arg_address_qualifier kaaq;
	char* kernel_arg_type_name;
	char* kernel_arg_name;
	cl_uint ocl_ver;

	/* Get OpenCL version of program's underlying platform. */
	ocl_ver = ccl_program_get_opencl_version(prg, &err);
	g_assert_no_error(err);

	/* If platform supports kernel argument queries, get kernel argument
	 * information and compare it with expected info. */
	if (ocl_ver >= 120) {

		/* First kernel argument. */
		kaaq = ccl_kernel_get_arg_info_scalar(krnl, 0,
				CL_KERNEL_ARG_ADDRESS_QUALIFIER,
				cl_kernel_arg_address_qualifier, &err);
		g_assert((err == NULL) || (err->code == CCL_ERROR_INFO_UNAVAILABLE_OCL));
		if (err == NULL) {
			g_assert_cmphex(kaaq, ==, CL_KERNEL_ARG_ADDRESS_GLOBAL);
		} else {
Example #25
0
static void pk_backend_refresh_cache_thread(PkBackendJob *job, GVariant *params, gpointer user_data) {
	gchar *tmp_dir_name, *db_err, *path = NULL;
	gint ret;
	gboolean force;
	GSList *file_list = NULL, *l;
	GFile *db_file = NULL;
	GFileInfo *file_info = NULL;
	GError *err = NULL;
	sqlite3_stmt *stmt = NULL;
	PkBackendKatjaJobData *job_data = pk_backend_job_get_user_data(job);

	pk_backend_job_set_status(job, PK_STATUS_ENUM_DOWNLOAD_CHANGELOG);

	/* Create temporary directory */
	tmp_dir_name = g_dir_make_tmp("PackageKit.XXXXXX", &err);
	if (!tmp_dir_name) {
		pk_backend_job_error_code(job, PK_ERROR_ENUM_INTERNAL_ERROR, "%s", err->message);
		g_error_free(err);
		pk_backend_job_finished(job);
		return;
	}

	g_variant_get(params, "(b)", &force);

	/* Force the complete cache refresh if the read configuration file is newer than the metadata cache */
	if (!force) {
		path = g_build_filename(LOCALSTATEDIR, "cache", "PackageKit", "metadata", "metadata.db", NULL);
		db_file = g_file_new_for_path(path);
		file_info = g_file_query_info(db_file, "time::modified-usec", G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, &err);
		if (err) {
			pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_CACHE, "%s: %s", path, err->message);
			g_error_free(err);
			goto out;
		}
		ret = sqlite3_prepare_v2(job_data->db,
								 "SELECT value FROM cache_info WHERE key LIKE 'last_modification'",
								 -1,
								 &stmt,
								 NULL);
		if ((ret != SQLITE_OK) || ((ret = sqlite3_step(stmt)) != SQLITE_ROW)) {
			pk_backend_job_error_code(job, PK_ERROR_ENUM_NO_CACHE, "%s: %s", path, sqlite3_errstr(ret));
			goto out;
		}
		if ((guint32) sqlite3_column_int(stmt, 0) > g_file_info_get_attribute_uint32(file_info, "time::modified-usec"))
			force = TRUE;
	}

	if (force) { /* It should empty all tables */
		if (sqlite3_exec(job_data->db, "DELETE FROM repos", NULL, 0, &db_err) != SQLITE_OK) {
			pk_backend_job_error_code(job, PK_ERROR_ENUM_INTERNAL_ERROR, "%s", db_err);
			sqlite3_free(db_err);
			goto out;
		}
	}

	for (l = repos; l; l = g_slist_next(l))	/* Get list of files that should be downloaded */
		file_list = g_slist_concat(file_list, katja_pkgtools_collect_cache_info(l->data, tmp_dir_name));

	/* Download repository */
	pk_backend_job_set_status(job, PK_STATUS_ENUM_DOWNLOAD_REPOSITORY);

	for (l = file_list; l; l = g_slist_next(l))
		katja_get_file(&job_data->curl, ((gchar **)l->data)[0], ((gchar **)l->data)[1]);
	g_slist_free_full(file_list, (GDestroyNotify)g_strfreev);

	/* Refresh cache */
	pk_backend_job_set_status(job, PK_STATUS_ENUM_REFRESH_CACHE);

	for (l = repos; l; l = g_slist_next(l))
		katja_pkgtools_generate_cache(l->data, job, tmp_dir_name);

out:
	sqlite3_finalize(stmt);
	if (file_info)
		g_object_unref(file_info);
	if (db_file)
		g_object_unref(db_file);
	g_free(path);

	pk_directory_remove_contents(tmp_dir_name);
	g_rmdir(tmp_dir_name);
	g_free(tmp_dir_name);
	pk_backend_job_finished(job);
}
Example #26
0
static GSubprocess *
gb_beautifier_process_create_for_clang_format (GbBeautifierWorkbenchAddin *self,
                                               ProcessState               *state,
                                               GError                     *error)
{
  g_autoptr(GSubprocessLauncher) launcher = NULL;
  GSubprocess *subprocess = NULL;
  GPtrArray *args;
  gchar *config_path;
  gchar *src_path;
  g_autofree gchar *tmp_workdir = NULL;
  g_autofree gchar *tmp_config_path = NULL;
  g_autofree gchar *tmp_src_path = NULL;

  g_assert (GB_IS_BEAUTIFIER_WORKBENCH_ADDIN (self));
  g_assert (state != NULL);

  config_path = g_file_get_path (state->config_file);
  src_path = g_file_get_path (state->src_file);

  g_assert (!ide_str_empty0 (config_path));
  g_assert (!ide_str_empty0 (src_path));
  g_assert (!ide_str_empty0 (state->lang_id));

  if (NULL == (tmp_workdir = g_dir_make_tmp ("gnome-builder-beautify-XXXXXX",
                                             &error)))
    return NULL;

  state->tmp_workdir_file = g_file_new_for_path (tmp_workdir);
  tmp_config_path = g_build_filename (tmp_workdir,
                                      ".clang-format",
                                      NULL);
  state->tmp_config_file = g_file_new_for_path (tmp_config_path);
  if (!g_file_copy (state->config_file,
                    state->tmp_config_file,
                    G_FILE_COPY_OVERWRITE,
                    NULL, NULL, NULL,
                    &error))
    return NULL;

  tmp_src_path = g_build_filename (tmp_workdir,
                                   "src_file",
                                   NULL);
  state->tmp_src_file = g_file_new_for_path (tmp_src_path);
  if (!g_file_copy (state->src_file,
                    state->tmp_src_file,
                    G_FILE_COPY_OVERWRITE,
                    NULL, NULL, NULL,
                    &error))
    return NULL;

  args = g_ptr_array_new ();
  g_ptr_array_add (args, "clang-format");
  g_ptr_array_add (args, "-style=file");
  g_ptr_array_add (args, tmp_src_path);
  g_ptr_array_add (args, NULL);

  launcher = g_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_PIPE);
  g_subprocess_launcher_set_cwd (launcher, tmp_workdir);
  subprocess = g_subprocess_launcher_spawnv (launcher,
                                             (const gchar * const *)args->pdata,
                                             &error);

  g_ptr_array_free (args, TRUE);
  return subprocess;
}
Example #27
0
} END_TEST

START_TEST(test_cc_oci_state_file_create) {
	struct cc_oci_config config = { { 0 } };
	const gchar *timestamp = "foo";
        struct oci_cfg_annotation* a = NULL;
	struct cc_oci_mount *m = NULL;
	g_autofree gchar *tmpdir = g_dir_make_tmp (NULL, NULL);
	gboolean ret;

	ck_assert(! cc_oci_state_file_create (NULL, NULL));

	/* Needs:
	 *
	 * - comms_path
	 * - procsock_path
	 * - optarg_bundle_path
	 * - optarg_container_id
	 * - runtime_path
	 *
	 */
	ck_assert(! cc_oci_state_file_create (&config, NULL));
	ck_assert(! cc_oci_state_file_create (&config, timestamp));

	config.optarg_container_id = "";

	ck_assert(! cc_oci_state_file_create (&config, NULL));
	ck_assert(! cc_oci_state_file_create (&config, timestamp));

	config.optarg_container_id = "foo";

	ck_assert(! cc_oci_state_file_create (&config, NULL));
	ck_assert(! cc_oci_state_file_create (&config, timestamp));

	config.bundle_path = g_strdup ("/tmp/bundle");

	ck_assert(! cc_oci_state_file_create (&config, NULL));
	ck_assert(! cc_oci_state_file_create (&config, timestamp));

	config.root_dir = g_strdup (tmpdir);
	ck_assert (config.root_dir);

	ck_assert (cc_oci_runtime_dir_setup (&config));

	ck_assert(! cc_oci_state_file_create (&config, NULL));
	ck_assert(! cc_oci_state_file_create (&config, timestamp));

	g_snprintf(config.state.comms_path, PATH_MAX, "/tmp");
	g_snprintf(config.state.procsock_path, PATH_MAX, "/tmp");

	ck_assert(! cc_oci_state_file_create (&config, NULL));

        a = g_new0(struct oci_cfg_annotation, 1);
        a->key = g_strdup("key1");
        a->value = g_strdup("val1");

        config.oci.annotations = g_slist_append(config.oci.annotations, a);

	/* config->vm not set */
	ck_assert(! cc_oci_state_file_create (&config, timestamp));

	config.vm = g_malloc0 (sizeof(struct cc_oci_vm_cfg));
	ck_assert (config.vm);

	g_strlcpy (config.vm->hypervisor_path, "hypervisor-path",
			sizeof (config.vm->hypervisor_path));

	g_strlcpy (config.vm->image_path, "image-path",
			sizeof (config.vm->image_path));

	g_strlcpy (config.vm->kernel_path, "kernel-path",
			sizeof (config.vm->kernel_path));

	g_strlcpy (config.vm->workload_path, "workload-path",
			sizeof (config.vm->workload_path));

	config.vm->kernel_params = g_strdup ("kernel params");

	/* All required elements now set */
	m = g_new0(struct cc_oci_mount, 1);
	g_snprintf(m->dest, sizeof(m->dest), "/tmp/tmp/tmp");
	m->directory_created = g_strdup("/tmp/tmp/");
	m->ignore_mount = true;
	config.oci.mounts = g_slist_append(config.oci.mounts, m);

	ck_assert (cc_oci_state_file_create (&config, timestamp));

	ret = g_file_test (config.state.state_file_path,
			G_FILE_TEST_EXISTS);
	ck_assert (ret);

	ck_assert (! g_remove (config.state.state_file_path));
	ck_assert (! g_remove (config.state.runtime_path));
	ck_assert (! g_remove (tmpdir));

	g_snprintf(config.state.runtime_path, PATH_MAX, "/abc/xyz/123");
	ck_assert(!cc_oci_state_file_create (&config, timestamp));

	/* clean up */
	cc_oci_config_free (&config);
} END_TEST
Example #28
0
static void
prepare_dbus_daemon_working_directory (GFile **test_program_working_directory_out, GFile **dbus_daemon_working_directory_out,
                                       GFile **config_file_out, GError **error)
{
	gchar *tmp_dir_path, *config_file;
	gsize config_file_length;
	GFile *tmp_dir_file = NULL, *tmp_dir_file_test_program = NULL, *tmp_dir_file_daemon = NULL, *tmp_dir_file_daemon_config = NULL;
	GError *child_error = NULL;

	/* Output. */
	*test_program_working_directory_out = NULL;
	*dbus_daemon_working_directory_out = NULL;
	*config_file_out = NULL;

	/* Check if the user's provided a config file. */
	if (dbus_daemon_config_file_path != NULL) {
		tmp_dir_file_daemon_config = g_file_new_for_commandline_arg (dbus_daemon_config_file_path);

		/* Check for existence; if the file doesn't exist, return an error. Note that subsequent code still needs to be able to handle
		 * the file not existing/dbus-daemon dying because of it. */
		if (g_file_query_exists (tmp_dir_file_daemon_config, NULL) == FALSE) {
			g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
			             _("The dbus-daemon configuration file specified with --dbus-daemon-config-file couldn’t be found."));

			g_object_unref (tmp_dir_file_daemon_config);

			return;
		}

		/* If the file exists, take its parent directory as the working directory and return. */
		tmp_dir_file_daemon = g_file_get_parent (tmp_dir_file_daemon_config);

		*test_program_working_directory_out = g_object_ref (tmp_dir_file_daemon);
		*dbus_daemon_working_directory_out = g_object_ref (tmp_dir_file_daemon);
		*config_file_out = tmp_dir_file_daemon_config;

		g_object_unref (tmp_dir_file_daemon);

		return;
	}

	/* Set up a temporary runtime directory for the dbus-daemon. */
	tmp_dir_path = g_dir_make_tmp ("bendy-bus_XXXXXX", &child_error);

	if (child_error != NULL) {
		goto error;
	}

	g_debug ("Using working directory: %s", tmp_dir_path);

	tmp_dir_file = g_file_new_for_path (tmp_dir_path);
	g_free (tmp_dir_path);

	/* Make a subdirectory for the test program. */
	tmp_dir_file_test_program = g_file_get_child (tmp_dir_file, "test-program");

	g_file_make_directory (tmp_dir_file_test_program, NULL, &child_error);

	if (child_error != NULL) {
		goto error;
	}

	/* Make a subdirectory for the dbus-daemon. */
	tmp_dir_file_daemon = g_file_get_child (tmp_dir_file, "dbus-daemon");

	g_file_make_directory (tmp_dir_file_daemon, NULL, &child_error);

	if (child_error != NULL) {
		goto error;
	}

	/* Create the default config.xml file. */
	tmp_dir_file_daemon_config = g_file_get_child (tmp_dir_file_daemon, "config.xml");

	config_file = build_config_file (tmp_dir_file_daemon, &config_file_length, system_bus);
	g_file_replace_contents (tmp_dir_file_daemon_config, config_file, config_file_length, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL,
	                         NULL, &child_error);
	g_free (config_file);

	if (child_error != NULL) {
		goto error;
	}

	/* Success! */
	*test_program_working_directory_out = tmp_dir_file_test_program;
	*dbus_daemon_working_directory_out = tmp_dir_file_daemon;
	*config_file_out = tmp_dir_file_daemon_config;

	return;

error:
	g_propagate_error (error, child_error);

	if (tmp_dir_file_daemon_config != NULL) {
		/* Hide the evidence. */
		g_file_delete (tmp_dir_file_daemon_config, NULL, NULL);
		g_object_unref (tmp_dir_file_daemon_config);
	}

	if (tmp_dir_file_daemon != NULL) {
		g_file_delete (tmp_dir_file_daemon, NULL, NULL);
		g_object_unref (tmp_dir_file_daemon);
	}

	if (tmp_dir_file_test_program != NULL) {
		g_file_delete (tmp_dir_file_test_program, NULL, NULL);
		g_object_unref (tmp_dir_file_test_program);
	}

	if (tmp_dir_file != NULL) {
		g_file_delete (tmp_dir_file, NULL, NULL);
		g_object_unref (tmp_dir_file);
	}
}
Example #29
0
///startet die Umwandlung/sortierung von odt zu pdf
void button_work_clicked(GtkWidget *widget, gpointer data){
	GError *error=NULL;
	GPtrArray *unoconv_argv=NULL;
	GPid unoconv_pid=0;

	//prüfen ob überhaupt Daten im Model verfügbar sind
	if (!gtk_tree_model_get_n_columns(gtk_tree_view_get_model(gui_get_gtk_tree_viewer()))){
		return;
	}
	//tmp-Ordner anlegen
	gchar *tmp = g_dir_make_tmp("odt2pdf-gtk_XXXXXX",&error);
	if (error!=NULL){
		g_warning("%s",error->message);
		g_error_free(error);
		error = NULL;
	}
	//temp_verzeichnis verfügbar machen
	temp_dir_save(g_strdup(tmp));
	//DEBUG
	g_print("%s\n",temp_dir_get());

	//Pfad für unoconv erstellen...
	unoconv_argv = g_ptr_array_new ();
	//function zum aufräumen übergeben
	g_ptr_array_set_free_func(unoconv_argv,ptr_array_clean);

	//ptr_array füllen
	fill_g_ptr_array(unoconv_argv,"unoconv");
	fill_g_ptr_array(unoconv_argv,"-f");
	fill_g_ptr_array(unoconv_argv,"pdf");
	fill_g_ptr_array(unoconv_argv,"-o");
	g_ptr_array_add(unoconv_argv,(gpointer)temp_dir_get_strdub());

	//wird für jedes Elemt in der Liststore ausgeführt
	gtk_tree_model_foreach(gtk_tree_view_get_model(gui_get_gtk_tree_viewer()),treemodel_ausgabe_unoconv,(gpointer)unoconv_argv);
	//abschließende NULL anhängen
	g_ptr_array_add(unoconv_argv,(gpointer)NULL);
	//startet den Converter und wartet bis er fertig ist
	//g_print("%s\n",unoconv_cmd->str);

	g_spawn_async_with_pipes 	(NULL,
														(gchar**)unoconv_argv->pdata,
														NULL,
														G_SPAWN_SEARCH_PATH|G_SPAWN_DO_NOT_REAP_CHILD,
														NULL,
														NULL,
														&unoconv_pid,
														NULL,
														NULL,
														NULL,
														&error);
	if (error!=NULL){
		g_warning("%s",error->message);
		g_error_free(error);
		error = NULL;
	}

	//g_child_watch einrichten, um über Programmende informiert zu werden
	g_child_watch_add(unoconv_pid,unoconv_child_watch_func,NULL);

	//strings freigeben
	g_ptr_array_free (unoconv_argv,TRUE);
	g_free(tmp);

	//Buttons ausgrauen
	interface_ausgrauen(FALSE);
}
Example #30
0
int main (int argc, char *argv[])
{
    gchar *in_dir;
    GList *tmp;
    struct evhttp_uri *uri;
    struct timeval tv;

    log_level = LOG_debug;

    event_set_mem_functions (g_malloc, g_realloc, g_free);
    // init SSL libraries
    CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free);
    ENGINE_load_builtin_engines ();
    ENGINE_register_all_complete ();
    ERR_load_crypto_strings ();
    OpenSSL_add_all_algorithms ();

    SSL_load_error_strings ();
    SSL_library_init ();
    if (!RAND_poll ()) {
        fprintf(stderr, "RAND_poll() failed.\n");
        return 1;
    }
    g_random_set_seed (time (NULL));

    in_dir = g_dir_make_tmp (NULL, NULL);
    g_assert (in_dir);

    app = g_new0 (Application, 1);
    app->files_count = 10;
    app->evbase = event_base_new ();
	app->dns_base = evdns_base_new (app->evbase, 1);

        app->conf = conf_create ();
        conf_add_boolean (app->conf, "log.use_syslog", TRUE);
        
        conf_add_uint (app->conf, "auth.ttl", 85800);
        
        conf_add_int (app->conf, "pool.writers", 2);
        conf_add_int (app->conf, "pool.readers", 2);
        conf_add_int (app->conf, "pool.operations", 4);
        conf_add_uint (app->conf, "pool.max_requests_per_pool", 100);

        conf_add_int (app->conf, "connection.timeout", 20);
        conf_add_int (app->conf, "connection.retries", -1);

        conf_add_uint (app->conf, "filesystem.dir_cache_max_time", 5);
        conf_add_boolean (app->conf, "filesystem.cache_enabled", TRUE);
        conf_add_string (app->conf, "filesystem.cache_dir", "/tmp/hydrafs");
        conf_add_string (app->conf, "filesystem.cache_dir_max_size", "1Gb");

        conf_add_boolean (app->conf, "statistics.enabled", TRUE);
        conf_add_int (app->conf, "statistics.port", 8011);

    conf_add_string (app->conf, "auth.user", "test:tester");
    conf_add_string (app->conf, "auth.key", "testing");
    uri = evhttp_uri_parse ("https://10.0.0.104:8080/auth/v1.0");
    
    app->ssl_ctx = SSL_CTX_new (TLSv1_client_method ());
    
    app->stats = hfs_stats_srv_create (app);
    app->auth_client = auth_client_create (app, uri);

    app->http = http_client_create (app);

    // start server
     start_srv (app->evbase, in_dir);

    app->timeout = evtimer_new (app->evbase, on_output_timer, NULL);

    evutil_timerclear(&tv);
    tv.tv_sec = 0;
    tv.tv_usec = 500;
    event_add (app->timeout, &tv);

    event_base_dispatch (app->evbase);

    evhttp_uri_free (uri);
    event_del (app->timeout);
    event_free (app->timeout);

    evhttp_free (app->http_srv);
    auth_client_destroy (app->auth_client);

    evdns_base_free (app->dns_base, 0);
    event_base_free (app->evbase);

    conf_destroy (app->conf);
    g_free (app);

    return 0;
}