示例#1
0
/*!
 * Handle commands to setup the environment as a precursor to
 * creating the state file.
 *
 * \param sub \ref subcommand.
 * \param config \ref cc_oci_config.
 * \param argc Argument count.
 * \param argv Argument vector.
 *
 * \return \c true on success, else \c false.
 */
gboolean
handle_command_setup (const struct subcommand *sub,
		struct cc_oci_config *config,
		int argc, char *argv[])
{
	gboolean  ret;

	g_assert (sub);
	g_assert (config);

	if (handle_default_usage (argc, argv, sub->name,
				&ret, 1, NULL)) {
		return ret;
	}

	config->optarg_container_id = argv[0];

	if (start_data.bundle) {
		/* Running in "runc mode" where --bundle has already
		 * been specified.
		 */
		if (argc != 1) {
			g_critical ("Usage: %s --bundle "
					"<bundle-path> <container-id>",
					sub->name);
			return false;
		}

		config->bundle_path = cc_oci_resolve_path (start_data.bundle);
		g_free (start_data.bundle);
		start_data.bundle = NULL;
	} else {
		/* Running in strict OCI-mode */
		if (argc != 2) {
			g_critical ("Usage: %s <container-id> "
					"<bundle-path>", sub->name);
			return false;
		}

		config->bundle_path = cc_oci_resolve_path (argv[1]);
	}

	config->console = start_data.console;
	config->pid_file = start_data.pid_file;
	config->dry_run_mode = start_data.dry_run_mode;
	config->detached_mode = start_data.detach;

	return true;
}
示例#2
0
} END_TEST

/*
 * TODO:
 *
 * We should really explore maximum paths values:
 *
 * - absolute maximum: PATH_MAX
 * - relative maximum: _POSIX_PATH_MAX
 * - pathconf(3)
 */
START_TEST(test_cc_oci_resolve_path) {
	gchar *tmpdir;
	gchar *file;
	gchar *slink;
	gchar *path;
	const char *d = NULL;

	tmpdir = g_dir_make_tmp (NULL, NULL);
	ck_assert (tmpdir);

	file = g_build_path ("/", tmpdir, "foo", NULL);
	ck_assert (file);

	slink = g_build_path ("/", tmpdir, "symlink", NULL);
	ck_assert (slink);

	/* create a symlink */
	ck_assert (! symlink (file, slink));

	ck_assert (! cc_oci_resolve_path (NULL));
	ck_assert (! cc_oci_resolve_path (""));
	ck_assert (! cc_oci_resolve_path ("not a path"));
	ck_assert (! cc_oci_resolve_path ("/does/not/exist"));

	/*******************************/
	/* check a known valid path */

	d = g_get_tmp_dir ();
	ck_assert (d);

	path = cc_oci_resolve_path (d);
	ck_assert (path);
	ck_assert (! g_strcmp0 (path, d));
	g_free (path);

	/*******************************/
	/* file doesn't exist */

	path = cc_oci_resolve_path (file);
	ck_assert (! path);

	/*******************************/
	/* create valid file */

	ck_assert (g_file_set_contents (file, "", -1, NULL));

	path = cc_oci_resolve_path (file);
	ck_assert (path);
	ck_assert (! g_strcmp0 (path, file));
	g_free (path);

	/*******************************/
	/* check a broken symlink */

	/* break the symlink by removing the file it points to */
	ck_assert (! g_remove (file));

	path = cc_oci_resolve_path (slink);
	ck_assert (! path);

	/*******************************/
	/* check a valid symlink */

	/* re create the file */
	ck_assert (g_file_set_contents (file, "", -1, NULL));

	path = cc_oci_resolve_path (slink);
	ck_assert (path);

	ck_assert (! g_strcmp0 (path, file));
	g_free (path);

	/* clean up */
	ck_assert (! g_remove (file));
	ck_assert (! g_remove (slink));
	ck_assert (! g_remove (tmpdir));
	g_free (tmpdir);
	g_free (file);
	g_free (slink);

} END_TEST