Commit Graph

1458 Commits

Author SHA1 Message Date
Phaedrus Leeds
3aa9a7f3a1 app: Fix behavior when installing end-of-life-rebased ref
Currently if the user specifies a ref to install that has been renamed
via the end-of-life-rebased mechanism, for example "flatpak install
com.visualstudio.code.oss", Flatpak erroneously tries to install both
the old and new versions of the app. This happens because the code
handling end-of-life-rebase conditions is written assuming the rebased
app is being updated rather than installed for the first time.

Specifically, in FlatpakCliTransaction and FlatpakQuietTransaction, in
end_of_lifed_with_rebase(), we treat a failure of
flatpak_transaction_add_uninstall() as fatal and return FALSE from the
signal handler, which means that the install operation that triggered
the signal will not be skipped (see the docs for
FlatpakTransaction::end-of-lifed-with-rebase).

So, instead check for the FLATPAK_ERROR_NOT_INSTALLED error code and
ignore it, so that the installation of the old version of the renamed
app will be properly cancelled.

Fixes https://github.com/flatpak/flatpak/issues/3754
2021-11-15 11:13:51 +01:00
Phaedrus Leeds
17fbe516c4 build-update-repo: Don't try to generate deltas of unknown refs
Spotted this by code inspection. Ignoring such refs was clearly the
intended behavior based on the comment.
2021-11-15 10:55:50 +01:00
Phaedrus Leeds
86d6918a11 app: Don't use carriage return for non-fancy output
flatpak_fancy_output() determines whether the output we write is
intended for e.g. a tty or e.g. a log file, the latter being "not
fancy". Currently we write carriage return characters in the not fancy
case, but change that to new lines, which are interpreted correctly by
editors such as vim (whereas a carriage return shows up as ^M since it
is not the correct newline character on Unixy operating systems).
2021-11-15 09:57:09 +01:00
Phaedrus Leeds
39de0ef280 search: Use <bundle> ID to determine flatpak app ID
The <bundle> element in the appstream data unambiguously provides the
full four-part flatpak ref, so use it to determine the app ID. But fall
back to using the <id> element, since that is required to be present.
2021-11-15 09:54:56 +01:00
Phaedrus Leeds
62e09b406b search: Don't strip .desktop suffix overzealously
This commit changes the search command to properly output the app ID for
IDs that end in .desktop, e.g. to print org.telegram.desktop rather than
org.telegram.

Fixes https://github.com/flatpak/flatpak/issues/4535
2021-11-15 09:54:56 +01:00
gasinvein
30964d2bac build-init: Use SDK arch for SDK extensions...
...instead of the app we're building arch.
2021-10-21 13:03:45 +03:00
Ryan Gonzalez
86659a2bfb repair: Fix incorrect progress when refs are skipped
Issue was shown in this comment:

https://github.com/flatpak/flatpak/issues/3542#issuecomment-917497591
2021-09-17 09:25:29 +02:00
Phaedrus Leeds
f268f4a870 install: Avoid a superfluous prompt to choose the only remote
The install command can search available remotes for a specified flatpak
when a remote wasn't specified. In case only one remote is configured,
or in case only one of the configured remotes matches the ref specified,
we currently prompt the user to confirm use of the remote anyway (unless
-y/--assumeyes was used). Skip this prompt even when -y/--assumeyes was
not used, since the remote to use will still effectively be confirmed
when the list of refs to be installed is presented for confirmation.

