about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog25
-rw-r--r--login/Makefile2
-rw-r--r--login/tst-grantpt.c78
-rw-r--r--sysdeps/generic/sysconf.c5
-rw-r--r--sysdeps/posix/sysconf.c3
-rw-r--r--sysdeps/unix/grantpt.c8
-rw-r--r--sysdeps/unix/sysv/linux/grantpt.c29
-rw-r--r--sysdeps/unix/sysv/linux/sparc/sparc64/clone.S2
8 files changed, 137 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 52cf6559cc..7e2129a60a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2001-12-18  Jakub Jelinek  <jakub@redhat.com>
+
+	* sysdeps/unix/sysv/linux/sparc/sparc64/clone.S (clone): Subtract
+	stack bias from child stack pointer before passing it to clone syscall.
+
+2001-12-18  Ulrich Drepper  <drepper@redhat.com>
+
+	* sysdeps/posix/sysconf.c (__sysconf): Respect POSIX minimum for
+	_SC_TZNAME_MAX.
+	* sysdeps/generic/sysconf.c (__sysconf): Likewise.
+	Reported by Thorsten Kukuk <kukuk@suse.de>.
+
+	* sysdeps/unix/grantpt.c (grantpt): Correct typo in comment and
+	add some casts.
+
+	* sysdeps/unix/sysv/linux/grantpt.c: Make __unix_grantpt static.
+
+2001-12-18  Thorsten Kukuk  <kukuk@suse.de>
+
+	* sysdeps/unix/sysv/linux/grantpt.c: Make errno results standard
+	conforming: return EBADF if file descriptor is invalid and EINVAL
+	if file descriptor is no valid tty.
+	* login/tst-grantpt.c: New file.
+	* login/Makefile (tests): Add tst-grantpt.
+
 2001-12-17  Ulrich Drepper  <drepper@redhat.com>
 
 	* io/ftw.c (ftw_dir): Handle inaccessibility of toplevel dir
diff --git a/login/Makefile b/login/Makefile
index b1fd3055e7..97fab761f3 100644
--- a/login/Makefile
+++ b/login/Makefile
@@ -37,7 +37,7 @@ distribute := utmp-private.h pty-private.h
 subdir-dirs = programs
 vpath %.c programs
 
-tests := tst-utmp tst-utmpx
+tests := tst-utmp tst-utmpx tst-grantpt
 
 # Build the -lutil library with these extra functions.
 extra-libs      := libutil
diff --git a/login/tst-grantpt.c b/login/tst-grantpt.c
new file mode 100644
index 0000000000..9b993daaca
--- /dev/null
+++ b/login/tst-grantpt.c
@@ -0,0 +1,78 @@
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
+static int
+test_ebadf (void)
+{
+  int fd, ret, err;
+
+  fd = posix_openpt (O_RDWR);
+  if (fd == -1)
+    {
+      printf ("posix_openpt(O_RDWR) failed\nerrno %d (%s)\n",
+	      errno, strerror (errno));
+      /* We don't fail because of this; maybe the system does not have
+	 SUS pseudo terminals.  */
+      return 0;
+    }
+  unlockpt (fd);
+  close (fd);
+
+  ret = grantpt (fd);
+  err = errno;
+  if (ret != -1 || err != EBADF)
+    {
+      printf ("grantpt(): expected: return = %d, errno = %d\n", -1, EBADF);
+      printf ("           got: return = %d, errno = %d\n", ret, err);
+      return 1;
+    }
+  return 0;
+}
+
+static int
+test_einval (void)
+{
+  int fd, ret, err;
+  const char file[] = "./grantpt-einval";
+
+  fd = open (file, O_RDWR | O_CREAT);
+  if (fd == -1)
+    {
+      printf ("open(\"%s\", O_RDWR) failed\nerrno %d (%s)\n",
+	      file, errno, strerror (errno));
+      return 0;
+    }
+  unlink (file);
+
+  ret = grantpt (fd);
+  err = errno;
+  if (ret != -1 || err != EINVAL)
+    {
+      printf ("grantpt(): expected: return = %d, errno = %d\n", -1, EINVAL);
+      printf ("           got: return = %d, errno = %d\n", ret, err);
+      ret = 1;
+    }
+  else
+    ret = 0;
+
+  close (fd);
+
+  return ret;
+}
+
+int
+main (void)
+{
+  int result = 0;
+
+  result += test_ebadf ();
+  result += test_einval ();
+
+  return result;
+}
diff --git a/sysdeps/generic/sysconf.c b/sysdeps/generic/sysconf.c
index 70f77b7a54..8816ddc682 100644
--- a/sysdeps/generic/sysconf.c
+++ b/sysdeps/generic/sysconf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1993, 1995, 1996, 1997 Free Software Foundation, Inc.
+/* Copyright (C) 1991,1993,1995,1996,1997,2001 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
@@ -21,6 +21,7 @@
 #include <unistd.h>
 #include <time.h>
 #include <limits.h>
+#include <sys/param.h>
 #include <sys/sysinfo.h>
 
 
@@ -36,7 +37,7 @@ __sysconf (name)
       return -1;
 
     case _SC_TZNAME_MAX:
-      return __tzname_max ();
+      return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
 
     case _SC_CHARCLASS_NAME_MAX:
 #ifdef	CHARCLASS_NAME_MAX
diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
index 46146c5396..05a9538271 100644
--- a/sysdeps/posix/sysconf.c
+++ b/sysdeps/posix/sysconf.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/param.h>
 #include <sys/sysinfo.h>
 #include <sys/types.h>
 #include <regex.h>
@@ -75,7 +76,7 @@ __sysconf (name)
 #endif
 
     case _SC_TZNAME_MAX:
-      return __tzname_max ();
+      return MAX (__tzname_max (), _POSIX_TZNAME_MAX);
 
     case _SC_JOB_CONTROL:
 #ifdef	_POSIX_JOB_CONTROL
diff --git a/sysdeps/unix/grantpt.c b/sysdeps/unix/grantpt.c
index f86e07c242..dad7d16b43 100644
--- a/sysdeps/unix/grantpt.c
+++ b/sysdeps/unix/grantpt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 2000, 2001 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@rabi.phys.columbia.edu>, 1998.
 
@@ -64,9 +64,9 @@ pts_name (int fd, char **pts, size_t buf_len)
 
       if (buf != *pts)
 	/* We've already malloced another buffer at least once.  */
