about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--sysdeps/unix/sysv/linux/ttyname.c23
-rw-r--r--sysdeps/unix/sysv/linux/ttyname_r.c29
3 files changed, 36 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index 0a8ed4ffb1..b5de71db3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 1999-03-05  Ulrich Drepper  <drepper@cygnus.com>
 
+	* sysdeps/unix/sysv/linux/ttyname_r.c (__ttyname_r): Remember
+	whether /dev/pts is available.
+	* sysdeps/unix/sysv/linux/ttyname.c (ttyname): Fix handling of
+	dev_pts_available.
+
 	* posix/globtest.sh: Make common_objpfx path absolute and and db2
 	and hesiod directory to library path [PR libc/1007].
 
diff --git a/sysdeps/unix/sysv/linux/ttyname.c b/sysdeps/unix/sysv/linux/ttyname.c
index a32d1a6605..9d345b8b94 100644
--- a/sysdeps/unix/sysv/linux/ttyname.c
+++ b/sysdeps/unix/sysv/linux/ttyname.c
@@ -111,7 +111,7 @@ ttyname (fd)
   char procname[30];
   struct stat st, st1;
   int dostat = 0;
-  char *name;
+  char *name = NULL;
   int save = errno;
 
   if (!__isatty (fd))
@@ -139,20 +139,21 @@ ttyname (fd)
   if (__fxstat (_STAT_VER, fd, &st) < 0)
     return NULL;
 
-  if (dev_pts_available
-      && __xstat (_STAT_VER, "/dev/pts", &st1) == 0 && S_ISDIR (st1.st_mode))
+  if (dev_pts_available)
     {
+      if (__xstat (_STAT_VER, "/dev/pts", &st1) == 0 && S_ISDIR (st1.st_mode))
+	{
 #ifdef _STATBUF_ST_RDEV
-      name = getttyname ("/dev/pts", st.st_rdev, st.st_ino, save, &dostat);
+	  name = getttyname ("/dev/pts", st.st_rdev, st.st_ino, save, &dostat);
 #else
-      name = getttyname ("/dev/pts", st.st_dev, st.st_ino, save, &dostat);
+	  name = getttyname ("/dev/pts", st.st_dev, st.st_ino, save, &dostat);
 #endif
-    }
-  else
-    {
-      __set_errno (save);
-      name = NULL;
-      dev_pts_available = 1;
+	}
+      else
+	{
+	  __set_errno (save);
+	  dev_pts_available = 0;
+	}
     }
 
   if (!name && dostat != -1)
diff --git a/sysdeps/unix/sysv/linux/ttyname_r.c b/sysdeps/unix/sysv/linux/ttyname_r.c
index b92c712fcc..ae5a029e65 100644
--- a/sysdeps/unix/sysv/linux/ttyname_r.c
+++ b/sysdeps/unix/sysv/linux/ttyname_r.c
@@ -103,6 +103,7 @@ __ttyname_r (fd, buf, buflen)
      char *buf;
      size_t buflen;
 {
+  static int dev_pts_available = 1;
   char procname[30];
   struct stat st, st1;
   int dostat = 0;
@@ -148,20 +149,28 @@ __ttyname_r (fd, buf, buflen)
   memcpy (buf, "/dev/pts/", sizeof ("/dev/pts/"));
   buflen -= sizeof ("/dev/pts/") - 1;
 
-  if (__xstat (_STAT_VER, buf, &st1) == 0 && S_ISDIR (st1.st_mode))
+  if (dev_pts_available)
     {
+      if (__xstat (_STAT_VER, buf, &st1) == 0 && S_ISDIR (st1.st_mode))
+	{
 #ifdef _STATBUF_ST_RDEV
-      ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,
-			  &dostat);
+	  ret = getttyname_r (buf, buflen, st.st_rdev, st.st_ino, save,
+			      &dostat);
 #else
-      ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,
-			  &dostat);
+	  ret = getttyname_r (buf, buflen, st.st_dev, st.st_ino, save,
+			      &dostat);
 #endif
-    }
-  else
-    {
-      __set_errno (save);
-      ret = ENOENT;
+	}
+      else
+	{
+	  __set_errno (save);
+	  ret = ENOENT;
+	}
+      else
+	{
+	  __set_errno (save);
+	  dev_pts_available = 0;
+	}
     }
 
   if (ret && dostat != -1)