run: Add --usr-fd and --app-fd options

Exposes options to pass in a fd for the runtime and app deploy. The
flatpak portal will make use of this in a following commit.
This commit is contained in:
Sebastian Wick
2026-02-06 20:55:46 +01:00
committed by Sebastian Wick
parent 873ed8b371
commit 494c5ea687

View File

@@ -60,7 +60,9 @@ static gboolean opt_parent_expose_pids;
static gboolean opt_parent_share_pids;
static int opt_instance_id_fd = -1;
static char *opt_app_path;
static int opt_app_fd = -1;
static char *opt_usr_path;
static int opt_usr_fd = -1;
static GOptionEntry options[] = {
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, N_("Arch to use"), N_("ARCH") },
@@ -88,7 +90,9 @@ static GOptionEntry options[] = {
{ "parent-share-pids", 0, 0, G_OPTION_ARG_NONE, &opt_parent_share_pids, N_("Share process ID namespace with parent"), 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 },
{ "app-path", 0, 0, G_OPTION_ARG_FILENAME, &opt_app_path, N_("Use PATH instead of the app's /app"), N_("PATH") },
{ "app-fd", 0, 0, G_OPTION_ARG_INT, &opt_app_fd, N_("Use FD instead of the app's /app"), N_("FD") },
{ "usr-path", 0, 0, G_OPTION_ARG_FILENAME, &opt_usr_path, N_("Use PATH instead of the runtime's /usr"), N_("PATH") },
{ "usr-fd", 0, 0, G_OPTION_ARG_INT, &opt_usr_fd, N_("Use FD instead of the runtime's /usr"), N_("FD") },
{ NULL }
};
@@ -311,7 +315,18 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
if (!opt_session_bus)
flags |= FLATPAK_RUN_FLAG_NO_SESSION_BUS_PROXY;
if (opt_app_path != NULL)
if (opt_app_fd >= 0 && opt_app_path != NULL)
{
flatpak_fail_error (error, FLATPAK_ERROR,
_("app-fd and app-path cannot both be used"));
return FALSE;
}
if (opt_app_fd >= 0)
{
app_fd = opt_app_fd;
}
else if (opt_app_path != NULL)
{
if (g_strcmp0 (opt_app_path, "") == 0)
{
@@ -330,7 +345,18 @@ flatpak_builtin_run (int argc, char **argv, GCancellable *cancellable, GError **
app_fd = FLATPAK_RUN_APP_DEPLOY_APP_ORIGINAL;
}
if (opt_usr_path != NULL)
if (opt_usr_fd >= 0 && opt_usr_path != NULL)
{
flatpak_fail_error (error, FLATPAK_ERROR,
_("usr-fd and usr-path cannot both be used"));
return FALSE;
}
if (opt_usr_fd >= 0)
{
usr_fd = opt_usr_fd;
}
else if (opt_usr_path != NULL)
{
usr_fd = open (opt_usr_path, O_PATH | O_CLOEXEC | O_NOFOLLOW);