[Glibc-bsd-commits] r4485 - trunk/glibc-ports/kfreebsd

Petr Salinger ps-guest at alioth.debian.org
Tue May 28 15:54:35 UTC 2013


Author: ps-guest
Date: 2013-05-28 15:54:35 +0000 (Tue, 28 May 2013)
New Revision: 4485

Modified:
   trunk/glibc-ports/kfreebsd/getpt.c
   trunk/glibc-ports/kfreebsd/ptsname.c
   trunk/glibc-ports/kfreebsd/unlockpt.c
Log:
use /dev/pts/ for pseudo terminal devicesc


Modified: trunk/glibc-ports/kfreebsd/getpt.c
===================================================================
--- trunk/glibc-ports/kfreebsd/getpt.c	2013-05-28 15:49:40 UTC (rev 4484)
+++ trunk/glibc-ports/kfreebsd/getpt.c	2013-05-28 15:54:35 UTC (rev 4485)
@@ -21,72 +21,31 @@
 #include <string.h>
 #include <unistd.h>
 #include <sys/ioctl.h>
+#include <sysdep.h>
 
+/* The system call does not change the controlling terminal, so we have
+ * to do it ourselves.  */
+extern int __syscall_posix_openpt (int oflag);
+libc_hidden_proto (__syscall_posix_openpt)
 
-/* Prefix for master pseudo terminal nodes.  */
-#define _PATH_PTY "/dev/pty"
-
-
-/* Letters indicating a series of pseudo terminals.  */
-#ifndef PTYNAME1
-#define PTYNAME1 "pqrs"
-#endif
-const char __libc_ptyname1[] attribute_hidden = PTYNAME1;
-
-/* Letters indicating the position within a series.  */
-#ifndef PTYNAME2
-#define PTYNAME2 "0123456789abcdefghijklmnopqrstuv";
-#endif
-const char __libc_ptyname2[] attribute_hidden = PTYNAME2;
-
-
-/* Open a master pseudo terminal and return its file descriptor.  */
 int
 __posix_openpt (int oflag)
 {
-  char buf[sizeof (_PATH_PTY) + 2];
-  const char *p, *q;
-  char *s;
-
-  s = __mempcpy (buf, _PATH_PTY, sizeof (_PATH_PTY) - 1);
-  /* s[0] and s[1] will be filled in the loop.  */
-  s[2] = '\0';
-
-  for (p = __libc_ptyname1; *p != '\0'; ++p)
-    {
-      s[0] = *p;
-
-      for (q = __libc_ptyname2; *q != '\0'; ++q)
-	{
-	  int fd;
-
-	  s[1] = *q;
-
-	  fd = __open (buf, oflag);
-	  if (fd >= 0)
-	    {
-	      if (!(oflag & O_NOCTTY))
-		__ioctl (fd, TIOCSCTTY, NULL);
-
-	      return fd;
-	    }
-
-	  if (errno == ENOENT)
-	    return -1;
-	}
-    }
-
-  __set_errno (ENOENT);
-  return -1;
+  int fd = INLINE_SYSCALL (posix_openpt, 1, oflag);
+  if (fd >= 0)
+  {
+      if (!(oflag & O_NOCTTY))
+        __ioctl (fd, TIOCSCTTY, NULL);
+  }
+  return fd;
 }
 
 weak_alias (__posix_openpt, posix_openpt)
 
-
 int
 __getpt (void)
 {
-  return __posix_openpt (O_RDWR);
+  return __posix_openpt (O_RDWR | O_NOCTTY);
 }
 
 weak_alias (__getpt, getpt)

Modified: trunk/glibc-ports/kfreebsd/ptsname.c
===================================================================
--- trunk/glibc-ports/kfreebsd/ptsname.c	2013-05-28 15:49:40 UTC (rev 4484)
+++ trunk/glibc-ports/kfreebsd/ptsname.c	2013-05-28 15:54:35 UTC (rev 4485)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 1998-2013 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -12,22 +12,26 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
 #include <paths.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <sys/sysmacros.h>
 #include <sys/sysctl.h>
+#include <termios.h>
 #include <unistd.h>
 
 
