Commit Graph

810 Commits

Author SHA1 Message Date
Alexander Larsson
eaa780ea63 ld.so.cache: Fix order of extension libs
We include the app extension ld.so.conf files before the app
and after that the runtime extension conf files.

This matches what is described in https://github.com/flatpak/flatpak/issues/1075

Closes: #1076
Approved by: alexlarsson
2017-10-04 15:13:13 +00:00
Alexander Larsson
aa28d9c7b4 run: Make extension ld.so.conf files have nicer numbering
We were creating names for all extensions, even those that did
not get a ld.so.conf file created, so the count in was weirdly
inconsistent.

Closes: #1076
Approved by: alexlarsson
2017-10-04 15:13:13 +00:00
Alexander Larsson
129ab559ee Strip some more common environment variables from the host
We strip PYTHONPATH, PERLLIB, PERL5LIB and XCURSOR_PATH from the
environment in the sandbox, because these kind of path variables
can badly affect the sandbox (e.g. pulling in host-side code).

Closes: #1078
Approved by: alexlarsson
2017-10-04 15:12:30 +00:00
Philip Withnall
166a4e144d common: Don’t commit arbitrary files into the ostree-metadata branch
When building the ostree-metadata branch (which only happens when
configured with --enable-p2p), we are supposed to create empty commits
which contain only metadata. However, the code to do this was wrong, and
was instead pulling in all the files from the current working directory
and committing them.

Fix that code to actually create an empty commit.

This could have been a fairly serious bug were it not for the fact that
nobody’s using this code because it’s all experimental.

Spotted as part of https://github.com/ostreedev/ostree/pull/1158.

Signed-off-by: Philip Withnall <withnall@endlessm.com>

Closes: #1066
Approved by: alexlarsson
2017-10-04 12:54:30 +00:00
Matthew Leeds
71f4a87f51 dir: Print debug output when opening flatpak dirs
It's easy to end up with multiple flatpak installations on a system, and
it's not always clear which one(s) flatpak is using. So this commit adds
some debug output in some cases when flatpak opens an installation
directory such as /var/lib/flatpak. This is especially important for
people who build flatpak themselves because if you omit --prefix=/usr
or use --with-system-install-dir your flatpak will look in non-standard
locations like /usr/local/var/lib/flatpak.

If we were to print this every time a flatpak directory is opened, it
would flood the log. So instead add a utility function and use it
strategically. Many flatpak commands will log the directory when they
use flatpak_option_context_parse(), others in
flatpak_find_deploy_for_ref(), and for others the logging has been
added manually.

Closes: #1067
Approved by: alexlarsson
2017-10-04 12:39:43 +00:00
Valentin David
845a0b3bf7 Use ld.so.cache instead of LD_LIBRARY_PATH (when not building)
Instead of setting LD_LIBRARY_PATH to make the app load the right
libraries we run ldconfig to generate a ld.so.cache that we feed
to the sandbox as /etc/ld.so.cache. The cache itself is generated
by running ldconfig at run time, but for apps we cache the
result in $HOME/.var/app/$APPID/.ld.so/cache based on the
current app/runtime/extensions commit ids.

We also unset LD_LIBRARY_PATH, to ensure any host-side value
does not mess with the sandbox.

