about summary refs log tree commit diff
path: root/sysdeps/unix/sysv/linux
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1998-09-17 19:51:33 +0000
committerUlrich Drepper <drepper@redhat.com>1998-09-17 19:51:33 +0000
commit9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd (patch)
tree77802928e3a7d3163bc63c89979295da8260112a /sysdeps/unix/sysv/linux
parentd8f2b9ea8cf4fb6d043f2dbbeaaca04d4fd70fc6 (diff)
downloadglibc-9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd.tar.gz
glibc-9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd.tar.xz
glibc-9b3c7c3c713d7018c79f0b0ca0b34d386e8a25dd.zip
Update.
1998-09-17 19:34  Ulrich Drepper  <drepper@cygnus.com>

	* sysdeps/unix/sysv/sysv4/bits/utsname.h: Fix typo.
	Patch by John Tobey <jtobey@banta-im.com>.

1998-09-17  Mark Kettenis  <kettenis@phys.uva.nl>

	* login/pty-internal.h: Removed.  Moved constants related to the
	`grantpt' helper program protocol to ...
	* login/pty-private.h: ... here.  New file.
	* sysdeps/unix/sysv/linux/ptsname.c (ptsname): Reimplementation
	to make the function work with kernels >= 2.1.115.
	* sysdeps/unix/sysv/linux/getpt.c (getpt): Reimplement to call BSD
	version if using the cloning device fails.
	* sysdeps/unix/sysv/linux/grantpt.c: New file.
	* sysdeps/unix/sysv/linux/unlockpt.c: General cleanup.
	* sysdeps/unix/bsd/getpt.c (__getpt): Largely rewritten to allow
	use by Linux specific code.
	* sysdeps/unix/bsd/unlockpt.c: General cleanup.
	* sysdeps/unix/grantpt.c: Largely rewritten.  (pts_name): New
	function.  (grantpt): Use pts_name, check group and permission
	mode in addition to owner.  Try to set the owner, group and
	permission mode first without invoking the helper program.
	* login/programs/pt_chown.c: Largely rewritten.  Add argp and
	internationalization support.  Use symbolic constants instead of
	hardwired numbers for permission mode.
	* sysdeps/unix/bsd/ptsname.c: New file.

1998-09-17 22:04  Tim Waugh  <tim@cyberelk.demon.co.uk>

	* posix/wordexp-test.c: Undo last change.

	* posix/wordexp.c: Undo last change.
Diffstat (limited to 'sysdeps/unix/sysv/linux')
-rw-r--r--sysdeps/unix/sysv/linux/getpt.c51
-rw-r--r--sysdeps/unix/sysv/linux/grantpt.c64
-rw-r--r--sysdeps/unix/sysv/linux/ptsname.c141
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc64/socket.S80
-rw-r--r--sysdeps/unix/sysv/linux/unlockpt.c20
5 files changed, 240 insertions, 116 deletions
diff --git a/sysdeps/unix/sysv/linux/getpt.c b/sysdeps/unix/sysv/linux/getpt.c
index 0f5949d1bc..8165eccc1b 100644
--- a/sysdeps/unix/sysv/linux/getpt.c
+++ b/sysdeps/unix/sysv/linux/getpt.c
@@ -17,33 +17,26 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include <sys/types.h>
-#include <fcntl.h>
 #include <errno.h>
+#include <fcntl.h>
 #include <stdlib.h>
-#include <string.h>
 
-#include "pty-internal.h"
+/* Path to the master pseudo terminal cloning device.  */
+#define _PATH_DEVPTMX "/dev/ptmx"
 
-/* Per Documentation/devices.txt: pty masters are /dev/pty[p-za-e][0-9a-f].
-   These strings are used also in ptsname.c. */
-const char __ptyname1[] = "pqrstuvwxyzabcde";
-const char __ptyname2[] = "0123456789abcdef";
+/* Prototype for function that opens BSD-style master pseudo-terminals.  */
+int __bsd_getpt (void);
 
-/* Open the master side of a pseudoterminal and return its file
-   descriptor, or -1 on error.  Linux version. */
+/* Open a master pseudo terminal and return its file descriptor.  */
 int
-__getpt ()
+__getpt (void)
 {
-  int fd;
-  const char *i, *j;
   static int have_dev_ptmx = 1;
-  char namebuf[PTYNAMELEN];
+  int fd;
 
-  /* The new way:  */
   if (have_dev_ptmx)
     {
-      fd = __open ("/dev/ptmx", O_RDWR);
+      fd = __open (_PATH_DEVPTMX, O_RDWR);
       if (fd != -1)
 	return fd;
       else
@@ -55,23 +48,11 @@ __getpt ()
 	}
     }
 
-  /* The old way: */
-  strcpy (namebuf, "/dev/pty");
-  namebuf[10] = '\0';
-  for (i = __ptyname1; *i; ++i)
-    {
-      namebuf[8] = *i;
-      for (j = __ptyname2; *j; ++j)
-        {
-	  namebuf[9] = *j;
-	  fd = __open (namebuf, O_RDWR);
-	  if (fd != -1)
-	    return fd;
-	  if (errno != EIO)
-	    return -1;
-        }
-    }
-  __set_errno (ENFILE);
-  return -1;
+  return __bsd_getpt ();
 }
-weak_alias (__getpt, getpt)
+
+#define PTYNAME1 "pqrstuvwxyzabcde";
+#define PTYNAME2 "0123456789abcdef";
+
+#define __getpt __bsd_getpt
+#include <sysdeps/unix/bsd/getpt.c>
diff --git a/sysdeps/unix/sysv/linux/grantpt.c b/sysdeps/unix/sysv/linux/grantpt.c
new file mode 100644
index 0000000000..668f13192e
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/grantpt.c
@@ -0,0 +1,64 @@
+/* Copyright (C) 1998 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 Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <limits.h>
+#include <stdlib.h>
+#include <sys/statfs.h>
+
+/* Constant that identifies the `devpts' filesystem.  */
+#define DEVPTS_SUPER_MAGIC	0x1cd1
+
+/* Prototype for function that changes ownership and access permission
+   for slave pseudo terminals that do not live on a `devpts'
+   filesystem.  */
+int __unix_grantpt (int fd);
+
+/* Prototype for private function that gets the name of the slave
+   pseudo terminal in a safe way.  */
+static int pts_name (int fd, char **pts, size_t buf_len);
+
+/* Change the ownership and access permission of the slave pseudo
+   terminal associated with the master pseudo terminal specified
+   by FD.  */
+int
+grantpt (int fd)
+{
+  struct statfs fsbuf;
+#ifdef PATH_MAX
+  char _buf[PATH_MAX];
+#else
+  char _buf[512];
+#endif
+  char *buf = _buf;
+
+  if (pts_name (fd, &buf, sizeof (_buf)))
+    return -1;
+  
+  if (__statfs (buf, &fsbuf) < 0)
+    return -1;
+
+  /* If the slave pseudo terminal lives on a `devpts' filesystem, the
+     ownership and access permission are already set.  */
+  if (fsbuf.f_type == DEVPTS_SUPER_MAGIC)
+    return 0;
+
+  return __unix_grantpt (fd);
+}
+
+#define grantpt __unix_grantpt
+#include <sysdeps/unix/grantpt.c>
diff --git a/sysdeps/unix/sysv/linux/ptsname.c b/sysdeps/unix/sysv/linux/ptsname.c
index 052516c7ac..048ac96551 100644
--- a/sysdeps/unix/sysv/linux/ptsname.c
+++ b/sysdeps/unix/sysv/linux/ptsname.c
@@ -17,50 +17,50 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include <sys/types.h>
+#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 <termios.h>
-#include <string.h>
-#include <errno.h>
-#include <stdlib.h>
 #include <unistd.h>
 
