Blame src/libostree/ostree-bootloader-zipl.c

rpm-build 0fba15
/*
rpm-build 0fba15
 * Copyright (C) 2019 Colin Walters <walters@verbum.org>
rpm-build 0fba15
 *
rpm-build 0fba15
 * This program is free software: you can redistribute it and/or modify
rpm-build 0fba15
 * it under the terms of the GNU Lesser General Public License as published
rpm-build 0fba15
 * by the Free Software Foundation; either version 2 of the licence or (at
rpm-build 0fba15
 * 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
rpm-build 0fba15
 * Public 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
rpm-build 0fba15
#include "config.h"
rpm-build 0fba15
rpm-build 0fba15
#include "ostree-sysroot-private.h"
rpm-build 0fba15
#include "ostree-bootloader-zipl.h"
rpm-build 0fba15
#include "otutil.h"
rpm-build 0fba15
rpm-build 0fba15
#include <string.h>
rpm-build 0fba15
rpm-build 0fba15
/* This is specific to zipl today, but in the future we could also
rpm-build 0fba15
 * use it for the grub2-mkconfig case.
rpm-build 0fba15
 */
rpm-build 0fba15
static const char zipl_requires_execute_path[] = "boot/ostree-bootloader-update.stamp";
rpm-build 0fba15
rpm-build 0fba15
struct _OstreeBootloaderZipl
rpm-build 0fba15
{
rpm-build 0fba15
  GObject       parent_instance;
rpm-build 0fba15
rpm-build 0fba15
  OstreeSysroot  *sysroot;
rpm-build 0fba15
};
rpm-build 0fba15
rpm-build 0fba15
typedef GObjectClass OstreeBootloaderZiplClass;
rpm-build 0fba15
rpm-build 0fba15
static void _ostree_bootloader_zipl_bootloader_iface_init (OstreeBootloaderInterface *iface);
rpm-build 0fba15
G_DEFINE_TYPE_WITH_CODE (OstreeBootloaderZipl, _ostree_bootloader_zipl, G_TYPE_OBJECT,
rpm-build 0fba15
                         G_IMPLEMENT_INTERFACE (OSTREE_TYPE_BOOTLOADER, _ostree_bootloader_zipl_bootloader_iface_init));
rpm-build 0fba15
rpm-build 0fba15
static gboolean
rpm-build 0fba15
_ostree_bootloader_zipl_query (OstreeBootloader *bootloader,
rpm-build 0fba15
                                   gboolean         *out_is_active,
rpm-build 0fba15
                                   GCancellable     *cancellable,
rpm-build 0fba15
                                   GError          **error)
rpm-build 0fba15
{
rpm-build 0fba15
  /* We don't auto-detect this one; should be explicitly chosen right now.
rpm-build 0fba15
   * see also https://github.com/coreos/coreos-assembler/pull/849
rpm-build 0fba15
   */
rpm-build 0fba15
  *out_is_active = FALSE;
rpm-build 0fba15
  return TRUE;
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static const char *
rpm-build 0fba15
_ostree_bootloader_zipl_get_name (OstreeBootloader *bootloader)
rpm-build 0fba15
{
rpm-build 0fba15
  return "zipl";
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static gboolean
rpm-build 0fba15
_ostree_bootloader_zipl_write_config (OstreeBootloader  *bootloader,
rpm-build 0fba15
                                          int                bootversion,
rpm-build 0fba15
                                          GPtrArray         *new_deployments,
rpm-build 0fba15
                                          GCancellable      *cancellable,
rpm-build 0fba15
                                          GError           **error)
rpm-build 0fba15
{
rpm-build 0fba15
  OstreeBootloaderZipl *self = OSTREE_BOOTLOADER_ZIPL (bootloader);
rpm-build 0fba15
rpm-build 0fba15
  /* Write our stamp file */
rpm-build 0fba15
  if (!glnx_file_replace_contents_at (self->sysroot->sysroot_fd, zipl_requires_execute_path,
rpm-build 0fba15
                                      (guint8*)"", 0, GLNX_FILE_REPLACE_NODATASYNC,
rpm-build 0fba15
                                      cancellable, error))
rpm-build 0fba15
    return FALSE;
rpm-build 0fba15
rpm-build 0fba15
  return TRUE;
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static gboolean
rpm-build 0fba15
_ostree_bootloader_zipl_post_bls_sync (OstreeBootloader  *bootloader,
rpm-build 0fba15
                                       GCancellable  *cancellable,
rpm-build 0fba15
                                       GError       **error)
rpm-build 0fba15
{
rpm-build 0fba15
  OstreeBootloaderZipl *self = OSTREE_BOOTLOADER_ZIPL (bootloader);
rpm-build 0fba15
rpm-build 0fba15
  /* Note that unlike the grub2-mkconfig backend, we make no attempt to
rpm-build 0fba15
   * chroot().
rpm-build 0fba15
   */
rpm-build 0fba15
  g_assert (self->sysroot->booted_deployment);
rpm-build 0fba15
rpm-build 0fba15
  if (!glnx_fstatat_allow_noent (self->sysroot->sysroot_fd, zipl_requires_execute_path, NULL, 0, error))
rpm-build 0fba15
    return FALSE;
rpm-build 0fba15
rpm-build 0fba15
  /* If there's no stamp file, nothing to do */
rpm-build 0fba15
  if (errno == ENOENT)
rpm-build 0fba15
    return TRUE;
rpm-build 0fba15
rpm-build 0fba15
  const char *const zipl_argv[] = {"zipl", NULL};
rpm-build 0fba15
  int estatus;
rpm-build 0fba15
  if (!g_spawn_sync (NULL, (char**)zipl_argv, NULL, G_SPAWN_SEARCH_PATH,
rpm-build 0fba15
                     NULL, NULL, NULL, NULL, &estatus, error))
rpm-build 0fba15
    return FALSE;
rpm-build 0fba15
  if (!g_spawn_check_exit_status (estatus, error))
rpm-build 0fba15
    return FALSE;
rpm-build 0fba15
  if (!glnx_unlinkat (self->sysroot->sysroot_fd, zipl_requires_execute_path, 0, error))
rpm-build 0fba15
    return FALSE;
rpm-build 0fba15
  return TRUE;
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static void
rpm-build 0fba15
_ostree_bootloader_zipl_finalize (GObject *object)
rpm-build 0fba15
{
rpm-build 0fba15
  OstreeBootloaderZipl *self = OSTREE_BOOTLOADER_ZIPL (object);
rpm-build 0fba15
rpm-build 0fba15
  g_clear_object (&self->sysroot);
rpm-build 0fba15
rpm-build 0fba15
  G_OBJECT_CLASS (_ostree_bootloader_zipl_parent_class)->finalize (object);
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
void
rpm-build 0fba15
_ostree_bootloader_zipl_init (OstreeBootloaderZipl *self)
rpm-build 0fba15
{
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
static void
rpm-build 0fba15
_ostree_bootloader_zipl_bootloader_iface_init (OstreeBootloaderInterface *iface)
rpm-build 0fba15
{
rpm-build 0fba15
  iface->query = _ostree_bootloader_zipl_query;
rpm-build 0fba15
  iface->get_name = _ostree_bootloader_zipl_get_name;
rpm-build 0fba15
  iface->write_config = _ostree_bootloader_zipl_write_config;
rpm-build 0fba15
  iface->post_bls_sync = _ostree_bootloader_zipl_post_bls_sync;
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
void
rpm-build 0fba15
_ostree_bootloader_zipl_class_init (OstreeBootloaderZiplClass *class)
rpm-build 0fba15
{
rpm-build 0fba15
  GObjectClass *object_class = G_OBJECT_CLASS (class);
rpm-build 0fba15
rpm-build 0fba15
  object_class->finalize = _ostree_bootloader_zipl_finalize;
rpm-build 0fba15
}
rpm-build 0fba15
rpm-build 0fba15
OstreeBootloaderZipl *
rpm-build 0fba15
_ostree_bootloader_zipl_new (OstreeSysroot *sysroot)
rpm-build 0fba15
{
rpm-build 0fba15
  OstreeBootloaderZipl *self = g_object_new (OSTREE_TYPE_BOOTLOADER_ZIPL, NULL);
rpm-build 0fba15
  self->sysroot = g_object_ref (sysroot);
rpm-build 0fba15
  return self;
rpm-build 0fba15
}