Fixes https://github.com/flatpak/flatpak/issues/4364
2021-08-24 13:57:04 +01:00
Simon McVittie
17b6c31c7c Add missing G_GNUC_PRINTF attributes
This allows callers to be checked for mismatches between format string
and arguments, and also means gcc can assume that the format string and
the arguments match up correctly when forwarding them to functions
like g_strdup_vprintf, removing the need to suppress -Wformat-nonliteral
warnings.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:33:18 +02:00
Simon McVittie
0592caca8a completion: Always pass a format string to flatpak_completion_debug
In principle this could have been subject to a format string attack
via an argument containing %n, although in practice the code that uses
this format string is #if 0.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-05-25 10:33:18 +02:00
Alexander Larsson
515ae5e5df CLI: List arch if it is not the primary arch (even if unique)
Currenly we only list arch in the list of things to install from a
transaction if not all the refs are the same arch. It makes more sense
to show the arch even if its unique if they are not the primary arch.
2021-05-19 09:54:59 +02:00
Alexander Larsson
0a9d5ac7f2 Include more architectures when listing installed refs.
It turns out that we can't currently uninstall a ref from a
non-standard arch without specifying the arch even if there is no similar
ref installed for the main arch. (#4264)

The fundamental reason for this that `flatpak_dir_find_installed_ref(s)`
currently only returns refs with standard arches unless you explicitly
specify an arch.

This changes flatpak_dir_find_installed_refs() to always return
all the refs for all installed arches. This is generally what
we want anyway, except in the case of "flatpak run org.some.Platform" where
we don't want to prompt if there are multiple arches installed, so that
is manually changed.

This changes find_matching_ref() to look for refs in all arches, but
always prefer (without prompting) the default arch if that is installed.
This also matches what all current callers want.

Fixes #4264
2021-05-19 09:54:52 +02:00
Alexander Larsson
51ac8e1590 builtin-utils: Use shared helper
This uses the new flatpak_remote_state_ensure_subsummary_all_arches() helper
in ensure_remote_state_all_arches().
2021-05-19 09:49:30 +02:00
Alexander Larsson
540bcda3bd Transaction: Ensure we download the subsummary for the arch of added refs
By default we only download the main arch subsummary, so if you added
a ref for some other arch it failed to find the ref. This works with the
CLI, because it explicilty loads the subsummary when its trying to expand
the parial ref to the full ref. However apps using libflatpak don't do that
so they failed.
2021-05-19 09:49:30 +02:00
Phaedrus Leeds
404d7c6941 Fix several memory leaks 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
66d00e1c47 list: Add a g_assert() for a coverity warning 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
284510eabb remote-info: Fix memory leak of branch 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
75e60c5d8e remote-info: Fix printing of branch 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
1120c7cb24 Fix memory errors w/ use of var_arrayofstring_to_strv() 2021-05-04 10:23:13 +02:00
Phaedrus Leeds
bc27dcb518 remote-list: Check for unlikely libostree error 2021-05-04 10:23:13 +02:00
Alexander Larsson
0cd4656ea1 Add (and use) custom, high-perfomance prune implementation
This is an optimized version of ostree_repo_prune() specialized for
archive mode repos. It is faster and uses less memory so that we can
prune larger repos (like flathub) in a realistic timeframe.

The primary reason it is faster is that it creates and uses a
`.commitmeta2` file for each commit, containing information about what
objects are reachable from that commit. This means incremental prunes
need only traverse over newly created commits.

Secondly, it uses the variant parser compiled accessors for the
various GVariants that are involved in the prune which is quite a bit
faster, especially if the repo is very large.

It also merges the scan-for-all-objects and prune-unreachable objects
phases, which means that we don't have to allocate a hashtable for
all the objects in the entire repo saving a lot of memory.

To save memory the hashtable of reachable objects, which can be quite
big on a big repo, points to a custom, very compact format for object
names.

Additionally it does the scanning for reachable objects twice, first
with a shared lock and then again (if anything changed) it with an
exclusive lock. This allows us to avoid using an exclusive lock during
the slowest part of the prune.

Unfortunately there are currently no public APIs for the ostree repo
locks. We really need to take an exclusive lock during the whole prune
or we parallel modifications (say a commit) might get their newly
written objects deleted. To work around this we have a minimal custom
implementation of an exclusive lock. Once the public API is available
we can start using that.

I created a repo with a lot of small commits to test this.  It has 9M,
and pruning with depth=10 deletes 2M of them.

The original performance looks like:

 Finding reachable objects: 287 seconds
 Pruning unreachable: 69 seconds

Just using the pregenerated reachable data:

 Finding reachable objects: 15 seconds
 Pruning unreachable: 69 seconds

The final optimized prune (using pregenerated data):

 Finding reachable objects: 12 seconds
 Pruning unreachable: 51 seconds

The above are with the page caches cleaned, on a second run the performance
increase is even more noticeable.

As a comparison to the above, finding the reachable objects in the
actual flathub repo took 22 hours, but with the pregenerated reachable data
only 39 minutes.
2021-04-26 10:30:14 +02:00
Simon McVittie
12d7855493 enter: Make it clearer that rest_argv_start always gets initialized
scan-build complained that rest_argv_start could be used uninitialized,
because it can't see that rest_argc >= 2 implies that rest_argv_start
got initialized at the same time rest_argc was set. Make this easier
to understand.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
3071d2ada9 quiet-transaction: Remove unnecessary finalize
This hasn't done anything useful since 0978826c: it just takes a
new ref to the installation, and then releases that ref without doing
anything with it. Detected by scan-build.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
c26a48a9aa Fix various unused variables detected by scan-build
scan-build has a lot of false positives for this codebase because it
doesn't understand __attribute__((__cleanup__)) or GLib's GError
convention, but it seems to have been right about these.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-19 09:09:04 +02:00
Simon McVittie
c2490aad12 app: Use autocleanup for FlatpakTablePrinter
Fixes: https://github.com/flatpak/flatpak/issues/4223
Fixes: https://github.com/flatpak/flatpak/issues/4224
2021-04-16 14:51:47 +02:00
Simon McVittie
38eac07293 run: Create a shared XDG_RUNTIME_DIR for each app-ID
Like $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this is shared between all
instances of the app, except for subsandboxed instances created by
flatpak-spawn --sandbox or equivalent. Unlike
$XDG_RUNTIME_DIR/app/$FLATPAK_ID, it does not exist at an equivalent
path on the host and in the sandboxed app.

Resolves: https://github.com/flatpak/flatpak/issues/4120
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 09:13:18 +02:00
Simon McVittie
40510e8ae8 run: Populate XDG_RUNTIME_DIR with symlinks into /run/flatpak
If XDG_RUNTIME_DIR is under app control, as it will be with #4120, we
don't want to be mounting pieces of filesystem directly into it, because
that will mean that the app could create a symlink that will cause us
to create a mount point for it at the target of the symlink, potentially
elsewhere in the host filesystem.

Instead, we mount them in /run/flatpak, which is a per-instance
directory entirely controlled by Flatpak; and then create (relative)
symlinks in XDG_RUNTIME_DIR, pointing into /run/flatpak.

In this commit, we still know that the XDG_RUNTIME_DIR is a
per-instance tmpfs, so we can safely create the symlinks using
the --symlink option. In a subsequent commit this will change to
creating them in a shared XDG_RUNTIME_DIR, if any.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 09:13:18 +02:00
Simon McVittie
b65b3f6ead run: Share /tmp between all instances of an app-ID
This allows apps that use /tmp as an IPC rendezvous point, such as those
that embed Chromium-derived browsers, to communicate between instances;
this would not previously have worked without --filesystem=/tmp, which
is a significant weakening of the sandbox.

It also allows /tmp to be shared with subsandboxes (if they are not
sandboxed more strictly).

The temporary directory is actually created in XDG_RUNTIME_DIR,
to avoid it becoming visible to unrelated apps that happen to have
--filesystem=/tmp.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:00:47 +02:00
Simon McVittie
3ebf371fc2 run: Allow caller to replace /app and/or /usr
The pressure-vessel container tool in Steam will want to use this, to
replace /usr with a Steam Runtime container supplied by the Steam CDN,
instead of using the same Flatpak runtime that is used to run the Steam
client and non-containerized games.

If a custom /usr is used, the "official" Flatpak runtime is still the
one reflected in the metadata. It is also mounted at /run/parent,
with all its extensions, so that pressure-vessel has the option of using
its graphics drivers (by populating the custom /usr with symlinks into
/run/parent and/or /run/host).

When doing this, we need to put an empty directory on /app, because
the real /app expects to be run on top of the real runtime. It would
also be reasonable to substitute a custom replacement for /app, so
I've included support for that too.

Partially addresses #3797.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-07 09:52:50 +02:00
Simon McVittie
90aa6c9b79 flatpak_run_add_extension_args: Give caller more control
When we add a way to specify a different /usr for a subsandbox, we'll
want to mount the "official" runtime elsewhere and avoid adding it
to the LD_LIBRARY_PATH.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-07 09:52:50 +02:00
malbx
0a9253f7d9 history: Handle transaction log entry with empty REF field
This checks that the value of the REF field is not an empty string
before calling `flatpak_decomposed_new_from_ref`.  Attempting to
decompose an empty string leads to a validation error and prevents
any history from being printed.

Fixes https://github.com/flatpak/flatpak/issues/4121
2021-04-06 10:19:26 +02:00
Phaedrus Leeds
0bf8cf9a08 create-usb: Skip copying extra-data flatpaks
Currently the create-usb command copies extra-data flatpaks such as the
org.freedesktop.Platform.openh264 runtime extension along with normal
non-extra-data content. This is an issue because on the computer
installing from the USB it will attempt to get the extra-data content
from the URI specified in the commit metadata, which will fail if the
URI is a resource on the Internet and the computer is offline.

Instead, have create-usb omit such refs. If it was specified explicitly
this is treated as a hard error and if it's a dependency it's treated as
a warning, so that e.g. org.freedesktop.Platform can still be copied to
a USB and installed/updated offline. On the receiving end the absence of
org.freedesktop.Platform.openh264 will correctly not be treated as fatal
to the installation of org.freedesktop.Platform.

This issue was affecting offline updates of Endless OS, since such OS
updates include flatpaks along with the OS content.

For the (legally questionable) topic of properly supporting extra-data
distribution offline, see https://github.com/flatpak/flatpak/issues/969
2021-03-23 15:16:17 -07:00
Bastien Nocera
19b11ade73 app: Fix deprecation warning
The "new way" is supported since at least 2010 (!).

app/parse-datetime.y:302.1-12: warning: deprecated directive: ‘%pure-parser’, use ‘%define api.pure’ [-Wdeprecated]
  302 | %pure-parser
      | ^~~~~~~~~~~~
      | %define api.pure
2021-03-10 10:33:51 +01:00
Bastien Nocera
1941ddbdba app: Use bison to build parse-datetime.y
As it uses directives that POSIX yacc doesn't support:
app/parse-datetime.y:302.1-12: warning: POSIX Yacc does not support %pure-parser [-Wyacc]
  302 | %pure-parser
      | ^~~~~~~~~~~~
app/parse-datetime.y:307.1-7: warning: POSIX Yacc does not support %expect [-Wyacc]
  307 | %expect 31
      | ^~~~~~~
2021-03-10 10:33:51 +01:00
Alicia Boya García
03369d3f47 Expose TERM to flatpak enter
This is necessary to be able to use ncurses-based programs, such as
nano or gdb TUI.
2021-03-10 10:32:29 +01:00
Alicia Boya García
f39287d47f Let child process handle SIGINT in flatpak enter
Otherwise when running software that handles SIGINT, such as gdb or
python, pressing ^C would kill flatpak-enter and return control to the
shell.
2021-03-10 10:28:52 +01:00
Phaedrus Leeds
79a91b5cf6 Make flatpak --help output use consistent verbiage
Use present tense consistently rather than gerunds for some headings in
"flatpak --help". Also tweak flatpak(1) to use similar wording but with
gerunds.
2021-03-10 10:27:31 +01:00
Simon McVittie
9a61d2c44f build: Convert environment into a sequence of bwrap arguments
This means we can systematically pass the environment variables
through bwrap(1), even if it is setuid and thus is filtering out
security-sensitive environment variables. bwrap itself ends up being
run with an empty environment instead.

This fixes a regression when CVE-2021-21261 was fixed: before the
CVE fixes, LD_LIBRARY_PATH would have been passed through like this
and appeared in the `flatpak build` shell, but during the CVE fixes,
the special case that protected LD_LIBRARY_PATH was removed in favour
of the more general flatpak_bwrap_envp_to_args(). That reasoning only
works if we use flatpak_bwrap_envp_to_args(), consistently, everywhere
that we run the potentially-setuid bwrap.

Fixes: 6d1773d2 "run: Convert all environment variables into bwrap arguments"
Resolves: https://github.com/flatpak/flatpak/issues/4080
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=980323
Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-21 14:16:44 +01:00
Simon McVittie
bbf6debec2 Add an option to share the pid namespace with the parent flatpak
As with flatpak run --parent-expose-pids, this will only work if we have
a working, non-setuid bwrap. Systems where user namespace creation is
restricted and bwrap needs to be setuid (Debian 10, RHEL/CentOS 7,
Arch Linux linux-hardened kernel) will have degraded functionality.

This option is similar to --expose-pids, except that instead of making
the subsandbox use a nested pid namespace inside the parent's, it makes
the subsandbox share the parent's pid namespace as-is, so that process
IDs in the parent and the subsandbox are interchangeable. This will
be useful if the parent and the subsandbox communicate via protocols
that assume a global view of the process ID namespace, for example
passing process IDs across an AF_UNIX socket or in shared memory.

In particular, this will be useful for Steam's pressure-vessel container
tool: the IPC between the Steam client and the "game overlay" loaded into
Steam games uses process IDs, and becomes confused if they don't match up.

This weakens the security boundary between a subsandbox and the parent,
but that's OK in some cases, especially if the subsandbox is being used
as a way to get a different runtime /usr (flatpak-spawn --latest-version
or #4018) rather than as a security boundary.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-01-12 09:55:23 +01:00
Philip Withnall
9411fe2bca flatpak: Add --print-updated-env option to print environment
This is the environment needed to use flatpaks; a following commit will
hook this up to the systemd environment generator.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2020-12-22 14:21:54 +01:00
Phaedrus Leeds
91223477d4 app: Handle NULL flatpak_instance_get_app()
Gracefully handle flatpak_instance_get_app() returning NULL, which
happens for example when there is a shell in a runtime, e.g. flatpak run
--command=sh org.gnome.Platform
2020-12-21 09:11:08 +01:00
Haochen Tong
b0b42e70ff app: fix crash when killing a process without a name 2020-12-21 09:11:08 +01:00
Alexander Larsson
b3321e9179 extra-data: Resolve runtime from the target installation
When installing to an installation we need to find the runtime to use
for the apply-extra-data script from the installation we're targeting,
because that is the one that FlatpakTransaction guaranteed has the
required dependencies (although its possible they came from the
default dependency source too, i.e. the system repos).

In particular, we run into this issue if nothing is installed
anywhere, and then we install an extra-data app into a custom
directory. The transaction will download the runtime, and it
will not be anywhere else. Without this change flatpak only
looked for the dependency in the systam an regular user dirs
where it isn't.
2020-12-09 16:12:25 +01:00
Phaedrus Leeds
2a8602ed88 app: Swap order of rebase/uninstall calls
In case the second of these two fails, the first will still have been
added to the transaction. And since it's better to install the renamed
app but not uninstall the old one, than to uninstall the old one but not
install the new one, swap the order.

See also https://github.com/flatpak/flatpak/issues/3991
2020-12-09 09:03:31 +01:00
Alexander Larsson
c4d2d6f0a9 cli: Show branch in eol messages 2020-11-16 11:23:10 +01:00
Alexander Larsson
7eb5f4ddc8 cli-transaction: Better handling of EOL refs
We remember what action we took for EOLs, and for sub-refs (ie .Locale)
we reuse that.

Also, we show if eol:ed refs are pinned (as that makes them not be
auto-uninstalled), and we list the apps that use the eol:ed runtime
ref.

Example run:
```
Looking for updates…
Info: (pinned) org.gnome.Sdk.Compat.i386 is end-of-life, with reason:
   The GNOME 3.34 runtime is no longer supported as of 14th August 2020. Please ask your application developer to migrate to a supported platform.
Info: org.gnome.Platform is end-of-life, with reason:
   The GNOME 3.32 runtime is no longer supported as of 11th March 2020. Please ask your application developer to migrate to a supported platform.
Applications using this runtime:
   org.gnome.HexGL
```
2020-11-16 11:23:10 +01:00
Alexander Larsson
866d471d37 build-repo: Switch order of subset and options columns
The subset column is typically short, while for eol options the
options column can be very long. So, it makes more sense to have the
options at the end.
2020-11-14 11:12:28 +01:00
Alexander Larsson
60caa765de remote-list: Support showing the subset 2020-11-13 10:32:19 +01:00
Alexander Larsson
754e1fb5d4 Allow configuring the subset
This adds support to remote-add, remote-modify and the flatpakrepo file
parser.
2020-11-13 10:32:19 +01:00
Alexander Larsson
a679fd5787 remote-repo: Properly list subset info
We don't user subsummary names, but the highlevel summary names.
2020-11-13 10:32:19 +01:00