flatpak-builder icon indicating copy to clipboard operation
flatpak-builder copied to clipboard

Invalid argument from mkdir/install -d when using flatpak-builder on musl based distros

Open Cogitri opened this issue 5 years ago • 11 comments

Linux distribution and version

Alpine Linux Edge

Flatpak-builder version

1.0.9

Flatpak version

1.6.2

Description of the problem

Building anything that calls mkdir or install -d with flatpak-builder fails when using flatpak-builder on a musl based distro, during make install this happens:

/usr/bin/mkdir -p '/app/share/man/man8'
/usr/bin/mkdir: cannot create directory ‘/app’: Invalid argument

Steps to reproduce

This can be reproduced with the following Dockerfile:

FROM alpine:edge
RUN apk add flatpak-builder
RUN flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
RUN flatpak install -y org.freedesktop.Platform/x86_64/19.08 org.freedesktop.Sdk/x86_64/19.08
RUN git clone --recursive https://github.com/A6GibKm/ch.protonmail.protonmail-bridge builder
WORKDIR builder

Build it using: docker build -t flatpak-builder . with the Dockerfile in the same dir and run it with docker container run --privileged --cap-add SYS_ADMIN --cap-add MKNOD --device /dev/fuse -it --rm flatpak-builder flatpak-builder build ch.protonmail.protonmail-bridge.yaml. The build fails with:

Running: install -Dp -m 755 apply_extra /app/bin/apply_extra
install: cannot create directory '/app': Invalid argument

Cogitri avatar Feb 17 '20 21:02 Cogitri

Its something localized to your system considering the same manifest builds on flathubs servers fine.

TingPing avatar Feb 18 '20 01:02 TingPing

It appears that this happens for multiple Alpine users, so I don't think this is localized to my system - it might be to Alpine (as a host?) though. I'm not exactly sure where to dig for this though.

Cogitri avatar Feb 18 '20 17:02 Cogitri

I guess I missed the title, yeah musl or non-gnu coreutuils is likely relevant.

TingPing avatar Feb 19 '20 03:02 TingPing

Doesn't it use the tooling from the flatpak SDK though?

Cogitri avatar Feb 19 '20 10:02 Cogitri

It does. The problem here is FUSE, or rather something that causes it to behave differently with musl. Build should work fine if you pass --disable-rofiles-fuse to flatpak-builder. From strace:

stat("/app/bin/apply_extra", {st_mode=S_IFREG|0755, st_size=175, ...}) = 0
mkdir("/app", 0755)                     = -1 EEXIST (File exists)
openat(AT_FDCWD, ".", O_RDONLY)         = 3</run/build/protonmail-bridge>
chdir("/app")                           = -1 EINVAL (Invalid argument)

barthalion avatar Feb 19 '20 21:02 barthalion

Ah yes, it works fine with --disable-rofiles-fuse, thanks for the workaround :)

Cogitri avatar Feb 23 '20 13:02 Cogitri

I also can reproduce. Note that it breaks GNOME Builder.

necessarily-equal avatar Mar 07 '20 11:03 necessarily-equal

We'll just force-disable rofiles-fuse on Alpine for now, see https://gitlab.alpinelinux.org/alpine/aports/merge_requests/5738.

Cogitri avatar Mar 23 '20 21:03 Cogitri

I doubt it it related to musl. It is the syscall chdir that fails. Could it be a race condition? that /app is removed before chdir("/app") happens?

ncopa avatar Mar 24 '20 12:03 ncopa

Hm, this has only been reproducible on Alpine Linux and Void Linux Musl for me though

Cogitri avatar Mar 24 '20 12:03 Cogitri

It's literally first creating the directory it's trying chdir into, there is no threads that could snatch that dir before it's entered. The bug exposed by musl is rather in ostree (rofiles-fuse) or FUSE itself.

barthalion avatar Mar 26 '20 10:03 barthalion