[gnome-builder] libide/threading: add private API to silence FD output



commit 043ebc439770df341f396fcd5472c7beafe9d9c7
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 27 16:57:38 2022 -0700

    libide/threading: add private API to silence FD output
    
    This just maps /dev/null into the destination FD, which can be easier than
    trying to plumb access to subprocess flags for the created launcher.
    
    We can make this API public in 44, but is private now to make backporting
    to 43 easier.

 src/libide/threading/ide-unix-fd-map-private.h | 33 ++++++++++++++++++++++++++
 src/libide/threading/ide-unix-fd-map.c         | 28 ++++++++++++++++++++++
 2 files changed, 61 insertions(+)
---
diff --git a/src/libide/threading/ide-unix-fd-map-private.h b/src/libide/threading/ide-unix-fd-map-private.h
new file mode 100644
index 000000000..02b94360c
--- /dev/null
+++ b/src/libide/threading/ide-unix-fd-map-private.h
@@ -0,0 +1,33 @@
+/* ide-unix-fd-map-private.h
+ *
+ * Copyright 2022 Christian Hergert <chergert redhat com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef struct _IdeUnixFDMap IdeUnixFdMap;
+
+gboolean ide_unix_fd_map_silence_fd (IdeUnixFdMap  *self,
+                                     int            dest_fd,
+                                     GError       **error);
+
+G_END_DECLS
diff --git a/src/libide/threading/ide-unix-fd-map.c b/src/libide/threading/ide-unix-fd-map.c
index 40291f0db..7760045de 100644
--- a/src/libide/threading/ide-unix-fd-map.c
+++ b/src/libide/threading/ide-unix-fd-map.c
@@ -31,6 +31,7 @@
 #include <gio/gunixoutputstream.h>
 
 #include "ide-unix-fd-map.h"
+#include "ide-unix-fd-map-private.h"
 
 typedef struct
 {
@@ -522,3 +523,30 @@ failure:
 
   IDE_RETURN (g_steal_pointer (&ret));
 }
+
+gboolean
+ide_unix_fd_map_silence_fd (IdeUnixFdMap  *self,
+                            int            dest_fd,
+                            GError       **error)
+{
+  int null_fd = -1;
+
+  g_return_val_if_fail (IDE_IS_UNIX_FD_MAP (self), FALSE);
+
+  if (dest_fd < 0)
+    return TRUE;
+
+  if (-1 == (null_fd = open ("/dev/null", O_WRONLY)))
+    {
+      int errsv = errno;
+      g_set_error_literal (error,
+                           G_IO_ERROR,
+                           g_io_error_from_errno (errsv),
+                           g_strerror (errsv));
+      return FALSE;
+    }
+
+  ide_unix_fd_map_take (self, ide_steal_fd (&null_fd), dest_fd);
+
+  return TRUE;
+}


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