-#include "pty-internal.h"
-
 #include <stdio-common/_itoa.h>
-#include <sys/sysmacros.h>
 
-/* Given the file descriptor of a master pty, return the pathname
-   of the associated slave.  */
+/* Directory where we can find the slave pty nodes.  */
+#define _PATH_DEVPTS "/dev/pts/"
 
-static char namebuf[PTYNAMELEN];
-extern const char __ptyname1[], __ptyname2[]; /* Defined in getpt.c.  */
+/* The are declared in getpt.c.  */
+extern const char *__libc_ptyname1;
+extern const char *__libc_ptyname2;
 
+/* Static buffer for `ptsname'.  */
+static char buffer[sizeof (_PATH_DEVPTS) + 20];
+
+
+/* Return the pathname of the pseudo terminal slave assoicated with
+   the master FD is open on, or NULL on errors.
+   The returned storage is good until the next call to this function.  */
 char *
-ptsname (fd)
-     int fd;
+ptsname (int fd)
 {
-  return __ptsname_r (fd, namebuf, PTYNAMELEN) != 0 ? NULL : namebuf;
+  return __ptsname_r (fd, buffer, sizeof (buffer)) != 0 ? NULL : buffer;
 }
 
+
+/* 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 (fd, buf, buflen)
-     int fd;
-     char *buf;
-     size_t buflen;
+__ptsname_r (int fd, char *buf, size_t buflen)
 {
+  int save_errno = errno;
   struct stat st;
-  int save = errno;
   int ptyno;
-  char nbuf[PTYNAMELEN], idbuf[6];
-  char *cp;
-
-#ifdef TIOCGPTN
-  static int tiocgptn_works = 1;
-#endif
-
-  if (!buf)
+  
+  if (buf == NULL)
     {
       __set_errno (EINVAL);
       return EINVAL;
@@ -73,61 +73,60 @@ __ptsname_r (fd, buf, buflen)
     }
 
 #ifdef TIOCGPTN
-  if (tiocgptn_works)
+  if (__ioctl (fd, TIOCGPTN, &ptyno) == 0)
     {
-      if (__ioctl (fd, TIOCGPTN, &ptyno) == 0)
-	goto gotit;
-      else
+      /* Buffer we use to print the number in.  For a maximum size for
+         `int' of 8 bytes we never need more than 20 digits.  */
+      char numbuf[21];
+      const char *devpts = _PATH_DEVPTS;
+      const size_t devptslen = strlen (devpts);
+      char *p;
+
+      numbuf[20] = '\0';
+      p = _itoa_word (ptyno, &numbuf[20], 10, 0);
+
+      if (buflen < devptslen + strlen (p) + 1)
 	{
-	  if(errno != EINVAL)
-	    return errno;
-	  else
-	    tiocgptn_works = 0;
+	  __set_errno (ERANGE);
+	  return ERANGE;
 	}
