[gnome-builder] fusremount: add fusermount wrapper



commit 7f323e9fb1a2945ed0479d5bb55dbc914da9297a
Author: Christian Hergert <chergert redhat com>
Date:   Thu Apr 12 01:28:24 2018 -0700

    fusremount: add fusermount wrapper
    
    This allows us to have a wrapper to call fusermount on the host from inside
    of our Flatpak bundle. The idea is to allow us to get the help from ostree
    rofiles which requires fusermount to unmount things.

 meson.build                               |  1 +
 meson_options.txt                         |  1 +
 src/{host-exec.c => fusermount-wrapper.c} | 42 +++++++++++++++++++++++--------
 src/meson.build                           |  7 +++---
 4 files changed, 36 insertions(+), 15 deletions(-)
---
diff --git a/meson.build b/meson.build
index 15f7ec7fc..7a1b523a2 100644
--- a/meson.build
+++ b/meson.build
@@ -70,6 +70,7 @@ status += [
   'Tracing ............... : @0@'.format(get_option('enable_tracing')),
   'Profiling ............. : @0@'.format(get_option('enable_profiling')),
   'RDTSCP ................ : @0@'.format(get_option('enable_rdtscp')),
+  'fusermount ............ : @0@'.format(get_option('fusermount_wrapper')),
   '',
   'Help Docs ............. : @0@'.format(get_option('with_help')),
   'API Docs .............. : @0@'.format(get_option('with_docs')),
diff --git a/meson_options.txt b/meson_options.txt
index 03e386b06..84b4094b5 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,6 +1,7 @@
 option('enable_tracing', type: 'boolean', value: false, description: 'Enable tracing of internals for 
troubleshooting Builder')
 option('enable_profiling', type: 'boolean', value: false, description: 'Enable profiling of the Builder 
codebase')
 option('enable_rdtscp', type: 'boolean', value: false, description: 'High performance counters')
+option('fusermount_wrapper', type: 'boolean', value: false, description: 'Install fusermount-wrapper when 
distributing with flatpak')
 
 option('with_safe_path', type: 'string', value: '', description: 'PATH variable to run build commands 
(default: platform-specific)')
 option('with_channel',
diff --git a/src/host-exec.c b/src/fusermount-wrapper.c
similarity index 81%
rename from src/host-exec.c
rename to src/fusermount-wrapper.c
index 8c349bd8e..a3fded7d9 100644
--- a/src/host-exec.c
+++ b/src/fusermount-wrapper.c
@@ -1,4 +1,4 @@
-/* host-exec.c
+/* fusermount-wrapper.c
  *
  * Copyright 2018 Christian Hergert <chergert redhat com>
  *
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include <errno.h>
 #include <ide.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -28,6 +29,25 @@
 
 static gint exit_code;
 
+static gboolean
+parse_fd (const gchar *str,
+          gint        *fd)
+{
+  gint64 v = g_ascii_strtoll (str, NULL, 10);
+
+  *fd = -1;
+
+  if (v < 0 || v > G_MAXINT)
+    return FALSE;
+
+  if (v == 0 && errno == EINVAL)
+    return FALSE;
+
+  *fd = v;
+
+  return TRUE;
+}
+
 static void
 wait_cb (IdeSubprocess *subprocess,
          GAsyncResult  *result,
@@ -67,9 +87,9 @@ main (int   argc,
   g_autoptr(GDBusConnection) bus = NULL;
   g_autoptr(IdeSubprocess) subprocess = NULL;
   g_autoptr(GMainLoop) main_loop = NULL;
-  g_autofree gchar *argv0 = NULL;
   g_autoptr(GError) error = NULL;
-  g_auto(GStrv) env = NULL;
+  const gchar *env;
+  gint fd = -1;
 
   g_log_set_default_handler (log_func, NULL);
 
@@ -78,24 +98,24 @@ main (int   argc,
   if (!(bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error)))
     g_error ("Failed to connect to session bus: %s", error->message);
 
-  launcher = ide_subprocess_launcher_new (G_SUBPROCESS_FLAGS_STDOUT_PIPE |
-                                          G_SUBPROCESS_FLAGS_STDIN_PIPE |
-                                              G_SUBPROCESS_FLAGS_STDERR_PIPE);
+  launcher = ide_subprocess_launcher_new (0);
 
-  argv0 = g_path_get_basename (argv[0]);
-  ide_subprocess_launcher_push_argv (launcher, argv0);
+  ide_subprocess_launcher_push_argv (launcher, "fusermount");
   for (guint i = 1; i < argc; i++)
     ide_subprocess_launcher_push_argv (launcher, argv[i]);
 
-  env = g_get_environ ();
-
   ide_subprocess_launcher_set_cwd (launcher, g_get_current_dir ());
-  ide_subprocess_launcher_set_environ (launcher, (const gchar * const *)env);
   ide_subprocess_launcher_set_run_on_host (launcher, TRUE);
   ide_subprocess_launcher_take_stdin_fd (launcher, dup (STDIN_FILENO));
   ide_subprocess_launcher_take_stdout_fd (launcher, dup (STDOUT_FILENO));
   ide_subprocess_launcher_take_stderr_fd (launcher, dup (STDERR_FILENO));
 
+  if ((env = g_getenv ("_FUSE_COMMFD")) && parse_fd (env, &fd) && fd > 2)
+    {
+      ide_subprocess_launcher_setenv (launcher, "_FUSE_COMMFD", env, TRUE);
+      ide_subprocess_launcher_take_fd (launcher, fd, fd);
+    }
+
   if (!(subprocess = ide_subprocess_launcher_spawn (launcher, NULL, &error)))
     g_error ("ERROR: %s", error->message);
 
diff --git a/src/meson.build b/src/meson.build
index e3dc6183a..3259278ce 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -22,10 +22,9 @@ executable('gnome-builder', gnome_builder_sources,
       dependencies: gnome_builder_plugins_deps + [libide_dep, gnome_builder_plugins_dep],
 )
 
-# Don't install until we actually start using this
-# install_dir: get_option('libexecdir'),
-executable('ide-host-exec', ['host-exec.c'],
-           install: false,
+executable('fusermount-wrapper', ['fusermount-wrapper.c'],
+           install: get_option('fusermount_wrapper'),
+       install_dir: get_option('bindir'),
             c_args: exe_c_args,
          link_args: exe_link_args,
      install_rpath: pkglibdir_abs,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]