#include "ostree-cmd-private.h"
#include "ostree-core-private.h"
+#include "ostree-sysroot-private.h"
#include "ostree.h"
#ifdef HAVE_LIBMOUNT
return path;
}
-/* Written by ostree-sysroot-deploy.c. We parse out the stateroot here since we
- * need to know it to mount /var. Unfortunately we can't easily use the
- * libostree API to find the booted deployment since /boot might not have been
- * mounted yet.
- */
-static char *
-stateroot_from_ostree_cmdline (const char *ostree_cmdline, GError **error)
-{
- static GRegex *regex;
- static gsize regex_initialized;
- if (g_once_init_enter (®ex_initialized))
- {
- regex = g_regex_new ("^/ostree/boot.[01]/([^/]+)/", 0, 0, NULL);
- g_assert (regex);
- g_once_init_leave (®ex_initialized, 1);
- }
-
- g_autoptr (GMatchInfo) match = NULL;
- if (!g_regex_match (regex, ostree_cmdline, 0, &match))
- return glnx_null_throw (error, "Failed to parse %s", ostree_cmdline);
-
- return g_match_info_fetch (match, 1);
-}
#endif
/* Forcibly enable our internal units, since we detected ostree= on the kernel cmdline */
static const char fstab_path[] = "/etc/fstab";
static const char var_path[] = "/var";
- /* ostree-prepare-root was patched to write the stateroot to this file */
- g_autofree char *stateroot = stateroot_from_ostree_cmdline (ostree_cmdline, error);
- if (!stateroot)
- return FALSE;
+ /* Written by ostree-sysroot-deploy.c. We parse out the stateroot here since we
+ * need to know it to mount /var. Unfortunately we can't easily use the
+ * libostree API to find the booted deployment since /boot might not have been
+ * mounted yet.
+ */
+ g_autofree char *stateroot = NULL;
+ if (!_ostree_sysroot_parse_bootlink (ostree_cmdline, NULL, &stateroot, NULL, NULL, error))
+ return glnx_prefix_error (error, "Parsing stateroot");
/* Load /etc/fstab if it exists, and look for a /var mount */
g_autoptr (OtLibMountFile) fstab = setmntent (fstab_path, "re");
gboolean _ostree_sysroot_list_all_boot_directories (OstreeSysroot *self, char ***out_bootdirs,
GCancellable *cancellable, GError **error);
+gboolean _ostree_sysroot_parse_bootlink (const char *bootlink, int *out_entry_bootversion,
+ char **out_osname, char **out_bootcsum,
+ int *out_treebootserial, GError **error);
+
G_END_DECLS
return TRUE;
}
-static gboolean
-parse_bootlink (const char *bootlink, int *out_entry_bootversion, char **out_osname,
- char **out_bootcsum, int *out_treebootserial, GError **error)
+// Parse the kernel argument ostree=
+gboolean
+_ostree_sysroot_parse_bootlink (const char *bootlink, int *out_entry_bootversion, char **out_osname,
+ char **out_bootcsum, int *out_treebootserial, GError **error)
{
static gsize regex_initialized;
static GRegex *regex;
g_autofree char *bootversion_str = g_match_info_fetch (match, 1);
g_autofree char *treebootserial_str = g_match_info_fetch (match, 4);
- *out_entry_bootversion = (int)g_ascii_strtoll (bootversion_str, NULL, 10);
- *out_osname = g_match_info_fetch (match, 2);
- *out_bootcsum = g_match_info_fetch (match, 3);
- *out_treebootserial = (int)g_ascii_strtoll (treebootserial_str, NULL, 10);
+ if (out_entry_bootversion)
+ *out_entry_bootversion = (int)g_ascii_strtoll (bootversion_str, NULL, 10);
+ if (out_osname)
+ *out_osname = g_match_info_fetch (match, 2);
+ if (out_bootcsum)
+ *out_bootcsum = g_match_info_fetch (match, 3);
+ if (out_treebootserial)
+ *out_treebootserial = (int)g_ascii_strtoll (treebootserial_str, NULL, 10);
return TRUE;
}
g_autofree char *osname = NULL;
g_autofree char *bootcsum = NULL;
int treebootserial = -1;
- if (!parse_bootlink (boot_link, &entry_boot_version, &osname, &bootcsum, &treebootserial, error))
+ if (!_ostree_sysroot_parse_bootlink (boot_link, &entry_boot_version, &osname, &bootcsum,
+ &treebootserial, error))
return FALSE;
g_autofree char *errprefix