-    }
-#endif
-  if (__fxstat (_STAT_VER, fd, &st) < 0)
-    return errno;
 
-  ptyno = minor (st.st_rdev);
-  if (major (st.st_rdev) == 4)
-    ptyno -= 128;
-
-#ifdef TIOCGPTN
- gotit:
+      __stpcpy (__stpcpy (buf, devpts), p);
+    }
+  else if (errno == EINVAL)
 #endif
-  /* Two different possible naming schemes for pty slaves:
-     the SVr4 way.  */
-
-  idbuf[5] = '\0';
-  __stpcpy (__stpcpy (nbuf, "/dev/pts/"),
-	    _itoa_word (ptyno, &idbuf[5], 10, 0));
-  if (__xstat (_STAT_VER, nbuf, &st) < 0)
     {
-      if (errno != ENOENT)
-	return errno;
-
-      /* ...and the BSD way.  */
-      nbuf[5]  = 't';
-      nbuf[7]  = 'y';
-      nbuf[8]  = __ptyname1[ptyno / 16];
-      nbuf[9]  = __ptyname2[ptyno % 16];
-      nbuf[10] = '\0';
+      char *p;
+      
+      if (buflen < strlen (_PATH_TTY) + 3)
+	{
+	  __set_errno (ERANGE);
+	  return ERANGE;
+	}
 
-      if (__xstat (_STAT_VER, nbuf, &st) < 0)
+      if (__fstat (fd, &st) < 0)
 	return errno;
-    }
 
-  if (buflen < strlen (nbuf) + 1)
-    {
-      __set_errno (ERANGE);
-      return ERANGE;
-    }
+      ptyno = minor (st.st_rdev);
+      if (major (st.st_rdev) == 4)
+	ptyno -= 128;
 
-  cp = __stpncpy (buf, nbuf, buflen);
-  cp[0] = '\0';
+      if (ptyno / 16 >= strlen (__libc_ptyname1))
+	{
+	  __set_errno (ENOTTY);
+	  return ENOTTY;
+	}
+      
+      p = __stpcpy (buf, _PATH_TTY);
+      p[0] = __libc_ptyname1[ptyno / 16];
+      p[1] = __libc_ptyname2[ptyno % 16];
+      p[2] = '\0';
+    }
+    
+  if (__stat (buf, &st) < 0)
+    return errno;
 