-	new_buf = realloc (buf, buf_len);
+	new_buf = (char *) realloc (buf, buf_len);
       else
-	new_buf = malloc (buf_len);
+	new_buf = (char *) malloc (buf_len);
       if (! new_buf)
 	{
 	  rv = -1;
@@ -159,7 +159,7 @@ grantpt (int fd)
       struct rlimit rl = { 0, 0 };
       __setrlimit (RLIMIT_CORE, &rl);
 
-      /* We pase the master pseudo terminal as file descriptor PTY_FILENO.  */
+      /* We pass the master pseudo terminal as file descriptor PTY_FILENO.  */
       if (fd != PTY_FILENO)
 	if (__dup2 (fd, PTY_FILENO) < 0)
 	  _exit (FAIL_EBADF);
diff --git a/sysdeps/unix/sysv/linux/grantpt.c b/sysdeps/unix/sysv/linux/grantpt.c
index 55e4f36c32..168081758f 100644
--- a/sysdeps/unix/sysv/linux/grantpt.c
+++ b/sysdeps/unix/sysv/linux/grantpt.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2001 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
@@ -16,6 +16,8 @@
    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
    02111-1307 USA.  */
 
+#include <errno.h>
+#include <fcntl.h>
 #include <limits.h>
 #include <stdlib.h>
 #include <sys/statfs.h>
@@ -25,7 +27,7 @@
 /* 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);
+static int __unix_grantpt (int fd);
 
 /* Prototype for private function that gets the name of the slave
    pseudo terminal in a safe way.  */
@@ -45,9 +47,24 @@ grantpt (int fd)
 #endif
   char *buf = _buf;
 
-  if (pts_name (fd, &buf, sizeof (_buf)))
-    return -1;
-  
+  if (__builtin_expect (pts_name (fd, &buf, sizeof (_buf)), 0))
+    {
+      int save_errno = errno;
+
+      /* Check, if the file descriptor is valid. pts_name returns the
+	 wrong errno number, so we cannot use that.  */
+      if (__libc_fcntl (fd, F_GETFD) == -1 && errno == EBADF)
+	return -1;
+
+      __set_errno (save_errno);
+
+       /* If the filedescriptor is no TTY, grantpt has to set errno
+          to EINVAL.  */
+       if (errno == ENOTTY)
+         __set_errno (EINVAL);
+       return -1;
+    }
+
   if (__statfs (buf, &fsbuf) < 0)
     return -1;
 
@@ -59,5 +76,5 @@ grantpt (int fd)
   return __unix_grantpt (fd);
 }
 
-#define grantpt __unix_grantpt
+#define grantpt static __unix_grantpt
 #include <sysdeps/unix/grantpt.c>
diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S b/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S
index 957a928f36..a7c248b2e8 100644
--- a/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S
+++ b/sysdeps/unix/sysv/linux/sparc/sparc64/clone.S
@@ -40,7 +40,7 @@ __clone:
 	 mov	%i3, %l3		/* save arg */
 
 	/* Do the system call */
-	mov	%i1, %o1
+	sub	%i1, 0x7ff, %o1
 	mov	%i2, %o0
 	set	__NR_clone, %g1
 	ta	0x6d