[Glibc-bsd-commits] r3435 - in trunk/glibc-ports: kfreebsd patches

Petr Salinger ps-guest at alioth.debian.org
Thu Jun 9 15:49:26 UTC 2011


Author: ps-guest
Date: 2011-06-09 15:49:25 +0000 (Thu, 09 Jun 2011)
New Revision: 3435

Added:
   trunk/glibc-ports/kfreebsd/grantpt.c
Modified:
   trunk/glibc-ports/kfreebsd/Versions
   trunk/glibc-ports/kfreebsd/getpt.c
   trunk/glibc-ports/kfreebsd/ptsname.c
   trunk/glibc-ports/kfreebsd/syscalls.list
   trunk/glibc-ports/kfreebsd/unlockpt.c
   trunk/glibc-ports/patches/scripts.patch
Log:
new posix_openpt(3) and related functions implementation



Modified: trunk/glibc-ports/kfreebsd/Versions
===================================================================
--- trunk/glibc-ports/kfreebsd/Versions	2011-06-09 08:19:41 UTC (rev 3434)
+++ trunk/glibc-ports/kfreebsd/Versions	2011-06-09 15:49:25 UTC (rev 3435)
@@ -112,6 +112,7 @@
     # misc fixes for FreeBSD:
     __syscall_freebsd6_lseek; __syscall_freebsd6_pread; __syscall_freebsd6_pwrite;
     __syscall_lseek; __syscall_pread; __syscall_pwrite;
+    __syscall_posix_openpt;
     __syscall_connect; __syscall_sendto;
     __syscall_cpuset_getaffinity ; __syscall_cpuset_setaffinity;
      # global variable used in brk()

Modified: trunk/glibc-ports/kfreebsd/getpt.c
===================================================================
--- trunk/glibc-ports/kfreebsd/getpt.c	2011-06-09 08:19:41 UTC (rev 3434)
+++ trunk/glibc-ports/kfreebsd/getpt.c	2011-06-09 15:49:25 UTC (rev 3435)
@@ -21,63 +21,27 @@
 #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"
+/* Prototype for function that opens BSD-style master pseudo-terminals.  */
+int __bsd_getpt (void);
 
-
-/* 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)
+  int fd = INLINE_SYSCALL (posix_openpt, 1, oflag);
+  if (fd >= 0)
     {
-      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;
-	}
+      if (!(oflag & O_NOCTTY))
+        __ioctl (fd, TIOCSCTTY, NULL);
     }
-
-  __set_errno (ENOENT);
-  return -1;
+  return fd;
 }
 
 weak_alias (__posix_openpt, posix_openpt)
@@ -86,7 +50,18 @@
 int
 __getpt (void)
 {
-  return __posix_openpt (O_RDWR);
+  int fd = __posix_openpt (O_RDWR);
+  if (fd == -1)
+      fd = __bsd_getpt ();
+  return fd;
 }
 
-weak_alias (__getpt, getpt)
+
+/* Letters indicating a series of pseudo terminals.  */
+#define PTYNAME1 "pqrs";
+/* Letters indicating the position within a series.  */
+#define PTYNAME2 "0123456789abcdefghijklmnopqrstuv";
+
+#define __getpt __bsd_getpt
+#define HAVE_POSIX_OPENPT
+#include <sysdeps/unix/bsd/getpt.c>

Added: trunk/glibc-ports/kfreebsd/grantpt.c
===================================================================
--- trunk/glibc-ports/kfreebsd/grantpt.c	                        (rev 0)
+++ trunk/glibc-ports/kfreebsd/grantpt.c	2011-06-09 15:49:25 UTC (rev 3435)
@@ -0,0 +1,32 @@
+/* Copyright (C) 2011 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
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library 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
+   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.  */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+extern int __isptymaster(int fd);
+
+int
+grantpt (int fd)
+{
+  /* there is no need/way to do granting of slave pseudo-terminal device,
+     just check whether fd might be valid master pseudo-terminal device */
+  return __isptymaster(fd);
+}

Modified: trunk/glibc-ports/kfreebsd/ptsname.c
===================================================================
--- trunk/glibc-ports/kfreebsd/ptsname.c	2011-06-09 08:19:41 UTC (rev 3434)
+++ trunk/glibc-ports/kfreebsd/ptsname.c	2011-06-09 15:49:25 UTC (rev 3435)
@@ -24,10 +24,10 @@
 #include <sys/sysmacros.h>
 #include <sys/sysctl.h>
 #include <unistd.h>
+#include <sys/ioctl.h>
 
-
 /* Static buffer for `ptsname'.  */
-static char buffer[sizeof (_PATH_TTY) + 2];
+static char buffer[sizeof (_PATH_DEV) + 20];
 
 
 /* Return the pathname of the pseudo terminal slave associated with
@@ -39,15 +39,26 @@
   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;
+}
+
+/* Store at most BUFLEN characters of the pathname of the slave pseudo
+   terminal associated with the master FD is open on in BUF.
+   Return 0 on success, otherwise an error number.  */
 int
-__ptsname_internal (int fd, char *buf, size_t buflen, struct stat64 *stp)
+__ptsname_r (int fd, char *buf, size_t buflen)
 {
   int saved_errno = errno;
+  struct fiodgname_arg fiodgname;
   char *p;
 
   if (buf == NULL)
@@ -56,19 +67,14 @@
       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)))
+  if (0 != __isptymaster(fd))
     {
       __set_errno (ENOTTY);
       return ENOTTY;
     }
 
-  if (buflen < sizeof (_PATH_TTY) + 2)
+  if (buflen < sizeof (_PATH_DEV) + 5)
     {
       __set_errno (ERANGE);
       return ERANGE;
@@ -78,34 +84,15 @@
   /* 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)
-    return errno;
-  p[0] = 't';
 
-  if (__xstat64 (_STAT_VER, buf, stp) < 0)
+  fiodgname.buf = p;
+  fiodgname.len = buflen;
+
+  if (0 != __ioctl(fd, FIODGNAME, &fiodgname))
     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;
 }
 
-
-/* Store at most BUFLEN characters of the pathname of the slave pseudo
-   terminal associated with the master FD is open on in BUF.
-   Return 0 on success, otherwise an error number.  */
-int
-__ptsname_r (int fd, char *buf, size_t buflen)
-{
-  struct stat64 st;
-  return __ptsname_internal (fd, buf, buflen, &st);
-}
 weak_alias (__ptsname_r, ptsname_r)

Modified: trunk/glibc-ports/kfreebsd/syscalls.list
===================================================================
--- trunk/glibc-ports/kfreebsd/syscalls.list	2011-06-09 08:19:41 UTC (rev 3434)
+++ trunk/glibc-ports/kfreebsd/syscalls.list	2011-06-09 15:49:25 UTC (rev 3435)
@@ -98,6 +98,7 @@
 ntp_adjtime		-	ntp_adjtime		i:p		ntp_adjtime
 obreak			-	obreak			i:a		__syscall_obreak
 sys_open		-	open			i:siv		__syscall_open
+posix_openpt		getpt	posix_openpt		i:i		__syscall_posix_openpt
 poll			-	poll			Ci:pii		__poll poll
 sys_pread		-	pread			i:ibni		__syscall_pread
 sys_freebsd6_pread	-	freebsd6_pread		i:ibnii		__syscall_freebsd6_pread

Modified: trunk/glibc-ports/kfreebsd/unlockpt.c
===================================================================
--- trunk/glibc-ports/kfreebsd/unlockpt.c	2011-06-09 08:19:41 UTC (rev 3434)
+++ trunk/glibc-ports/kfreebsd/unlockpt.c	2011-06-09 15:49:25 UTC (rev 3435)
@@ -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)

Modified: trunk/glibc-ports/patches/scripts.patch
===================================================================
--- trunk/glibc-ports/patches/scripts.patch	2011-06-09 08:19:41 UTC (rev 3434)
+++ trunk/glibc-ports/patches/scripts.patch	2011-06-09 15:49:25 UTC (rev 3435)
@@ -13,7 +13,7 @@
  .*-sun-solaris2.*	2	2.0.0	# just an arbitrary value
  
 -.*-.*-freebsd.*-gnu.*	3	4.0.0	# earliest compatible kernel version
-+.*-.*-kfreebsd.*	3	5.4.0	# earliest compatible kernel version
++.*-.*-kfreebsd.*	3	8.0.0	# earliest compatible kernel version
  
  .*-.*-knetbsd.*-gnu.*	4	1.6.0	# earliest compatible kernel version
  




More information about the Glibc-bsd-commits mailing list