[gnome-builder] terminal: fallback to ptsname() if ptsname_r() is not available
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] terminal: fallback to ptsname() if ptsname_r() is not available
- Date: Thu, 3 Nov 2016 21:30:21 +0000 (UTC)
commit 6e03588cb17d07f18b73c3d9ae288fa2b60222ce
Author: Christian Hergert <chergert redhat com>
Date: Thu Nov 3 14:28:54 2016 -0700
terminal: fallback to ptsname() if ptsname_r() is not available
We are technically safe from race-conditions here in Builder specific
code today, as we only call ptsname_r() from the main loop. So switching
to the MT-unsafe ptsname() is fine. However, I'd like to always use the
re-entrant safe POSIX functions when possible.
This falls back to ptsname() when ptsname_r() isn't available, such as on
BSD variants.
https://bugzilla.gnome.org/show_bug.cgi?id=773880
plugins/terminal/configure.ac | 12 ++++++++++++
plugins/terminal/gb-terminal-view.c | 11 ++++++++++-
2 files changed, 22 insertions(+), 1 deletions(-)
---
diff --git a/plugins/terminal/configure.ac b/plugins/terminal/configure.ac
index 9cfb190..5732e86 100644
--- a/plugins/terminal/configure.ac
+++ b/plugins/terminal/configure.ac
@@ -10,6 +10,18 @@ AS_IF([test x$enable_terminal_plugin = xyes && test x$have_vte = xno],[
AC_MSG_ERROR([Failed to locate vte dependencies. Try installing vte291-devel.])
])
+dnl We prefer ptsname_r(), but will settle for ptsname() if necessary
+AC_TRY_LINK([#ifndef _XOPEN_SOURCE
+ #define _XOPEN_SOURCE
+ #endif
+ #ifndef _GNU_SOURCE
+ #define _GNU_SOURCE
+ #endif
+ #include <stdlib.h>],
+ [char buf[10]; ptsname_r(0, buf, sizeof(buf));],
+ [AC_DEFINE(HAVE_PTSNAME_R, 1,
+ Define to 1 if you have a re-entrant version of ptsname)])
+
# for if ENABLE_CLANG_PLUGIN in Makefile.am
AM_CONDITIONAL(ENABLE_TERMINAL_PLUGIN, test x$enable_terminal_plugin = xyes)
diff --git a/plugins/terminal/gb-terminal-view.c b/plugins/terminal/gb-terminal-view.c
index ae9b01b..62b08ec 100644
--- a/plugins/terminal/gb-terminal-view.c
+++ b/plugins/terminal/gb-terminal-view.c
@@ -193,9 +193,13 @@ gb_terminal_respawn (GbTerminalView *self,
gint64 now;
int master_fd = -1;
int tty_fd = -1;
- char name[PATH_MAX + 1];
gint stdout_fd = -1;
gint stderr_fd = -1;
+#ifdef HAVE_PTSNAME_R
+ char name[PATH_MAX + 1];
+#else
+ const char *name;
+#endif
IDE_ENTRY;
@@ -255,8 +259,13 @@ gb_terminal_respawn (GbTerminalView *self,
if (unlockpt (master_fd) != 0)
IDE_GOTO (failure);
+#ifdef HAVE_PTSNAME_R
if (ptsname_r (master_fd, name, sizeof name - 1) != 0)
IDE_GOTO (failure);
+#else
+ if (NULL == (name = ptsname (master_fd)))
+ IDE_GOTO (failure);
+#endif
if (-1 == (tty_fd = open (name, O_RDWR | O_CLOEXEC)))
IDE_GOTO (failure);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]