-  __set_errno (save);
+  __set_errno (save_errno);
   return 0;
 }
 weak_alias (__ptsname_r, ptsname_r)
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S b/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S
new file mode 100644
index 0000000000..84f2eeca2f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/socket.S
@@ -0,0 +1,80 @@
+/* Copyright (C) 1997, 1998 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Miguel de Icaza <miguel@gnu.ai.mit.edu>, 1997.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 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
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU C Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+   Boston, MA 02111-1307, USA.  */
+
+#include <sysdep.h>
+#include <socketcall.h>
+
+#define P(a, b) P2(a, b)
+#define P2(a, b) a##b
+
+#ifndef NARGS
+#ifdef socket
+#error NARGS not defined
+#endif
+#define NARGS 3
+#endif
+
+	.text
+/* The socket-oriented system calls are handled unusually in Linux.
+   They are all gated through the single `socketcall' system call number.
+   `socketcall' takes two arguments: the first is the subcode, specifying
+   which socket function is being called; and the second is a pointer to
+   the arguments to the specific function.
+
+   The .S files for the other calls just #define socket and #include this.  */
+
+#ifndef __socket
+#define __socket P(__,socket)
+#endif
+
+.globl __socket
+ENTRY (__socket)
+
+	/* Drop up to 6 arguments (recvfrom) into the memory allocated by
+	   the caller for varargs, since that's really what we have.  */
+	stx	%o0, [%sp + STACK_BIAS + 128 + 0]
+	stx	%o1, [%sp + STACK_BIAS + 128 + 8]
+#if NARGS > 2
+	stx	%o2, [%sp + STACK_BIAS + 128 + 16]
+#if NARGS > 3
+	stx	%o3, [%sp + STACK_BIAS + 128 + 24]
+#if NARGS > 4
+	stx	%o4, [%sp + STACK_BIAS + 128 + 32]
+#if NARGS > 5
+	stx	%o5, [%sp + STACK_BIAS + 128 + 40]
+#endif
+#endif
+#endif
+#endif
+
+	mov	P(SOCKOP_,socket), %o0		/* arg 1: socket subfunction */
+	add	%sp, STACK_BIAS + 128, %o1	/* arg 2: parameter block */
+	LOADSYSCALL(socketcall)
+	ta	0x6d
+
+        bcs,pn	%xcc, 1f
+	 nop
+	retl
+	 nop
+
+1:	SYSCALL_ERROR_HANDLER
+
+END (__socket)
+
+weak_alias (__socket, socket)
diff --git a/sysdeps/unix/sysv/linux/unlockpt.c b/sysdeps/unix/sysv/linux/unlockpt.c
index e20545fe80..4df33198ef 100644
--- a/sysdeps/unix/sysv/linux/unlockpt.c
+++ b/sysdeps/unix/sysv/linux/unlockpt.c
@@ -17,33 +17,33 @@
    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.  */
 
-#include <sys/ioctl.h>
-#include <termios.h>
 #include <errno.h>
 #include <stdlib.h>
+#include <sys/ioctl.h>
+#include <termios.h>
+
 
-/* Given a fd on a master pseudoterminal, clear a kernel lock so that
-   the slave can be opened.  This is to avoid a race between opening the
-   master and calling grantpt() to take possession of the slave.  */
+/* Unlock the slave pseudo terminal associated with the master pseudo
+   terminal specified by FD.  */
 int
-unlockpt (fd)
-     int fd __attribute__ ((unused));
+unlockpt (int fd)
 {
 #ifdef TIOCSPTLCK
-  int serrno = errno;
+  int save_errno = errno;
   int unlock = 0;
 
   if (__ioctl (fd, TIOCSPTLCK, &unlock))
     {
       if (errno == EINVAL)
 	{
-	  __set_errno (serrno);
+	  __set_errno (save_errno);
 	  return 0;
 	}
       else
 	return -1;
     }
 #endif
-  /* On pre-/dev/ptmx kernels this function should be a no-op.  */
+  /* If we have no TIOCSPTLCK ioctl, all slave pseudo terminals are
+     unlocked by default.  */
   return 0;
 }