The default ld.so.conf we set (if the runtime has none, or an empty
one) is:

 include /run/flatpak/ld.so.conf.d/*.conf
 include /app/etc/ld.so.conf
 /app/lib

Additionally all the extension points that have add_ld_path set gets a
ld.so.conf snippet in /run/flatpak/ld.so.conf.d.

This allows applications and extensions to install their own paths if
needed, and if the runtime wants more location they can install a
custom ld.so.conf that includes the above.

In the flatpak build case we still use LD_LIBRARY_PATH like before,
because there is no good key (like the commit ids) for keeping the
cache up-to-date. Also, the behaviour is different when building an
app for instance. If /app/lib is not in LD_LIBRARY_PATH then the
sandbox-wide /etc/ld.so.cache must be updated for a newly installed
library to work, but the sandbox is not allowed to update
/etc/ld.so.cache.

This code was originally written by Valentin David <valentin.david@gmail.com>
with changes by Alexander Larsson <alexl@redhat.com>.

Closes: #1073
Approved by: alexlarsson
2017-10-04 10:27:14 +00:00
Alexander Larsson
f06cae1556 run: Break out /usr link creation to helper
This is the code needed to set up the symlinks into the runtime
to make stuff work. We will need this separately for minimal runtime
use.

Closes: #1073
Approved by: alexlarsson
2017-10-04 10:27:14 +00:00
Alexander Larsson
5cd8db035b common: Add flatpak_switch_symlink_and_remove
This creates a symlink pointing to a target, but if the symlink
already exists, it ensures (atomically) that the previous target
is deleted. This is useful to keep a single-item cache around.

Closes: #1073
Approved by: alexlarsson
2017-10-04 10:27:14 +00:00
Alexander Larsson
73f44dd656 Add extensions to /.flatpak-info
This fixes https://github.com/flatpak/flatpak/issues/502

Closes: #1069
Approved by: alexlarsson
2017-10-03 08:01:46 +00:00
Alexander Larsson
acdf869693 common: Add commit id to FlatpakExtension
Closes: #1069
Approved by: alexlarsson
2017-10-03 08:01:46 +00:00
Alexander Larsson
f04bc43eef Add commit ids for app and runtime to /.flatpak-info
Closes: #1069
Approved by: alexlarsson
2017-10-03 08:01:46 +00:00
Alexander Larsson
0ab0e94647 Add flatpak_deploy_get_deploy_data helpers
Closes: #1069
Approved by: alexlarsson
2017-10-03 08:01:46 +00:00
Alexander Larsson
1fbdda5d0e run: Add some helpers to add fds to the argv array
This cleans up a bunch of repeated code.
2017-10-02 14:53:04 +02:00
Sam Spilsbury
d0af046a2f system-helper: Add PruneLocalRepo method
We might want to prune the repo from within the library or
the command line and may not be in a privileged context, so
we'll need to jump through the system helper to prune the refs.

Closes: #1034
Approved by: alexlarsson
2017-09-28 15:39:05 +00:00
Sam Spilsbury
27a76acb5d dir: Don't prune refs immediately after calling flatpak_dir_remove_ref
It might be more efficient to perform this operation at the end of
removing a batch of refs, so perform it there instead.

Closes: #1034
Approved by: alexlarsson
2017-09-28 15:39:05 +00:00
Sam Spilsbury
96b4c5ed13 dir: Add gtkdoc comment for flatpak_dir_remove_ref
Closes: #1034
Approved by: alexlarsson
2017-09-28 15:39:05 +00:00
Sam Spilsbury
f05e87d6bf dir: No need to query remote in filter_out_deployed_refs
Closes: #1034
Approved by: alexlarsson
2017-09-28 15:39:05 +00:00
Sam Spilsbury
284138fa61 dir: Add FindMatchingRefsFlags flag argument find_matching_refs
In some cases, we want to include the repo part of the refspec,
for instance, if we are to pass refs directly to flatpak_dir_remove_ref

Closes: #1034
Approved by: alexlarsson
2017-09-28 15:39:05 +00:00
Sam Spilsbury
3f91b4d883 system-helper: Add RemoveLocalRef helper function
This depends on the modify-repo privilege

Closes: #1034
Approved by: alexlarsson
2017-09-28 15:39:05 +00:00
Sam Spilsbury
99611aed52 dir: Add flatpak_dir_cleanup_undeployed_refs
This can be used to remove any undeployed refs from the local repo
in order to save on disk space.

Closes: #1034
Approved by: alexlarsson
2017-09-28 15:39:05 +00:00
Colin Walters
747f66158d tree-wide: Bump libglnx
A few fixes worth having, also just testing Homu.

```
Colin Walters (2):
      fdio: Open target dirname for glnx_file_copy_at()
      lockfile: Use an `initialized` member rather than explicit init

Jonathan Lebon (1):
      macros: use size_t for glnx_strjoina len

Philip Withnall (1):
      shutil: Fix assertion failure in glnx_shutil_mkdir_p_at()
```

Closes: #1046
Approved by: alexlarsson
2017-09-27 18:53:46 +00:00
Alexander Larsson
69d7474bcd Don't lock the system repo when pulling to a child repo
This causes permission denied when installing to the system
repo using the helper.
2017-09-26 23:24:18 +02:00
Alexander Larsson
a265436574 run: Fix exporting the homedir if also exporting host
The FAKE_MODE_DIR support did not work correctly because of
a MAX() with a fallback value of 0, which is greater than
FAKE_MODE_DIR.
2017-09-26 20:12:19 +02:00
Alexander Larsson
b35177e4bf appstream update: Don't skip all arches if one is unchanged
Move skip_commit from a function global to a per-loop variable so
that it is reset for each architecture.
2017-09-26 16:34:30 +02:00
Alexander Larsson
c3cfc4aa78 Remove unused variables 2017-09-26 11:58:44 +02:00
Alexander Larsson
557803309b Disable min-free-space-percent by default
To many people are running into issues with this in the wild. We now
set this to zero by default. You can still manually override this.
2017-09-25 16:25:20 +02:00
Alexander Larsson
08aef072c9 Change how exposing symlinks are handled, allowing $HOME to be a symlink
We used to only expose symlinks if the path to one was explicitly exposed,
like --filesystem=/symlink, but if you did say --filesystem=/symlink/dir, then
we would make /symlink be a regular directory in the sandbox tmpfs.

This means all exports are fully resolved, which allows use to remove the
workaround for symlinks that we had with sorting by "level".

We also add a FAKE_MODE_DIR, which is used to ensure the homedir is there,
created on tmpfs if needed only, while handling symlinks correctly.

This means that flatpak works well even if $HOME is on a symlink.
2017-09-25 14:30:03 +02:00
Alexander Larsson
f1df5cb1d9 run: Fix some symlink handling issues
If the target of a direct bind, such as $home/.var/app/$appid/ is
a symlink, and the symlink contains absolute pathnames, then they
will not resolve correctly in the bwrap setup code due to the
fact that the final root is on /newroot, not /, so we resolve
the target paths before we call bwrap.
2017-09-25 14:08:19 +02:00
Alexander Larsson
5ca82643d2 flatpak-run: Correctly handle symlinks in flatpak_exports_path_is_visible
When we're resolving a symlink to see if the destination is visible, then
we have to actually append the rest of the path to look at the final
target, not just the intermediate symlinked directory.
2017-09-25 14:05:52 +02:00
Alexander Larsson
6d5beff5d3 Don't allow manual exports of /dev. These are handled by --dev= 2017-09-25 14:03:56 +02:00
Alexander Larsson
ac5f17203f Handle ~/.local/share/flatpak being a symlink
When we hide a directory like that and it is a symlink we need
to hide the symlink target. Additionally, when we're checking
whether we need to mount the tmpfs we need to check that the
target is an actual dir, rather than a symlink to a dir.

Fixes https://github.com/flatpak/flatpak/issues/1032
2017-09-25 11:05:32 +02:00
Alexander Larsson
c48d8f427f Add a repo-lock that protects against object removal
This is taken in exclusive mode whenever we prune the repo. Anything
that is not protected against object disappearing from the repo can
take the lock in a shared mode to avoid running at the same
time as a prune operation.

The two operations the are problematic in this respect is
Pull:
 * During the pull we see that some object we require is already available
   and doesn't need downloading. We can't have it be removed before we
   commit the transaction.
 * During the transaction commit we're moving the object to the
   repo, and they risk being pruned as unreachable until we have updated
   the ref.
Deploy:
 * Once we start checking out a particular ref we assume all the object
   from it is reachable. If the ref is updated in parallel some object
   can become unreachable and removed.

So, we take shared locks in these operations.

In the prune operation we take the block non-blocking, and skip
the prune entirely if some other operation is outstanding, because
we don't want to block a long time, and its likely that due to the other
operation we will run prune shortly anyway.

Note: Nothing protects the system-helper case when we download to a separate
repo. However, if there is a race we will get an error when importing this
to the system repo, so we'll never end up in an inconsistent state.
2017-09-22 16:35:18 +02:00
Alexander Larsson
98d3a58129 Update to latest libglnx and update tmpfile use for api change 2017-09-22 12:38:10 +02:00
Alexander Larsson
440389bc8e Add locale-subset property of extensions to match *.Locale behaviour
This way other types of extensions can also be subset by locale.
For instance, documentation.
2017-09-21 16:39:53 +02:00
Alexander Larsson
3e86ee750b run: Ensure the font cache dirs are never writable
Otherwise, if the host dirs don't exist we could end
up with a writable non-persistent directory where fontconfig
writes its caches.
2017-09-20 17:36:03 +02:00
Sam Spilsbury
e72d4b8172 dir: Factor out find_ref_for_refs_set 2017-09-20 09:07:18 +02:00
Sam Spilsbury
7be94770e3 builtins: Correctly support --no-pull option in install command
Previously we would still try to look up the remote information
to get the correct ref, this might not be supported in a case where
the user does not have an internet connection at the time that
applications are to be installed from the local repository.
2017-09-20 09:07:18 +02:00
Sam Spilsbury
0802d169bd dir: Add flatpak_dir_find_local_ref
Same thing as flatpak_dir_find_remote_ref except that it operates
on the local repo instead of the remote one.
2017-09-20 09:07:18 +02:00
Alexander Larsson
07d62fb86e generate_appstream: Add debug output when skipping commit
This might help us debug a weird behaviour on flathub where
it was never updating the appstream.
2017-09-19 16:34:26 +02:00
Alexander Larsson
66df733814 Expose fontconfig caches as well as fonts
This is the first step in increasing the startup performance for
font use in flatpak. Right now every app has its own cache
for the system font dirs, which means they must be fully regenerated
the first time the app starts.

With this we now expose the host system and per-use fontconfig caches
in the sandbox (read-only). This allows the sandbox to re-use caches
from the host, if the runtime fontconfig configuration is correct.

Unfortunately, this doesn't currently work, because the font caches
are looked up based on absolute paths to the font directories and they
are different in the host and the sandbox. There is some work in
progress to fix this in fontconfig here:
 https://bugs.freedesktop.org/show_bug.cgi?id=101889
2017-09-19 12:39:35 +02:00
Alexander Larsson
7eece97d3c build: Add --with-appdir
If specified, this exposes the ~/.var/app/$appid to the build
sandbox. Useful when testing uninstalled builds.
2017-09-19 11:52:27 +02:00
Philip Withnall
2faffecc42 common/utils: Fix is_number("") to return FALSE
Previously, it was possible to enter ‘ ’ (a space) at a number prompt,
and it would be stripped, passed to is_number() (which would erroneously
return TRUE), then passed to strtol() and the return value used
unconditionally.

Fix that by fixing is_number() to return FALSE for the empty string.

Signed-off-by: Philip Withnall <withnall@endlessm.com>
2017-09-18 15:36:24 +02:00
Alexander Larsson
2d0ceef446 flatpak_installed_ref_load_metadata: Find correct deploy directory
We're scoping the deploy directory by the subpaths these days, so
we need to take that into account when finding the metadata file.

Fixes https://github.com/flatpak/flatpak/issues/1014
2017-09-15 16:02:50 +02:00
Alexander Larsson
75c2db1a73 Fix some leaks
g_variant_dict_end() returns a floating reference, we have to
sink it before using it with a g_autoptr.
2017-09-14 13:07:12 +02:00
Alexander Larsson
40126c3e6f Fix crash when installing extra-data
We pass FLATPAK_RUN_FLAG_NO_A11Y_BUS_PROXY when running the
sandboxed apply_extra_data script, because otherwise we run into
a crash due to the lack of an .flatpak-info file (and also, because
it is not needed).
2017-09-14 08:55:30 +02:00
Alexander Larsson
1ee74fc5ea Expose host icons readonly in sandbox
Icons are really only a bunch of pngs, and the icon theme specification
has been stable since forever and never broke ABI. So, exposing the
host fonts should be pretty safe, comparable to the fonts that we
already expose.

This ends up being kind of important since a lot of things pick up the
icon theme from the host. In particular, it means that libXcursor can pick up
the correct cursor icons for the current cursor theme.
2017-09-13 14:54:49 +02:00
Alexander Larsson
4e97018bc6 Properly check the tmp dir mode
This was using a boolean && instead of a bitwise mask. Reported
by covertity.
2017-09-13 12:11:51 +02:00
Alexander Larsson
0b1e45c47f Add comment about why we're allowing xa.ref discrepancies sometimes
See https://github.com/flatpak/flatpak/pull/1013 for discussion.
2017-09-13 11:56:59 +02:00
Cosimo Cecchi
643f9d6e14 dir: relax requirements around xa.ref matching deployed commit
In case the summary file is GPG-signed, we already have other better
ways of verifying expectations around the installed ref.
If the deployed branch does not match xa.ref, simply warn instead of
aborting.

Based on a patch by Dan Nicholson <nicholson@endlessm.com>
2017-09-13 11:45:00 +02:00
Matthew Leeds
037a13cde0 completion: Make filename completions smarter
Many flatpak commands only work on *.flatpak or *.flatpakref files, so
the bash auto completion showing every file is distracting and
unnecessary. This commit makes flatpak only show relevant files when
possible by using the "-G globpattern" compgen option.
2017-09-12 16:14:43 +02:00