|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* Copyright (C) 2011 Colin Walters <walters@verbum.org>
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* SPDX-License-Identifier: LGPL-2.0+
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is free software; you can redistribute it and/or
|
|
rpm-build |
0fba15 |
* modify it under the terms of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License as published by the Free Software Foundation; either
|
|
rpm-build |
0fba15 |
* version 2 of the License, or (at your option) any later version.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This library is distributed in the hope that it will be useful,
|
|
rpm-build |
0fba15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
rpm-build |
0fba15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
rpm-build |
0fba15 |
* Lesser General Public License for more details.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* You should have received a copy of the GNU Lesser General Public
|
|
rpm-build |
0fba15 |
* License along with this library; if not, write to the
|
|
rpm-build |
0fba15 |
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
rpm-build |
0fba15 |
* Boston, MA 02111-1307, USA.
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* Author: Colin Walters <walters@verbum.org>
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "config.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include <gio/gio.h>
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include <stdlib.h>
|
|
rpm-build |
0fba15 |
#include <string.h>
|
|
rpm-build |
0fba15 |
#include <sys/statvfs.h>
|
|
rpm-build |
0fba15 |
#include <sys/mount.h>
|
|
rpm-build |
0fba15 |
#include <linux/fs.h>
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#include "ot-main.h"
|
|
rpm-build |
0fba15 |
#include "ostree.h"
|
|
rpm-build |
0fba15 |
#include "ot-admin-functions.h"
|
|
rpm-build |
0fba15 |
#include "otutil.h"
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static char *opt_repo;
|
|
rpm-build |
0fba15 |
static char *opt_sysroot;
|
|
rpm-build |
0fba15 |
static gboolean opt_verbose;
|
|
rpm-build |
0fba15 |
static gboolean opt_version;
|
|
rpm-build |
0fba15 |
static gboolean opt_print_current_dir;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static GOptionEntry global_entries[] = {
|
|
rpm-build |
0fba15 |
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &opt_verbose, "Print debug information during command processing", NULL },
|
|
rpm-build |
0fba15 |
{ "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL },
|
|
rpm-build |
0fba15 |
{ NULL }
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static GOptionEntry repo_entry[] = {
|
|
rpm-build |
0fba15 |
{ "repo", 0, 0, G_OPTION_ARG_FILENAME, &opt_repo, "Path to OSTree repository (defaults to current directory or /sysroot/ostree/repo)", "PATH" },
|
|
rpm-build |
0fba15 |
{ NULL }
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static GOptionEntry global_admin_entries[] = {
|
|
rpm-build |
0fba15 |
/* No description since it's hidden from --help output. */
|
|
rpm-build |
0fba15 |
{ "print-current-dir", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_NONE, &opt_print_current_dir, NULL, NULL },
|
|
rpm-build |
0fba15 |
{ "sysroot", 0, 0, G_OPTION_ARG_FILENAME, &opt_sysroot, "Create a new OSTree sysroot at PATH", "PATH" },
|
|
rpm-build |
0fba15 |
{ NULL }
|
|
rpm-build |
0fba15 |
};
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static GOptionContext *
|
|
rpm-build |
0fba15 |
ostree_option_context_new_with_commands (OstreeCommand *commands)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
GOptionContext *context = g_option_context_new ("COMMAND");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_autoptr(GString) summary = g_string_new ("Builtin Commands:");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
while (commands->name != NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if ((commands->flags & OSTREE_BUILTIN_FLAG_HIDDEN) == 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_string_append_printf (summary, "\n %-18s", commands->name);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (commands->description != NULL )
|
|
rpm-build |
0fba15 |
g_string_append_printf (summary, "%s", commands->description);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
commands++;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_option_context_set_summary (context, summary->str);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return context;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
int
|
|
rpm-build |
0fba15 |
ostree_usage (OstreeCommand *commands,
|
|
rpm-build |
0fba15 |
gboolean is_error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GOptionContext) context =
|
|
rpm-build |
0fba15 |
ostree_option_context_new_with_commands (commands);
|
|
rpm-build |
0fba15 |
g_option_context_add_main_entries (context, global_entries, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_autofree char *help = g_option_context_get_help (context, FALSE, NULL);
|
|
rpm-build |
0fba15 |
if (is_error)
|
|
rpm-build |
0fba15 |
g_printerr ("%s", help);
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
g_print ("%s", help);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return (is_error ? 1 : 0);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* If we're running as root, booted into an OSTree system and have a read-only
|
|
rpm-build |
0fba15 |
* /sysroot, then assume we may need write access. Create a new mount namespace
|
|
rpm-build |
0fba15 |
* if so, and return *out_ns = TRUE. Otherwise, *out_ns = FALSE.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
static gboolean
|
|
rpm-build |
0fba15 |
maybe_setup_mount_namespace (gboolean *out_ns,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
*out_ns = FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* If we're not root, then we almost certainly can't be remounting anything */
|
|
rpm-build |
0fba15 |
if (getuid () != 0)
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* If the system isn't booted via libostree, also nothing to do */
|
|
rpm-build |
0fba15 |
if (!glnx_fstatat_allow_noent (AT_FDCWD, "/run/ostree-booted", NULL, 0, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
if (errno == ENOENT)
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
glnx_autofd int sysroot_subdir_fd = glnx_opendirat_with_errno (AT_FDCWD, "/sysroot", TRUE);
|
|
rpm-build |
0fba15 |
if (sysroot_subdir_fd < 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (errno != ENOENT)
|
|
rpm-build |
0fba15 |
return glnx_throw_errno_prefix (error, "opendirat");
|
|
rpm-build |
0fba15 |
/* No /sysroot - nothing to do */
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
struct statvfs stvfs;
|
|
rpm-build |
0fba15 |
if (fstatvfs (sysroot_subdir_fd, &stvfs) < 0)
|
|
rpm-build |
0fba15 |
return glnx_throw_errno_prefix (error, "fstatvfs");
|
|
rpm-build |
0fba15 |
if (stvfs.f_flag & ST_RDONLY)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (unshare (CLONE_NEWNS) < 0)
|
|
rpm-build |
0fba15 |
return glnx_throw_errno_prefix (error, "preparing writable sysroot: unshare (CLONE_NEWNS)");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
*out_ns = TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
message_handler (const gchar *log_domain,
|
|
rpm-build |
0fba15 |
GLogLevelFlags log_level,
|
|
rpm-build |
0fba15 |
const gchar *message,
|
|
rpm-build |
0fba15 |
gpointer user_data)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
/* Make this look like normal console output */
|
|
rpm-build |
0fba15 |
if (log_level & G_LOG_LEVEL_DEBUG)
|
|
rpm-build |
0fba15 |
g_printerr ("OT: %s\n", message);
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
g_printerr ("%s: %s\n", g_get_prgname (), message);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
int
|
|
rpm-build |
0fba15 |
ostree_run (int argc,
|
|
rpm-build |
0fba15 |
char **argv,
|
|
rpm-build |
0fba15 |
OstreeCommand *commands,
|
|
rpm-build |
0fba15 |
GError **res_error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
OstreeCommand *command;
|
|
rpm-build |
0fba15 |
GError *error = NULL;
|
|
rpm-build |
0fba15 |
GCancellable *cancellable = NULL;
|
|
rpm-build |
0fba15 |
#ifndef BUILDOPT_TSAN
|
|
rpm-build |
0fba15 |
g_autofree char *prgname = NULL;
|
|
rpm-build |
0fba15 |
#endif
|
|
rpm-build |
0fba15 |
const char *command_name = NULL;
|
|
rpm-build |
0fba15 |
gboolean success = FALSE;
|
|
rpm-build |
0fba15 |
int in, out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */
|
|
rpm-build |
0fba15 |
g_setenv ("GIO_USE_VFS", "local", TRUE);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, message_handler, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/*
|
|
rpm-build |
0fba15 |
* Parse the global options. We rearrange the options as
|
|
rpm-build |
0fba15 |
* necessary, in order to pass relevant options through
|
|
rpm-build |
0fba15 |
* to the commands, but also have them take effect globally.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
for (in = 1, out = 1; in < argc; in++, out++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
/* The non-option is the command, take it out of the arguments */
|
|
rpm-build |
0fba15 |
if (argv[in][0] != '-')
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (command_name == NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
command_name = argv[in];
|
|
rpm-build |
0fba15 |
out--;
|
|
rpm-build |
0fba15 |
continue;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
argv[out] = argv[in];
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
argc = out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
command = commands;
|
|
rpm-build |
0fba15 |
while (command->name)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (g_strcmp0 (command_name, command->name) == 0)
|
|
rpm-build |
0fba15 |
break;
|
|
rpm-build |
0fba15 |
command++;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!command->fn)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GOptionContext) context =
|
|
rpm-build |
0fba15 |
ostree_option_context_new_with_commands (commands);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* This will not return for some options (e.g. --version). */
|
|
rpm-build |
0fba15 |
if (ostree_option_context_parse (context, NULL, &argc, &argv, NULL, NULL, cancellable, &error))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (command_name == NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_set_error_literal (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
rpm-build |
0fba15 |
"No command specified");
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
rpm-build |
0fba15 |
"Unknown command '%s'", command_name);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
ostree_usage (commands, TRUE);
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#ifndef BUILDOPT_TSAN
|
|
rpm-build |
0fba15 |
prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name);
|
|
rpm-build |
0fba15 |
g_set_prgname (prgname);
|
|
rpm-build |
0fba15 |
#endif
|
|
rpm-build |
0fba15 |
OstreeCommandInvocation invocation = { .command = command };
|
|
rpm-build |
0fba15 |
if (!command->fn (argc, argv, &invocation, cancellable, &error))
|
|
rpm-build |
0fba15 |
goto out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
success = TRUE;
|
|
rpm-build |
0fba15 |
out:
|
|
rpm-build |
0fba15 |
g_assert (success || error);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_propagate_error (res_error, error);
|
|
rpm-build |
0fba15 |
return 1;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
return 0;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Process a --repo arg; used below, and for the remote builtins */
|
|
rpm-build |
0fba15 |
static OstreeRepo *
|
|
rpm-build |
0fba15 |
parse_repo_option (GOptionContext *context,
|
|
rpm-build |
0fba15 |
const char *repo_path,
|
|
rpm-build |
0fba15 |
gboolean skip_repo_open,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepo) repo = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* This is a bit of a brutal hack; we set up a mount
|
|
rpm-build |
0fba15 |
* namespace if it appears that we may need it. It'd
|
|
rpm-build |
0fba15 |
* be better to do this more precisely in the future.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
gboolean setup_ns = FALSE;
|
|
rpm-build |
0fba15 |
if (!maybe_setup_mount_namespace (&setup_ns, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
if (setup_ns)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (mount ("/sysroot", "/sysroot", NULL, MS_REMOUNT | MS_SILENT, NULL) < 0)
|
|
rpm-build |
0fba15 |
return glnx_null_throw_errno_prefix (error, "Remounting /sysroot read-write");
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (repo_path == NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GError) local_error = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
repo = ostree_repo_new_default ();
|
|
rpm-build |
0fba15 |
if (!ostree_repo_open (repo, cancellable, &local_error))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (g_error_matches (local_error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autofree char *help = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
rpm-build |
0fba15 |
"Command requires a --repo argument");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
help = g_option_context_get_help (context, FALSE, NULL);
|
|
rpm-build |
0fba15 |
g_printerr ("%s", help);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_propagate_error (error, g_steal_pointer (&local_error));
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
return NULL;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GFile) repo_file = g_file_new_for_path (repo_path);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
repo = ostree_repo_new (repo_file);
|
|
rpm-build |
0fba15 |
if (!skip_repo_open)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (!ostree_repo_open (repo, cancellable, error))
|
|
rpm-build |
0fba15 |
return NULL;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return g_steal_pointer (&repo);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Used by the remote builtins which are special in taking --sysroot or --repo */
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
ostree_parse_sysroot_or_repo_option (GOptionContext *context,
|
|
rpm-build |
0fba15 |
const char *sysroot_path,
|
|
rpm-build |
0fba15 |
const char *repo_path,
|
|
rpm-build |
0fba15 |
OstreeSysroot **out_sysroot,
|
|
rpm-build |
0fba15 |
OstreeRepo **out_repo,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeSysroot) sysroot = NULL;
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepo) repo = NULL;
|
|
rpm-build |
0fba15 |
if (sysroot_path)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GFile) sysroot_file = g_file_new_for_path (sysroot_path);
|
|
rpm-build |
0fba15 |
sysroot = ostree_sysroot_new (sysroot_file);
|
|
rpm-build |
0fba15 |
if (!ostree_sysroot_load (sysroot, cancellable, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
if (!ostree_sysroot_get_repo (sysroot, &repo, cancellable, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
repo = parse_repo_option (context, repo_path, FALSE, cancellable, error);
|
|
rpm-build |
0fba15 |
if (!repo)
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
ot_transfer_out_value (out_sysroot, &sysroot);
|
|
rpm-build |
0fba15 |
ot_transfer_out_value (out_repo, &repo);
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
ostree_option_context_parse (GOptionContext *context,
|
|
rpm-build |
0fba15 |
const GOptionEntry *main_entries,
|
|
rpm-build |
0fba15 |
int *argc,
|
|
rpm-build |
0fba15 |
char ***argv,
|
|
rpm-build |
0fba15 |
OstreeCommandInvocation *invocation,
|
|
rpm-build |
0fba15 |
OstreeRepo **out_repo,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeRepo) repo = NULL;
|
|
rpm-build |
0fba15 |
/* When invocation is NULL, do not fetch repo */
|
|
rpm-build |
0fba15 |
const OstreeBuiltinFlags flags = invocation ? invocation->command->flags : OSTREE_BUILTIN_FLAG_NO_REPO;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (invocation && invocation->command->description != NULL)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
const char *context_summary = g_option_context_get_summary (context);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* If the summary is originally empty, we set the description, but
|
|
rpm-build |
0fba15 |
* for root commands(command with subcommands), we want to prepend
|
|
rpm-build |
0fba15 |
* the description to the existing summary string
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
if (context_summary == NULL)
|
|
rpm-build |
0fba15 |
g_option_context_set_summary (context, invocation->command->description);
|
|
rpm-build |
0fba15 |
else
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
/* TODO: remove this part once we deduplicate the ostree_option_context_new_with_commands
|
|
rpm-build |
0fba15 |
* function from other root commands( command with subcommands). Because
|
|
rpm-build |
0fba15 |
* we can directly add the summary inside the ostree_option_context_new_with_commands function.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
g_autoptr(GString) new_summary_string = g_string_new (context_summary);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_string_prepend (new_summary_string, "\n\n");
|
|
rpm-build |
0fba15 |
g_string_prepend (new_summary_string, invocation->command->description);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_option_context_set_summary (context, new_summary_string->str);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
/* Entries are listed in --help output in the order added. We add the
|
|
rpm-build |
0fba15 |
* main entries ourselves so that we can add the --repo entry first. */
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!(flags & OSTREE_BUILTIN_FLAG_NO_REPO))
|
|
rpm-build |
0fba15 |
g_option_context_add_main_entries (context, repo_entry, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (main_entries != NULL)
|
|
rpm-build |
0fba15 |
g_option_context_add_main_entries (context, main_entries, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_option_context_add_main_entries (context, global_entries, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!g_option_context_parse (context, argc, argv, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Filter out the first -- we see; g_option_context_parse() leaves it in */
|
|
rpm-build |
0fba15 |
int in, out;
|
|
rpm-build |
0fba15 |
gboolean removed_double_dashes = FALSE;
|
|
rpm-build |
0fba15 |
for (in = 1, out = 1; in < *argc; in++, out++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (g_str_equal ((*argv)[in], "--") && !removed_double_dashes)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
removed_double_dashes = TRUE;
|
|
rpm-build |
0fba15 |
out--;
|
|
rpm-build |
0fba15 |
continue;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
(*argv)[out] = (*argv)[in];
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
*argc = out;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (opt_version)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
/* This should now be YAML, like `docker version`, so it's both nice to read
|
|
rpm-build |
0fba15 |
* possible to parse */
|
|
rpm-build |
0fba15 |
g_auto(GStrv) features = g_strsplit (OSTREE_FEATURES, " ", -1);
|
|
rpm-build |
0fba15 |
g_print ("%s:\n", PACKAGE_NAME);
|
|
rpm-build |
0fba15 |
g_print (" Version: '%s'\n", PACKAGE_VERSION);
|
|
rpm-build |
0fba15 |
if (strlen (OSTREE_GITREV) > 0)
|
|
rpm-build |
0fba15 |
g_print (" Git: %s\n", OSTREE_GITREV);
|
|
rpm-build |
0fba15 |
#ifdef BUILDOPT_IS_DEVEL_BUILD
|
|
rpm-build |
0fba15 |
g_print (" DevelBuild: yes\n");
|
|
rpm-build |
0fba15 |
#endif
|
|
rpm-build |
0fba15 |
g_print (" Features:\n");
|
|
rpm-build |
0fba15 |
for (char **iter = features; iter && *iter; iter++)
|
|
rpm-build |
0fba15 |
g_print (" - %s\n", *iter);
|
|
rpm-build |
0fba15 |
exit (EXIT_SUCCESS);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (opt_verbose)
|
|
rpm-build |
0fba15 |
g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!(flags & OSTREE_BUILTIN_FLAG_NO_REPO))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
repo = parse_repo_option (context, opt_repo, (flags & OSTREE_BUILTIN_FLAG_NO_CHECK) > 0,
|
|
rpm-build |
0fba15 |
cancellable, error);
|
|
rpm-build |
0fba15 |
if (!repo)
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (out_repo)
|
|
rpm-build |
0fba15 |
*out_repo = g_steal_pointer (&repo);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
static void
|
|
rpm-build |
0fba15 |
on_sysroot_journal_msg (OstreeSysroot *sysroot,
|
|
rpm-build |
0fba15 |
const char *msg,
|
|
rpm-build |
0fba15 |
void *dummy)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_print ("%s\n", msg);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
ostree_admin_option_context_parse (GOptionContext *context,
|
|
rpm-build |
0fba15 |
const GOptionEntry *main_entries,
|
|
rpm-build |
0fba15 |
int *argc,
|
|
rpm-build |
0fba15 |
char ***argv,
|
|
rpm-build |
0fba15 |
OstreeAdminBuiltinFlags flags,
|
|
rpm-build |
0fba15 |
OstreeCommandInvocation *invocation,
|
|
rpm-build |
0fba15 |
OstreeSysroot **out_sysroot,
|
|
rpm-build |
0fba15 |
GCancellable *cancellable,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
/* Entries are listed in --help output in the order added. We add the
|
|
rpm-build |
0fba15 |
* main entries ourselves so that we can add the --sysroot entry first. */
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_option_context_add_main_entries (context, global_admin_entries, NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_option_context_parse (context, main_entries, argc, argv,
|
|
rpm-build |
0fba15 |
invocation, NULL, cancellable, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!opt_print_current_dir && (flags & OSTREE_ADMIN_BUILTIN_FLAG_NO_SYSROOT))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_assert_null (out_sysroot);
|
|
rpm-build |
0fba15 |
/* Early return if no sysroot is requested */
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_autoptr(GFile) sysroot_path = NULL;
|
|
rpm-build |
0fba15 |
if (opt_sysroot != NULL)
|
|
rpm-build |
0fba15 |
sysroot_path = g_file_new_for_path (opt_sysroot);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_autoptr(OstreeSysroot) sysroot = ostree_sysroot_new (sysroot_path);
|
|
rpm-build |
0fba15 |
if (!ostree_sysroot_initialize (sysroot, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
g_signal_connect (sysroot, "journal-msg", G_CALLBACK (on_sysroot_journal_msg), NULL);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if ((flags & OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED) == 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
/* If we're requested to lock the sysroot, first check if we're operating
|
|
rpm-build |
0fba15 |
* on a booted (not physical) sysroot. Then find out if the /sysroot
|
|
rpm-build |
0fba15 |
* subdir is a read-only mount point, and if so, create a new mount
|
|
rpm-build |
0fba15 |
* namespace and tell the sysroot that we've done so. See the docs for
|
|
rpm-build |
0fba15 |
* ostree_sysroot_set_mount_namespace_in_use().
|
|
rpm-build |
0fba15 |
*
|
|
rpm-build |
0fba15 |
* This is a conservative approach; we could just always
|
|
rpm-build |
0fba15 |
* unshare() too.
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
if (ostree_sysroot_is_booted (sysroot))
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
gboolean setup_ns = FALSE;
|
|
rpm-build |
0fba15 |
if (!maybe_setup_mount_namespace (&setup_ns, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
if (setup_ns)
|
|
rpm-build |
0fba15 |
ostree_sysroot_set_mount_namespace_in_use (sysroot);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Released when sysroot is finalized, or on process exit */
|
|
rpm-build |
0fba15 |
if (!ot_admin_sysroot_lock (sysroot, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (!ostree_sysroot_load (sysroot, cancellable, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (flags & OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
OstreeDeployment *booted = ostree_sysroot_get_booted_deployment (sysroot);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* Only require root if we're manipulating a booted sysroot. (Mostly
|
|
rpm-build |
0fba15 |
* useful for the test suite)
|
|
rpm-build |
0fba15 |
*/
|
|
rpm-build |
0fba15 |
if (booted && getuid () != 0)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_set_error (error, G_IO_ERROR, G_IO_ERROR_PERMISSION_DENIED,
|
|
rpm-build |
0fba15 |
"You must be root to perform this command");
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (opt_print_current_dir)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_autoptr(GPtrArray) deployments = NULL;
|
|
rpm-build |
0fba15 |
OstreeDeployment *first_deployment;
|
|
rpm-build |
0fba15 |
g_autoptr(GFile) deployment_file = NULL;
|
|
rpm-build |
0fba15 |
g_autofree char *deployment_path = NULL;
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
deployments = ostree_sysroot_get_deployments (sysroot);
|
|
rpm-build |
0fba15 |
if (deployments->len == 0)
|
|
rpm-build |
0fba15 |
return glnx_throw (error, "Unable to find a deployment in sysroot");
|
|
rpm-build |
0fba15 |
first_deployment = deployments->pdata[0];
|
|
rpm-build |
0fba15 |
deployment_file = ostree_sysroot_get_deployment_directory (sysroot, first_deployment);
|
|
rpm-build |
0fba15 |
deployment_path = g_file_get_path (deployment_file);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_print ("%s\n", deployment_path);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* The g_autoptr, g_autofree etc. don't happen when we explicitly
|
|
rpm-build |
0fba15 |
* exit, making valgrind complain about leaks */
|
|
rpm-build |
0fba15 |
g_clear_object (&sysroot);
|
|
rpm-build |
0fba15 |
g_clear_object (&sysroot_path);
|
|
rpm-build |
0fba15 |
g_clear_object (&deployment_file);
|
|
rpm-build |
0fba15 |
g_clear_pointer (&deployments, g_ptr_array_unref);
|
|
rpm-build |
0fba15 |
g_clear_pointer (&deployment_path, g_free);
|
|
rpm-build |
0fba15 |
exit (EXIT_SUCCESS);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
if (out_sysroot)
|
|
rpm-build |
0fba15 |
*out_sysroot = g_steal_pointer (&sysroot);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
ostree_ensure_repo_writable (OstreeRepo *repo,
|
|
rpm-build |
0fba15 |
GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
if (!ostree_repo_is_writable (repo, error))
|
|
rpm-build |
0fba15 |
return glnx_prefix_error (error, "Cannot write to repository");
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
#ifndef OSTREE_DISABLE_GPGME
|
|
rpm-build |
0fba15 |
void
|
|
rpm-build |
0fba15 |
ostree_print_gpg_verify_result (OstreeGpgVerifyResult *result)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
guint n_sigs = ostree_gpg_verify_result_count_all (result);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
/* XXX If we ever add internationalization, use ngettext() here. */
|
|
rpm-build |
0fba15 |
g_print ("GPG: Verification enabled, found %u signature%s:\n",
|
|
rpm-build |
0fba15 |
n_sigs, n_sigs == 1 ? "" : "s");
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_autoptr(GString) buffer = g_string_sized_new (256);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
for (guint ii = 0; ii < n_sigs; ii++)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_string_append_c (buffer, '\n');
|
|
rpm-build |
0fba15 |
ostree_gpg_verify_result_describe (result, ii, buffer, " ",
|
|
rpm-build |
0fba15 |
OSTREE_GPG_SIGNATURE_FORMAT_DEFAULT);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
g_print ("%s", buffer->str);
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
#endif /* OSTREE_DISABLE_GPGME */
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
gboolean
|
|
rpm-build |
0fba15 |
ot_enable_tombstone_commits (OstreeRepo *repo, GError **error)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
gboolean tombstone_commits = FALSE;
|
|
rpm-build |
0fba15 |
GKeyFile *config = ostree_repo_get_config (repo);
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
tombstone_commits = g_key_file_get_boolean (config, "core", "tombstone-commits", NULL);
|
|
rpm-build |
0fba15 |
/* tombstone_commits is FALSE either if it is not found or it is really set to FALSE in the config file. */
|
|
rpm-build |
0fba15 |
if (!tombstone_commits)
|
|
rpm-build |
0fba15 |
{
|
|
rpm-build |
0fba15 |
g_key_file_set_boolean (config, "core", "tombstone-commits", TRUE);
|
|
rpm-build |
0fba15 |
if (!ostree_repo_write_config (repo, config, error))
|
|
rpm-build |
0fba15 |
return FALSE;
|
|
rpm-build |
0fba15 |
}
|
|
rpm-build |
0fba15 |
|
|
rpm-build |
0fba15 |
return TRUE;
|
|
rpm-build |
0fba15 |
}
|