[gnome-builder] threading: add simple API to check if a TTY is needed
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] threading: add simple API to check if a TTY is needed
- Date: Tue, 19 Feb 2019 00:57:43 +0000 (UTC)
commit efb92b702d6e85684cce775f525b161f59c3410b
Author: Christian Hergert <chergert redhat com>
Date: Mon Feb 18 16:55:05 2019 -0800
threading: add simple API to check if a TTY is needed
This is mostly just to give launcher subclasses an easy way to determine
if they need a TTY. For example, podman can use --tty.
src/libide/threading/ide-subprocess-launcher.c | 36 ++++++++++++++++++++++++++
src/libide/threading/ide-subprocess-launcher.h | 2 ++
2 files changed, 38 insertions(+)
---
diff --git a/src/libide/threading/ide-subprocess-launcher.c b/src/libide/threading/ide-subprocess-launcher.c
index 6e7f7aacf..f116a94a1 100644
--- a/src/libide/threading/ide-subprocess-launcher.c
+++ b/src/libide/threading/ide-subprocess-launcher.c
@@ -1071,3 +1071,39 @@ ide_subprocess_launcher_append_path (IdeSubprocessLauncher *self,
ide_subprocess_launcher_setenv (self, "PATH", path, TRUE);
}
}
+
+gboolean
+ide_subprocess_launcher_get_needs_tty (IdeSubprocessLauncher *self)
+{
+ IdeSubprocessLauncherPrivate *priv = ide_subprocess_launcher_get_instance_private (self);
+
+ g_return_val_if_fail (IDE_IS_SUBPROCESS_LAUNCHER (self), FALSE);
+
+ if ((priv->stdin_fd != -1 && isatty (priv->stdin_fd)) ||
+ (priv->stdout_fd != -1 && isatty (priv->stdout_fd)) ||
+ (priv->stderr_fd != -1 && isatty (priv->stderr_fd)))
+ return TRUE;
+
+ if (priv->fd_mapping != NULL)
+ {
+ for (guint i = 0; i < priv->fd_mapping->len; i++)
+ {
+ const FdMapping *fdmap = &g_array_index (priv->fd_mapping, FdMapping, i);
+
+ switch (fdmap->dest_fd)
+ {
+ case STDIN_FILENO:
+ case STDOUT_FILENO:
+ case STDERR_FILENO:
+ if (isatty (fdmap->source_fd))
+ return TRUE;
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ return FALSE;
+}
diff --git a/src/libide/threading/ide-subprocess-launcher.h b/src/libide/threading/ide-subprocess-launcher.h
index 6bcc52700..2bc172d6f 100644
--- a/src/libide/threading/ide-subprocess-launcher.h
+++ b/src/libide/threading/ide-subprocess-launcher.h
@@ -131,5 +131,7 @@ void ide_subprocess_launcher_take_stdout_fd (IdeSubproce
IDE_AVAILABLE_IN_3_32
void ide_subprocess_launcher_take_stderr_fd (IdeSubprocessLauncher *self,
gint stderr_fd);
+IDE_AVAILABLE_IN_3_32
+gboolean ide_subprocess_launcher_get_needs_tty (IdeSubprocessLauncher *self);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]