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



commit 735a697ee67515f45871a48765d454c6472540b9
Author: Christian Hergert <chergert redhat com>
Date:   Wed Apr 3 12:55:47 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.

 src/libide/threading/ide-subprocess-launcher.c | 35 ++++++++++++++++++++++++++
 src/libide/threading/ide-subprocess-launcher.h |  2 ++
 2 files changed, 37 insertions(+)
---
diff --git a/src/libide/threading/ide-subprocess-launcher.c b/src/libide/threading/ide-subprocess-launcher.c
index f116a94a1..cdb22b3bd 100644
--- a/src/libide/threading/ide-subprocess-launcher.c
+++ b/src/libide/threading/ide-subprocess-launcher.c
@@ -1107,3 +1107,38 @@ 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
+ *
+ * Since: 3.34
+ */
+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..78d88d956 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);
+IDE_AVAILABLE_IN_3_34
+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]