Use posix_openpt() instead of calling openpty() to allocate a PTY

and open the slave TTY, and calling unlockpt() afterwards.

PR:		128941
Submitted by:	ed
Reported by:	Gerhard Gonter <g.gonter@ieee.org>
This commit is contained in:
Erwin Lansing 2009-02-02 19:24:49 +00:00
parent b0ff3937f1
commit 57eda18a6c
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=227466
3 changed files with 61 additions and 0 deletions

View file

@ -7,6 +7,7 @@
PORTNAME= IO-Tty
PORTVERSION= 1.07
PORTREVISION= 1
CATEGORIES= devel perl5
MASTER_SITES= CPAN
PKGNAMEPREFIX= p5-

View file

@ -0,0 +1,39 @@
--- Makefile.PL
+++ Makefile.PL
@@ -95,16 +95,17 @@
# checking for various functions
-my %funcs = (ttyname => "",
- openpty => "-lutil",
- _getpty => "",
- strlcpy => "",
- sigaction => "",
- grantpt => "",
- unlockpt => "",
- getpt => "",
- ptsname => "",
- ptsname_r => "",
+my %funcs = (ttyname => "",
+ openpty => "-lutil",
+ _getpty => "",
+ strlcpy => "",
+ sigaction => "",
+ grantpt => "",
+ unlockpt => "",
+ getpt => "",
+ posix_openpt => "",
+ ptsname => "",
+ ptsname_r => "",
);
foreach my $f (sort keys %funcs) {
@@ -290,7 +291,7 @@
msg => "WARNING! Neither ptsname() nor ptsname_r() could be found,\n so we cannot use a high-level interface like openpty().\n",
},
{
- defines => [qw"-DHAVE_DEV_PTMX -DHAVE_DEV_PTYM_CLONE -DHAVE_DEV_PTC -DHAVE_DEV_PTMX_BSD -DHAVE__GETPTY -DHAVE_OPENPTY -DHAVE_GETPT"],
+ defines => [qw"-DHAVE_DEV_PTMX -DHAVE_DEV_PTYM_CLONE -DHAVE_DEV_PTC -DHAVE_DEV_PTMX_BSD -DHAVE__GETPTY -DHAVE_OPENPTY -DHAVE_GETPT -DHAVE_POSIX_OPENPT"],
msg => "No high-level lib or clone device has been found, we will use BSD-style ptys.\n",
},
) {

View file

@ -0,0 +1,21 @@
--- Tty.xs
+++ Tty.xs
@@ -453,6 +453,18 @@
#if defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R)
/* we don't need to try these if we don't have a way to get the pty names */
+#if defined(HAVE_POSIX_OPENPT)
+#if PTY_DEBUG
+ if (print_debug)
+ fprintf(stderr, "trying posix_openpt()...\n");
+#endif
+ *ptyfd = posix_openpt(O_RDWR|O_NOCTTY);
+ if (*ptyfd >= 0 && open_slave(ptyfd, ttyfd, namebuf, namebuflen))
+ break; /* got one */
+ if (PL_dowarn)
+ warn("pty_allocate(nonfatal): posix_openpt(): %.100s", strerror(errno));
+#endif /* defined(HAVE_POSIX_OPENPT) */
+
#if defined(HAVE_GETPT)
/* glibc defines this */
#if PTY_DEBUG