+/* Directory where we can find the slave pty nodes.  */
+#define _PATH_DEVPTS "/dev/pts/"
+
 /* Static buffer for `ptsname'.  */
-static char buffer[sizeof (_PATH_TTY) + 2];
+static char buffer[sizeof (_PATH_DEVPTS) + 20];
 
 
 /* Return the pathname of the pseudo terminal slave associated with
@@ -39,62 +43,57 @@
   return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
 }
 
-/* The are declared in getpt.c.  */
-extern const char __libc_ptyname1[] attribute_hidden;
-extern const char __libc_ptyname2[] attribute_hidden;
 
+int
+__isptymaster(int fd)
+{
+  if (0 == __ioctl(fd, TIOCPTMASTER))
+    return 0;
 
+  if (errno != EBADF)
+    __set_errno (EINVAL);
+
+  return -1;
+}
+
+
 int
 __ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
 {
-  int saved_errno = errno;
+  struct fiodgname_arg fiodgname;
   char *p;
-
   if (buf == NULL)
     {
       __set_errno (EINVAL);
       return EINVAL;
     }
-
-  /* Don't call isatty (fd) - it usually fails with errno = EAGAIN.  */
-
-  if (__fxstat64 (_STAT_VER, fd, stp) < 0)
-    return errno;
-
+    
   /* Check if FD really is a master pseudo terminal.  */
-  if (!(S_ISCHR (stp->st_mode)))
-    {
-      __set_errno (ENOTTY);
-      return ENOTTY;
-    }
+  if (0 != __isptymaster(fd))
+  {
+      return errno;
+  }
 
-  if (buflen < sizeof (_PATH_TTY) + 2)
-    {
+  if (buflen < sizeof (_PATH_DEV) + 5) /* "/dev/" + "pts/"   */
+  {
       __set_errno (ERANGE);
       return ERANGE;
-    }
+  }
 
   /* Construct the slave's pathname.  */
   /* instead of strlen(_PATH_DEV) we use (sizeof (_PATH_DEV) - 1)  */
   p = __mempcpy (buf, _PATH_DEV, sizeof (_PATH_DEV) - 1);
   buflen -= (sizeof (_PATH_DEV) - 1);
-  if(__sysctlbyname("kern.devname", p, &buflen, &stp->st_rdev, sizeof (stp->st_rdev)) < 0)
+
+  fiodgname.buf = p;
+  fiodgname.len = buflen;
+
+  if (0 != __ioctl(fd, FIODGNAME, &fiodgname))
     return errno;
-  p[0] = 't';
 
   if (__xstat64 (_STAT_VER, buf, stp) < 0)
     return errno;
 
-  /* Check if the pathname we're about to return might be
-     slave pseudo terminal of the given master pseudo terminal.  */
-  if (!(S_ISCHR (stp->st_mode)))
-    {
-      /* This really is a configuration problem.  */
-      __set_errno (ENOTTY);
-      return ENOTTY;
-    }
-
-  __set_errno (saved_errno);
   return 0;
 }
 

Modified: trunk/glibc-ports/kfreebsd/unlockpt.c
===================================================================
--- trunk/glibc-ports/kfreebsd/unlockpt.c	2013-05-28 15:49:40 UTC (rev 4484)
+++ trunk/glibc-ports/kfreebsd/unlockpt.c	2013-05-28 15:54:35 UTC (rev 4485)
@@ -21,25 +21,12 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+extern int __isptymaster(int fd);
 
 int
-__unlockpt (int fd)
+unlockpt (int fd)
 {
-  struct stat64 st;
-
   /* there is no need/way to do unlocking of slave pseudo-terminal device,
      just check whether fd might be valid master pseudo-terminal device */
-
-  if (__fxstat64 (_STAT_VER, fd, &st) < 0)
-    return -1;
-
-  if (!(S_ISCHR (st.st_mode)))
-  {
-    __set_errno (ENOTTY);
-    return -1;
-  }
-
-  return 0;
+  return __isptymaster(fd);
 }
-
-weak_alias (__unlockpt, unlockpt)




More information about the Glibc-bsd-commits mailing list