Skip to content

Commit

Permalink
Add option for transient etc
Browse files Browse the repository at this point in the history
  • Loading branch information
pwallrab committed Aug 7, 2023
1 parent c9a38df commit 5370cc8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
7 changes: 7 additions & 0 deletions man/ostree-prepare-root.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ License along with this library. If not, see <https://www.gnu.org/licenses/>.
<listitem><para>A boolean value; the default is false. If this is set to <literal>true</literal>, then the <literal>/sysroot</literal> mount point is mounted read-only.</para></listitem>
</varlistentry>
</variablelist>

<variablelist>
<varlistentry>
<term><varname>sysroot.etc</varname></term>
<listitem><para>A string value; the default is persitent. If this is set to <literal>transient</literal>, then the <literal>/sysroot</literal> mount point is mounted transiently i.e. a non-persistent location.</para></listitem>
</varlistentry>
</variablelist>
</refsect1>


Expand Down
21 changes: 11 additions & 10 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,10 @@ load_composefs_config (GError **error)
static gboolean
find_etc (const char **out_path, GError **error)
{
struct stat stbuf;

// Look for /etc
if (fstatat (AT_FDCWD, "etc") == 0)
if (!glnx_fstatat_allow_noent (AT_FDCWD, "etc", &stbuf, AT_SYMLINK_NOFOLLOW, error))
{
*out_path = "etc";
return TRUE;
Expand All @@ -342,7 +344,7 @@ find_etc (const char **out_path, GError **error)
}

// Look for /usr/etc
if (fstatat (AT_FDCWD, "usr/etc") == 0)
if (!glnx_fstatat_allow_noent (AT_FDCWD, "usr/etc", &stbuf, AT_SYMLINK_NOFOLLOW, error))
{
*out_path = "usr/etc";
return TRUE;
Expand All @@ -352,7 +354,7 @@ find_etc (const char **out_path, GError **error)
return glnx_throw_errno_prefix (error, "failed to stat etc");
}
*out_path = NULL;
return TRUE;
return FALSE;
}

int
Expand Down Expand Up @@ -600,9 +602,9 @@ main (int argc, char *argv[])

g_autofree char *etc_config = NULL;
if (!ot_keyfile_get_value_with_default (config, SYSROOT_KEY, ETC_KEY, "persistent", &etc_config,
error))
&error))
errx (EXIT_FAILURE, "failed to parse %s.%s: %s", SYSROOT_KEY, ETC_KEY, error->message);
bool etc_transient = FALSE;
bool etc_transient = false;
if (g_str_equal (etc_config, "persistent"))
etc_transient = false;
else if (g_str_equal (etc_config, "transient"))
Expand Down Expand Up @@ -634,11 +636,10 @@ main (int argc, char *argv[])
if (!find_etc (&etc_lower, &error))
errx (EXIT_FAILURE, "Failed to find etc: %s", error->message);

if (etc_lower)
{
g_autofree char etc_ovl_options
= g_strdup_printf ("lowerdir=%s,upperdir=%s,workdir=%s", etc_lower, upper, work);
if (g_str_equal (""))
g_autofree char *etc_ovl_options
= g_strdup_printf ("lowerdir=%s,upperdir=%s,workdir=%s", etc_lower, upper, work);
if (mount ("overlay", TMP_SYSROOT "/etc", "overlay", MS_SILENT, etc_ovl_options) < 0)
err (EXIT_FAILURE, "failed to mount transient etc overlayfs");
}
else
{
Expand Down

0 comments on commit 5370cc8

Please sign in to comment.