This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch master updated. glibc-2.26-543-g645ac9a


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  645ac9aaf89e3311949828546df6334322f48933 (commit)
       via  98e0742024d4c13c08a6076b3d119c250e7d0118 (commit)
      from  e7a574594931a8221b39432dc0637ec7423b14f6 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=645ac9aaf89e3311949828546df6334322f48933

commit 645ac9aaf89e3311949828546df6334322f48933
Author: Christian Brauner <christian.brauner@ubuntu.com>
Date:   Sun Oct 8 14:10:46 2017 +0200

    openpty: use TIOCGPTPEER to open slave side fd
    
    Newer kernels expose the ioctl TIOCGPTPEER [1] call to userspace which allows to
    safely allocate a file descriptor for a pty slave based solely on the master
    file descriptor. This allows us to avoid path-based operations and makes this
    function a lot safer in the face of devpts mounts in different mount namespaces.
    
    [1]: https://patchwork.kernel.org/patch/9760743/
    
    Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>

diff --git a/ChangeLog b/ChangeLog
index e1e98ad..da396ff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
 
 	* login/openpty.c (openpty): Close slave pty file descriptor on error.
 
+	* login/openpty.c (openpty): If defined, use the TIOCGPTPEER ioctl()
+	call to allocate the slave pty file descriptor.
+
 2017-10-06  Joseph Myers  <joseph@codesourcery.com>
 
 	* sysdeps/ieee754/ldbl-128/s_fma.c: Include <libm-alias-double.h>.
diff --git a/login/openpty.c b/login/openpty.c
index 9e556c2..6703128 100644
--- a/login/openpty.c
+++ b/login/openpty.c
@@ -94,6 +94,8 @@ openpty (int *amaster, int *aslave, char *name,
   char *buf = _buf;
   int master, ret = -1, slave = -1;
 
+  *buf = '\0';
+
   master = getpt ();
   if (master == -1)
     return -1;
@@ -104,12 +106,22 @@ openpty (int *amaster, int *aslave, char *name,
   if (unlockpt (master))
     goto on_error;
 
-  if (pts_name (master, &buf, sizeof (_buf)))
-    goto on_error;
-
-  slave = open (buf, O_RDWR | O_NOCTTY);
+#ifdef TIOCGPTPEER
+  /* Try to allocate slave fd solely based on master fd first. */
+  slave = ioctl (master, TIOCGPTPEER, O_RDWR | O_NOCTTY);
+#endif
   if (slave == -1)
-    goto on_error;
+    {
+      /* Fallback to path-based slave fd allocation in case kernel doesn't
+       * support TIOCGPTPEER.
+       */
+      if (pts_name (master, &buf, sizeof (_buf)))
+        goto on_error;
+
+      slave = open (buf, O_RDWR | O_NOCTTY);
+      if (slave == -1)
+        goto on_error;
+    }
 
   /* XXX Should we ignore errors here?  */
   if (termp)
@@ -122,7 +134,13 @@ openpty (int *amaster, int *aslave, char *name,
   *amaster = master;
   *aslave = slave;
   if (name != NULL)
-    strcpy (name, buf);
+    {
+      if (*buf == '\0')
+        if (pts_name (master, &buf, sizeof (_buf)))
+          goto on_error;
+
+      strcpy (name, buf);
+    }
 
   ret = 0;
 

http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=98e0742024d4c13c08a6076b3d119c250e7d0118

commit 98e0742024d4c13c08a6076b3d119c250e7d0118
Author: Christian Brauner <christian.brauner@ubuntu.com>
Date:   Sun Oct 8 14:09:47 2017 +0200

    openpty: close slave pty fd on error
    
    When openpty() failed only the master fd was closed so far. Let's close the
    slave fd as well. Also, let's unify the error handling.
    
    Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>

diff --git a/ChangeLog b/ChangeLog
index deec63d..e1e98ad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-10-08  Christian Brauner  <christian.brauner@ubuntu.com>
+
+	* login/openpty.c (openpty): Close slave pty file descriptor on error.
+
 2017-10-06  Joseph Myers  <joseph@codesourcery.com>
 
 	* sysdeps/ieee754/ldbl-128/s_fma.c: Include <libm-alias-double.h>.
diff --git a/login/openpty.c b/login/openpty.c
index 41ab048..9e556c2 100644
--- a/login/openpty.c
+++ b/login/openpty.c
@@ -92,29 +92,24 @@ openpty (int *amaster, int *aslave, char *name,
   char _buf[512];
 #endif
   char *buf = _buf;
-  int master, slave;
+  int master, ret = -1, slave = -1;
 
   master = getpt ();
   if (master == -1)
     return -1;
 
   if (grantpt (master))
-    goto fail;
+    goto on_error;
 
   if (unlockpt (master))
-    goto fail;
+    goto on_error;
 
   if (pts_name (master, &buf, sizeof (_buf)))
-    goto fail;
+    goto on_error;
 
   slave = open (buf, O_RDWR | O_NOCTTY);
   if (slave == -1)
-    {
-      if (buf != _buf)
-	free (buf);
-
-      goto fail;
-    }
+    goto on_error;
 
   /* XXX Should we ignore errors here?  */
   if (termp)
@@ -129,12 +124,19 @@ openpty (int *amaster, int *aslave, char *name,
   if (name != NULL)
     strcpy (name, buf);
 
+  ret = 0;
+
+ on_error:
+  if (ret == -1) {
+    close (master);
+
+    if (slave != -1)
+      close (slave);
+  }
+
   if (buf != _buf)
     free (buf);
-  return 0;
 
- fail:
-  close (master);
-  return -1;
+  return ret;
 }
 libutil_hidden_def (openpty)

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog       |    7 +++++++
 login/openpty.c |   52 ++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 43 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]