mirror of
https://github.com/flatpak/flatpak.git
synced 2026-04-16 13:00:48 -04:00
run: Add --instance-id-fd
This commit is contained in:
committed by
Alexander Larsson
parent
4d1899b1d7
commit
f687f6b2eb
@@ -537,7 +537,7 @@ flatpak_builtin_build (int argc, char **argv, GCancellable *cancellable, GError
|
||||
runtime_ref,
|
||||
app_id_dir, app_context, NULL,
|
||||
FALSE, TRUE, TRUE,
|
||||
&app_info_path,
|
||||
&app_info_path, 0,
|
||||
&instance_id_host_dir,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
@@ -57,6 +57,7 @@ static char *opt_commit;
|
||||
static char *opt_runtime_commit;
|
||||
static int opt_parent_pid;
|
||||
static gboolean opt_parent_expose_pids;
|
||||
static int opt_instance_id_fd = -1;
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to use"), N_("ARCH") },
|
||||
@@ -81,6 +82,7 @@ static GOptionEntry options[] = {
|
||||
{ "die-with-parent", 'p', 0, G_OPTION_ARG_NONE, &opt_die_with_parent, N_("Kill processes when the parent process dies"), NULL },
|
||||
{ "parent-pid", 0, 0, G_OPTION_ARG_INT, &opt_parent_pid, N_("Use PID as parent pid for sharing namespaces"), N_("PID") },
|
||||
{ "parent-expose-pids", 0, 0, G_OPTION_ARG_NONE, &opt_parent_expose_pids, N_("Make processes visible in parent namespace"), NULL },
|
||||
{ "instance-id-fd", 0, 0, G_OPTION_ARG_INT, &opt_instance_id_fd, N_("Write the instance ID to the given file descriptor"), NULL },
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
@@ -310,6 +312,7 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
|
||||
opt_command,
|
||||
&argv[rest_argv_start + 1],
|
||||
rest_argc - 1,
|
||||
opt_instance_id_fd,
|
||||
NULL,
|
||||
cancellable,
|
||||
error))
|
||||
|
||||
@@ -705,7 +705,7 @@ flatpak_installation_launch_full (FlatpakInstallation *self,
|
||||
run_flags,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL, 0,
|
||||
NULL, 0, 0,
|
||||
&instance_dir,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
@@ -164,6 +164,7 @@ gboolean flatpak_run_add_app_info_args (FlatpakBwrap *bwrap,
|
||||
gboolean build,
|
||||
gboolean devel,
|
||||
char **app_info_path_out,
|
||||
int instance_id_fd,
|
||||
char **host_instance_id_host_dir_out,
|
||||
GError **error);
|
||||
|
||||
@@ -179,6 +180,7 @@ gboolean flatpak_run_app (const char *app_ref,
|
||||
const char *custom_command,
|
||||
char *args[],
|
||||
int n_args,
|
||||
int instance_id_fd,
|
||||
char **instance_dir_out,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
|
||||
@@ -2198,6 +2198,7 @@ flatpak_run_add_app_info_args (FlatpakBwrap *bwrap,
|
||||
gboolean build,
|
||||
gboolean devel,
|
||||
char **app_info_path_out,
|
||||
int instance_id_fd,
|
||||
char **instance_id_host_dir_out,
|
||||
GError **error)
|
||||
{
|
||||
@@ -2372,6 +2373,38 @@ flatpak_run_add_app_info_args (FlatpakBwrap *bwrap,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* NOTE: It is important that this takes place after bwrapinfo.json is created,
|
||||
otherwise start notifications in the portal may not work. */
|
||||
if (instance_id_fd != -1)
|
||||
{
|
||||
gsize instance_id_position = 0;
|
||||
gsize instance_id_size = strlen (instance_id);
|
||||
|
||||
while (instance_id_size > 0)
|
||||
{
|
||||
gssize bytes_written = write (instance_id_fd, instance_id + instance_id_position, instance_id_size);
|
||||
if (G_UNLIKELY (bytes_written <= 0))
|
||||
{
|
||||
int errsv = bytes_written == -1 ? errno : ENOSPC;
|
||||
if (errsv == EINTR)
|
||||
continue;
|
||||
|
||||
close (fd);
|
||||
close (fd2);
|
||||
close (fd3);
|
||||
|
||||
g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv),
|
||||
_("Failed to write to instance id fd: %s"), g_strerror (errsv));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
instance_id_position += bytes_written;
|
||||
instance_id_size -= bytes_written;
|
||||
}
|
||||
|
||||
close (instance_id_fd);
|
||||
}
|
||||
|
||||
flatpak_bwrap_add_args_data_fd (bwrap, "--info-fd", fd3, NULL);
|
||||
|
||||
if (app_info_path_out != NULL)
|
||||
@@ -3483,6 +3516,7 @@ flatpak_run_app (const char *app_ref,
|
||||
const char *custom_command,
|
||||
char *args[],
|
||||
int n_args,
|
||||
int instance_id_fd,
|
||||
char **instance_dir_out,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
@@ -3801,7 +3835,8 @@ flatpak_run_app (const char *app_ref,
|
||||
app_ref_parts[1], app_ref_parts[3],
|
||||
runtime_ref, app_id_dir, app_context, extra_context,
|
||||
sandboxed, FALSE, flags & FLATPAK_RUN_FLAG_DEVEL,
|
||||
&app_info_path, &instance_id_host_dir, error))
|
||||
&app_info_path, instance_id_fd, &instance_id_host_dir,
|
||||
error))
|
||||
return FALSE;
|
||||
|
||||
if (!flatpak_run_add_dconf_args (bwrap, app_ref_parts[1], metakey, error))
|
||||
|
||||
@@ -569,6 +569,14 @@ key=v1;v2;
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--instance-id-fd</option></term>
|
||||
|
||||
<listitem><para>
|
||||
Write the instance ID string to the given file descriptor.
|
||||
</para></listitem>
|
||||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--file-forwarding</option></term>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user