Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switchroot: Ensure /run/ostree-booted is created even without initramfs #1508

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/switchroot/ostree-mount-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,19 @@ read_proc_cmdline_ostree (void)
return ret;
}

/* This is an API for other projects to determine whether or not the
* currently running system is ostree-controlled.
*/
static inline void
touch_run_ostree (void)
{
int fd = open ("/run/ostree-booted", O_CREAT | O_WRONLY | O_NOCTTY | O_CLOEXEC, 0640);
/* We ignore failures here in case /run isn't mounted...not much we
* can do about that, but we don't want to fail.
*/
if (fd == -1)
return;
(void) close (fd);
}

#endif /* __OSTREE_MOUNT_UTIL_H_ */
25 changes: 7 additions & 18 deletions src/switchroot/ostree-prepare-root.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,6 @@

#include "ostree-mount-util.h"

/* This is an API for other projects to determine whether or not the
* currently running system is ostree-controlled.
*/
static void
touch_run_ostree (void)
{
int fd;

fd = open ("/run/ostree-booted", O_CREAT | O_WRONLY | O_NOCTTY | O_CLOEXEC, 0640);
/* We ignore failures here in case /run isn't mounted...not much we
* can do about that, but we don't want to fail.
*/
if (fd == -1)
return;
(void) close (fd);
}

static char*
resolve_deploy_path (const char * root_mountpoint)
{
Expand Down Expand Up @@ -205,7 +188,13 @@ main(int argc, char *argv[])
err (EXIT_FAILURE, "failed to bind mount (class:readonly) /usr");
}

touch_run_ostree ();

/* We only stamp /run now if we're running in an initramfs, i.e. we're
* not pid 1. Otherwise it's handled later via ostree-remount.service.
* https://mail.gnome.org/archives/ostree-list/2018-March/msg00012.html
*/
if (getpid () != 1)
touch_run_ostree ();

if (strcmp(root_mountpoint, "/") == 0)
{
Expand Down
10 changes: 10 additions & 0 deletions src/switchroot/ostree-remount.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ main(int argc, char *argv[])
struct stat stbuf;
int i;

/* See comments in ostree-prepare-root.c for this.
*
* This service is triggered via
* ConditionKernelCommandLine=ostree
* but it's a lot easier for various bits of userspace to check for
* a file versus parsing the kernel cmdline. So let's ensure
* the stamp file is created here too.
*/
touch_run_ostree ();

/* The /sysroot mount needs to be private to avoid having a mount for e.g. /var/cache
* also propagate to /sysroot/ostree/deploy/$stateroot/var/cache
*
Expand Down