ostree-prepare-root: Refactor code to resolve deploy_path
I'll reuse this for a new ostree-init. Closes: #403 Approved by: cgwalters
This commit is contained in:
parent
94e50ca5aa
commit
1364e6e30d
|
|
@ -108,25 +108,12 @@ touch_run_ostree (void)
|
|||
(void) close (fd);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
static char*
|
||||
resolve_deploy_path (const char * root_mountpoint)
|
||||
{
|
||||
const char *root_mountpoint = NULL;
|
||||
char *ostree_target = NULL;
|
||||
char *deploy_path = NULL;
|
||||
char srcpath[PATH_MAX];
|
||||
char destpath[PATH_MAX];
|
||||
char newroot[PATH_MAX];
|
||||
struct stat stbuf;
|
||||
int orig_cwd_dfd;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf (stderr, "usage: ostree-prepare-root SYSROOT\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
root_mountpoint = argv[1];
|
||||
char *ostree_target, *deploy_path;
|
||||
|
||||
ostree_target = parse_ostree_cmdline ();
|
||||
if (!ostree_target)
|
||||
|
|
@ -135,16 +122,6 @@ main(int argc, char *argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Create a temporary target for our mounts in the initramfs; this will
|
||||
* be moved to the new system root below.
|
||||
*/
|
||||
snprintf (newroot, sizeof(newroot), "%s.tmp", root_mountpoint);
|
||||
if (mkdir (newroot, 0755) < 0)
|
||||
{
|
||||
perrorv ("Couldn't create temporary sysroot '%s': ", newroot);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
snprintf (destpath, sizeof(destpath), "%s/%s", root_mountpoint, ostree_target);
|
||||
printf ("Examining %s\n", destpath);
|
||||
if (lstat (destpath, &stbuf) < 0)
|
||||
|
|
@ -164,6 +141,38 @@ main(int argc, char *argv[])
|
|||
exit (EXIT_FAILURE);
|
||||
}
|
||||
printf ("Resolved OSTree target to: %s\n", deploy_path);
|
||||
return deploy_path;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
const char *root_mountpoint = NULL;
|
||||
char *deploy_path = NULL;
|
||||
char srcpath[PATH_MAX];
|
||||
char destpath[PATH_MAX];
|
||||
char newroot[PATH_MAX];
|
||||
struct stat stbuf;
|
||||
int orig_cwd_dfd;
|
||||
|
||||
if (argc < 2)
|
||||
{
|
||||
fprintf (stderr, "usage: ostree-prepare-root SYSROOT\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
root_mountpoint = argv[1];
|
||||
deploy_path = resolve_deploy_path (root_mountpoint);
|
||||
|
||||
/* Create a temporary target for our mounts in the initramfs; this will
|
||||
* be moved to the new system root below.
|
||||
*/
|
||||
snprintf (newroot, sizeof(newroot), "%s.tmp", root_mountpoint);
|
||||
if (mkdir (newroot, 0755) < 0)
|
||||
{
|
||||
perrorv ("Couldn't create temporary sysroot '%s': ", newroot);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* Work-around for a kernel bug: for some reason the kernel
|
||||
* refuses switching root if any file systems are mounted
|
||||
|
|
|
|||
Loading…
Reference in New Issue