Skip to content
Snippets Groups Projects
wrap-interactive.c 3.96 KiB
/*
 * Copyright © 2017-2019 Collabora Ltd.
 *
 * SPDX-License-Identifier: LGPL-2.1-or-later
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, see <http://www.gnu.org/licenses/>.
 */

#include "wrap-interactive.h"

#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

#include <glib/gstdio.h>

void
pv_bwrap_wrap_in_xterm (FlatpakBwrap *wrapped_command)
{
  g_return_if_fail (wrapped_command != NULL);

  flatpak_bwrap_add_args (wrapped_command,
                          "xterm", "-e",
                          /* Original command will go here and become
                           * the argv of xterm -e */
                          NULL);
}

void
pv_bwrap_wrap_interactive (FlatpakBwrap *wrapped_command,
                           PvShell shell)
{
  static const char preamble[] =
    {
      "prgname=\"$1\"\n"
      "shift\n"
    };
  const char *script = "";
  static const char start_shell[] =
    {
      "echo\n"
      "echo\n"
      "echo\n"
      "echo \"$1: Starting interactive shell (original command is in "
      "\\\"\\$@\\\")\"\n"
      "echo\n"
      "echo\n"
      "echo\n"
      "exec bash -i -s \"$@\"\n"
    };
  gchar *command;

  g_return_if_fail (wrapped_command != NULL);

  switch (shell)
    {
      case PV_SHELL_NONE: