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

Aurelien Jarno aurel32 at alioth.debian.org
Sun Jul 3 17:16:16 UTC 2011


Author: aurel32
Date: 2011-07-03 17:16:16 +0000 (Sun, 03 Jul 2011)
New Revision: 3530

Modified:
   trunk/glibc-ports/kfreebsd/Versions
   trunk/glibc-ports/kfreebsd/getpt.c
   trunk/glibc-ports/kfreebsd/grantpt.c
   trunk/glibc-ports/kfreebsd/ptsname.c
   trunk/glibc-ports/kfreebsd/syscalls.list
   trunk/glibc-ports/kfreebsd/unlockpt.c
Log:
Revert r3435 (see bug#632452)


Modified: trunk/glibc-ports/kfreebsd/Versions
===================================================================
--- trunk/glibc-ports/kfreebsd/Versions	2011-07-03 16:31:31 UTC (rev 3529)
+++ trunk/glibc-ports/kfreebsd/Versions	2011-07-03 17:16:16 UTC (rev 3530)
@@ -112,7 +112,6 @@
     # 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-07-03 16:31:31 UTC (rev 3529)
+++ trunk/glibc-ports/kfreebsd/getpt.c	2011-07-03 17:16:16 UTC (rev 3530)
@@ -21,27 +21,63 @@
 #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)
 
-/* Prototype for function that opens BSD-style master pseudo-terminals.  */
-int __bsd_getpt (void);
+/* 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)
 {
-  int fd = INLINE_SYSCALL (posix_openpt, 1, oflag);
-  if (fd >= 0)
+  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)
     {
-      if (!(oflag & O_NOCTTY))
-        __ioctl (fd, TIOCSCTTY, NULL);
+      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;
+	}
     }
-  return fd;
+
+  __set_errno (ENOENT);
+  return -1;
 }
 
 weak_alias (__posix_openpt, posix_openpt)
@@ -50,18 +86,7 @@
 int
 __getpt (void)
 {
-  int fd = __posix_openpt (O_RDWR);
-  if (fd == -1)
-      fd = __bsd_getpt ();
-  return fd;
+  return __posix_openpt (O_RDWR);
 }
 
-
-/* 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>
+weak_alias (__getpt, getpt)

Modified: trunk/glibc-ports/kfreebsd/grantpt.c
===================================================================
--- trunk/glibc-ports/kfreebsd/grantpt.c	2011-07-03 16:31:31 UTC (rev 3529)
+++ trunk/glibc-ports/kfreebsd/grantpt.c	2011-07-03 17:16:16 UTC (rev 3530)
@@ -1,32 +0,0 @@
-/* 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-07-03 16:31:31 UTC (rev 3529)
+++ trunk/glibc-ports/kfreebsd/ptsname.c	2011-07-03 17:16:16 UTC (rev 3530)
@@ -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_DEV) + 20];
+static char buffer[sizeof (_PATH_TTY) + 2];
 
 
 /* Return the pathname of the pseudo terminal slave associated with
@@ -39,26 +39,15 @@
   return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
 }
 
-int
-__isptymaster(int fd)
-{
-  if (0 == __ioctl(fd, TIOCPTMASTER))
-    return 0;
+/* The are declared in getpt.c.  */
+extern const char __libc_ptyname1[] attribute_hidden;
+extern const char __libc_ptyname2[] attribute_hidden;
 
-  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_r (int fd, char *buf, size_t buflen)
+__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)
@@ -67,14 +56,19 @@
       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 (0 != __isptymaster(fd))
+  if (!(S_ISCHR (stp->st_mode)))
     {
       __set_errno (ENOTTY);
       return ENOTTY;
     }
 
-  if (buflen < sizeof (_PATH_DEV) + 5)
+  if (buflen < sizeof (_PATH_TTY) + 2)
     {
       __set_errno (ERANGE);
       return ERANGE;
@@ -84,15 +78,34 @@
   /* 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';
 
-  fiodgname.buf = p;
-  fiodgname.len = buflen;
-
-  if (0 != __ioctl(fd, FIODGNAME, &fiodgname))
+  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;
 }
 
+
+/* 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-07-03 16:31:31 UTC (rev 3529)
+++ trunk/glibc-ports/kfreebsd/syscalls.list	2011-07-03 17:16:16 UTC (rev 3530)
@@ -100,7 +100,6 @@
 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-07-03 16:31:31 UTC (rev 3529)
+++ trunk/glibc-ports/kfreebsd/unlockpt.c	2011-07-03 17:16:16 UTC (rev 3530)
@@ -21,12 +21,25 @@
 #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 */
-  return __isptymaster(fd);
+
+  if (__fxstat64 (_STAT_VER, fd, &st) < 0)
+    return -1;
+
+  if (!(S_ISCHR (st.st_mode)))
+  {
+    __set_errno (ENOTTY);
+    return -1;
+  }
+
+  return 0;
 }
+
+weak_alias (__unlockpt, unlockpt)




More information about the Glibc-bsd-commits mailing list