[gnome-builder/gnome-builder-3-32] threading: add API to get max FD for a subprocess launcher



commit 1420f52c59d1bdad001add33d799634e0faa1fbb
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 3 13:46:19 2019 -0700

    threading: add API to get max FD for a subprocess launcher
    
    This can be used to determine what the maximum FD number that will be
    mapped into the new process.
    
    This is a backport from master, that keeps the API private.

 src/libide/threading/ide-subprocess-launcher.c | 33 ++++++++++++++++++++++++++
 src/libide/threading/ide-subprocess-launcher.h |  2 ++
 2 files changed, 35 insertions(+)
---
diff --git a/src/libide/threading/ide-subprocess-launcher.c b/src/libide/threading/ide-subprocess-launcher.c
index f116a94a1..99b3f7578 100644
--- a/src/libide/threading/ide-subprocess-launcher.c
+++ b/src/libide/threading/ide-subprocess-launcher.c
@@ -1107,3 +1107,36 @@ ide_subprocess_launcher_get_needs_tty (IdeSubprocessLauncher *self)
 
   return FALSE;
 }
+
+/**
+ * _ide_subprocess_launcher_get_max_fd:
+ * @self: a #IdeSubprocessLauncher
+ *
+ * Gets the hightest number of FD that has been mapped into the
+ * subprocess launcher.
+ *
+ * This will always return a value >= 2 (to indicate stdin/stdout/stderr).
+ *
+ * Returns: an integer for the max-fd
+ */
+gint
+_ide_subprocess_launcher_get_max_fd (IdeSubprocessLauncher *self)
+{
+  IdeSubprocessLauncherPrivate *priv = ide_subprocess_launcher_get_instance_private (self);
+  gint max_fd = 2;
+
+  g_return_val_if_fail (IDE_IS_SUBPROCESS_LAUNCHER (self), 2);
+
+  if (priv->fd_mapping != NULL)
+    {
+      for (guint i = 0; i < priv->fd_mapping->len; i++)
+        {
+          const FdMapping *map = &g_array_index (priv->fd_mapping, FdMapping, i);
+
+          if (map->dest_fd > max_fd)
+            max_fd = map->dest_fd;
+        }
+    }
+
+  return max_fd;
+}
diff --git a/src/libide/threading/ide-subprocess-launcher.h b/src/libide/threading/ide-subprocess-launcher.h
index 2bc172d6f..fbe5d798f 100644
--- a/src/libide/threading/ide-subprocess-launcher.h
+++ b/src/libide/threading/ide-subprocess-launcher.h
@@ -133,5 +133,7 @@ void                   ide_subprocess_launcher_take_stderr_fd       (IdeSubproce
                                                                      gint                    stderr_fd);
 IDE_AVAILABLE_IN_3_32
 gboolean               ide_subprocess_launcher_get_needs_tty        (IdeSubprocessLauncher  *self);
+G_GNUC_INTERNAL
+gint                   _ide_subprocess_launcher_get_max_fd          (IdeSubprocessLauncher  *self);
 
 G_END_DECLS


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