Commit Graph

17 Commits

Author SHA1 Message Date
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
cb47d83b72 run: Add option to share /dev/shm between instances of an app-ID
Similar to /tmp, applications might well use /dev/shm as an IPC
rendezvous between instances, which wouldn't have worked without
--device=shm until now.

Because /dev/shm has specific characteristics (in particular it's
meant to always be a tmpfs), we offload the actual storage into a
subdirectory of the real /dev/shm. Because /dev/shm is a shared
directory between all uids, we have to be extra-careful how we
do this, which is why the test coverage here is important.

This is done on an opt-in basis because of its extra complexity.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-16 08:57:20 +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
712efd3156 instance: Create and destroy per-app-ID subdirs of XRD/.flatpak
If we want to provide a per-app-ID XDG_RUNTIME_DIR (#4120) or a
per-app-ID /tmp or /dev/shm (#4093) then we'll need somewhere to put
them. Unlike $XDG_RUNTIME_DIR/app/$FLATPAK_ID, this should be somewhere
that is *not* accessible to the app, so that we can trust its contents.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-15 18:00:47 +02:00
Simon McVittie
be0e87df5d instance: Factor out flatpak_instance_get_instances_directory
The only functional change here is that we consistently use
flatpak_get_real_xdg_runtime_dir(), instead of a mixture of
the versions with and without realpath().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 11:53:23 +02:00
Simon McVittie
3393366877 common: Move flatpak_run_allocate_id() to flatpak-instance
This localizes knowledge of the internal structure of
$XDG_RUNTIME_DIR/.flatpak into the flatpak-instance module.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2021-04-06 11:53:23 +02:00
Phaedrus Leeds
c31dc54594 instance: Add missing nullable annotation 2020-12-21 09:11:08 +01:00
Ryan Gonzalez
1735d88f01 Clean up duplicated instance collection code
It was completely identical in flatpak-run.c and flatpak-instance.c.
2020-06-05 16:36:13 +02:00
Alexander Larsson
2f628d11ff Make flatpak_instance_new_for_id non-static
We want to use this from the portal
2019-11-27 14:21:25 +01:00
Matthew Leeds
e8816b7663 Remove extra newlines in variable definiton blocks
Uncrustify has an option "nl_func_var_def_blk" which is supposed to
ensure there's a newline character between the block of variable
definitions and the rest of the function body, but it gets confused and
thinks that the first instance of "g_autoptr" or "g_auto" being used on
a variable is the start of the function body. So this commit removes
those extra newline characters and removes that option in uncrustify.cfg
so they don't get re-added the next time uncrustify is run.

Here's the command I used:

perl -0777 -i -pe 's/\n(\n\s*g_auto\()/\1/g' `git ls-tree --name-only
-r HEAD | grep \\\.[ch]$ | grep -v common/valgrind-private.h |
grep -v app/flatpak-polkit-agent-text-listener\\\.[ch]`

I ran it again with "g_autoptr" in place of "g_auto", and made a few
manual edits to add back the newline when the g_auto* was in the middle
of a function body rather than at the top.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthew Leeds
8d962a686f Run uncrustify
I had to make a few manual edits but other than those the changes look
reasonable.

Closes: #2715
Approved by: matthiasclasen
2019-02-25 18:12:30 +00:00
Matthias Clasen
88d25970c7 Handle app-less instances better
FlatpakInstance was not dealing well with sandboxes
that don't have an application. In this case, the
metadata does not have an Application group, but
a Runtime group instead.

Closes: #2482
Approved by: matthiasclasen
2019-01-08 00:56:09 +00:00
Matthias Clasen
6daf195e42 Instance: mitigate races, add new launch api
Avoid the 3-second 'afterlife' of instances by using
kill (pid, 0) instead of checking the file lock. We
trade pid for lock races, but this seems more reliable.

Also add flatpak_installation_launch_full that returns
a FlatpakInstance for the launched app, and lets us
avoid races around killing the app, by using a child
watch.

Closes: #2221
Approved by: matthiasclasen
2018-10-23 07:15:39 +00:00
Matthew Leeds
d5b8266a09 instance: Fix gtk-doc warning 2018-10-17 14:23:20 -07:00
Matthias Clasen
83bb5b9c52 instance: Be more defensive in get_child_pid
There is a race; flatpak_installation_launch may return
before bubblewrap has written the bwrapinfo.json file.
Make flatpak_instance_get_child_pid() deal with this and
document that the function may return 0 for a little
while.
2018-10-10 12:21:15 +02:00
Matthias Clasen
dd546ad365 Make FlatpakInstance api public
This can be of use in frontends like GNOME Software.

Closes: #2201
Approved by: alexlarsson
2018-10-08 08:36:23 +00:00
Matthias Clasen
336f887289 Add an instance api
This is made to let gnome-software enumerate all
running instances and get the same information
about them that flatpak ps provides.

For now, we keep it private. It will become library
api once we open new development
2018-09-03 11:54:19 -04:00