Skip to content

Can't chdir() into directory #1407

Closed
Closed

Description

@chergert

When testing Builder on Atomic Workstation, I get an error where bwrap can't chdir() into a directory that exists.

I've not been able to track down why, so figured I'd ask here to see if you have any ideas.

flatpak build \
  --env=LANG=en_US.UTF-8 \
  --env=USER=christian \
  --env=HOME=/home/christian \
  --env=PATH=/usr/bin:/bin \
  --env=TERM=xterm-256color \
  --env=V=0 \
  --env=CCACHE_DIR=/home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/flatpak-builder/ccache \
  --env=PATH=/app/bin:/usr/bin \
  --share=network \
  --nofilesystem=host \
  --filesystem=/home/christian/.var/app/org.gnome.Builder/cache/gnome-builder \
  --filesystem=/home/christian/Projects/TestApp \
  --filesystem=/home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/builds/org.gnome.Testapp.json-local-flatpak-org.gnome.Platform-x86_64-master-master \
  --build-dir=/home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/builds/org.gnome.Testapp.json-local-flatpak-org.gnome.Platform-x86_64-master-master \
  --env=V=1 \
  '--env=CFLAGS=-O2 -g' \
  '--env=CXXFLAGS=-O2 -g' \
  --env=NOCONFIGURE=1 \
  /home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/flatpak/staging/flatpak:org.gnome.Platform-x86_64-master:master \
  meson /var/home/christian/Projects/TestApp . --prefix /app --libdir=lib

bwrap: Can't chdir to /home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/builds/org.gnome.Testapp.json-local-flatpak-org.gnome.Platform-x86_64-master-master: No such file or directory

The directory does exist.

[christian@localhost TestApp]$ test -d  /home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/builds/org.gnome.Testapp.json-local-flatpak-org.gnome.Platform-x86_64-master-master
[christian@localhost TestApp]$ echo $?
0

Activity

  1. chergert commented on Feb 12, 2018

    @chergert
    ContributorAuthor

    I should note that this only happens on Fedora Atomic Workstation, and is completely fine everywhere else I've tested (non-Atomic that is).

    /CC @cgwalters

  2. chergert commented on Feb 12, 2018

    @chergert
    ContributorAuthor

    I've noticed that this seems to be in relation to applying --build-dir. I also have learned that Atomic is using a symlink for home, to /var/home which could be related. Though I've adjusted paths to use /var/home and did not see any difference (along with --filesystem=/var/home).

    Perhaps it doesn't matter though, as I saw this from strace output.

    [pid  2223] mount("none", "/newroot/var", NULL, MS_NOSUID|MS_NODEV|MS_REMOUNT|MS_BIND|MS_RELATIME, NULL) = 0
    
  3. chergert commented on Feb 12, 2018

    @chergert
    ContributorAuthor

    I think this strace output shows that we are in fact stomping over --filesystem= provided that include /var.

    [pid  2555] mkdir("/newroot/var", 0755) = -1 EEXIST (File exists)
    [pid  2555] mount("/oldroot/var/home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/flatpak/staging/flatpak:org.gnome.Platform-x86_64-master:master/var", "/newroot/var", NULL, MS_BIND|MS_REC, NULL) = 0
    [pid  2555] lstat("/newroot", {st_mode=S_IFDIR|0755, st_size=460, ...}) = 0
    [pid  2555] lstat("/newroot/var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
    [pid  2555] openat(3, "self/mountinfo", O_RDONLY|O_CLOEXEC) = 5
    ...
    [pid  2555] mount("none", "/newroot/var", NULL, MS_NOSUID|MS_NODEV|MS_REMOUNT|MS_BIND|MS_RELATIME, NULL) = 0
    [pid  2555] mount("oldroot", "oldroot", NULL, MS_REC|MS_PRIVATE, NULL) = 0
    [pid  2555] umount2("oldroot", MNT_DETACH) = 0
    [pid  2555] unshare(CLONE_NEWUSER)      = 0
    ...
    [pid  2555] chdir("/newroot")           = 0
    [pid  2555] chroot("/newroot")          = 0
    [pid  2555] chdir("/")                  = 0
    ...
    [pid  2555] chdir("/var/home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/builds/org.gnome.Testapp.json-local-flatpak-org.gnome.Platform-x86_64-master-master") = -1 ENOENT (No such file or directory)
    
  4. alexlarsson commented on Feb 13, 2018

    @alexlarsson
    Member
    [pid  2223] mount("none", "/newroot/var", NULL, MS_NOSUID|MS_NODEV|MS_REMOUNT|MS_BIND|MS_RELATIME, NULL) = 0
    

    Just remounts that mountpoint nosuid,nodev,relatime which should be fine.

    Is any path element traversed when resolving /var/home/christian/.var/app/org.gnome.Builder/cache/gnome-builder/projects/TestApp/builds/org.gnome.Testapp.json-local-flatpak-org.gnome.Platform-x86_64-master-master an absolute symlink? Because those don't work during the bwrap setup phase (because the root is at /newroot).

  5. chergert commented on Feb 13, 2018

    @chergert
    ContributorAuthor
    [christian@localhost christian]$ ls -lsah /
    ...
       0 lrwxrwxrwx.   3 root root    8 Feb 11 18:27 home -> var/home
    ...
    
  6. alexlarsson commented on Feb 13, 2018

    @alexlarsson
    Member

    That is a relative link though, they should work fine.

  7. matthiasclasen commented on Feb 14, 2018

    @matthiasclasen
    Collaborator

    After staring at this some more, and talking to Colin, I've come to the conclusion that this is caused by flatpak setting up its own /var, and symlinks like home -> var/home getting resolved 'too late', when the world has changed underneath them.

    To confirm that theory, I changed my atomic ws to mount my home partition on /home, instead of mounting it on /var/home with a symlink. Sure enough, that makes the problem go away.

    Colin suggests that maybe the easiest flatpak-side fix would be to avoid /var, and maybe use /flatpak instead - would that be possible ?

  8. alexlarsson commented on Feb 14, 2018

    @alexlarsson
    Member

    Flatpak doesn't "use" /var for anything itself really, it just has to supply it in the sandbox due to applications expecting it to be there, for example for /var/tmp.

  9. cgwalters commented on Feb 14, 2018

    @cgwalters
    Collaborator

    This is probably the same issue as #1280 btw.

  10. cgwalters commented on Feb 14, 2018

    @cgwalters
    Collaborator

    Maybe what would work is to "reverse" symlinks - follow them to their destination, then mount that as the original target?

    In general though...for systems which want to "passthrough" the full host (AFAIK steam wants this), the only general solution may be to have it appear as /host which is a pattern we've come up with in Project Atomic for tools containers.

  11. alexlarsson commented on Feb 15, 2018

    @alexlarsson
    Member

    Oh, i see. This is specific to "flatpak build" which makes /var be the same as $builddir/var so that we can persist things in there...

  12. alexlarsson commented on Feb 15, 2018

    @alexlarsson
    Member

    This was actually a workaround for /var/home being a symlink:
    1aadc3e

  13. alexlarsson commented on Feb 15, 2018

    @alexlarsson
    Member

    Fucking symlinks, how do they work!

  14. added a commit that references this issue on Feb 15, 2018
  15. added a commit that references this issue on Feb 16, 2018
  16. added a commit that references this issue on Feb 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions