[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/4] ptsname_r: use instead of ptsname
From: |
Eric Blake |
Subject: |
[PATCH 5/4] ptsname_r: use instead of ptsname |
Date: |
Wed, 9 Nov 2011 16:51:57 -0700 |
We might as well be ready for thread-safety, if ptsname_r is
improved to add appropriate locking.
* lib/openpty.c (openpty): Convert for thread-safety.
* lib/unlockpt.c (unlockpt): Likewise.
* modules/openpty (Depends-on): Add ptsname_r.
* modules/unlockpt (Depends-on): Likewise.
* lib/pt_chown.c (do_pt_chown): Document safety.
Signed-off-by: Eric Blake <address@hidden>
---
Again, I'll wait for feedback before pushing this (in part
because right now ptsname_r fails on platforms where the
existing use of ptsname succeeds, while we debate about
making ptsname_r be implemented as a lock around ptsname).
ChangeLog | 7 +++++++
lib/openpty.c | 5 ++---
lib/pt_chown.c | 3 ++-
lib/unlockpt.c | 4 ++--
modules/openpty | 1 +
modules/unlockpt | 2 +-
6 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 404b95d..6cc7e22 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2011-11-09 Eric Blake <address@hidden>
+ ptsname_r: use instead of ptsname
+ * lib/openpty.c (openpty): Convert for thread-safety.
+ * lib/unlockpt.c (unlockpt): Likewise.
+ * modules/openpty (Depends-on): Add ptsname_r.
+ * modules/unlockpt (Depends-on): Likewise.
+ * lib/pt_chown.c (do_pt_chown): Document safety.
+
ptsname_r-tests: new test module
* modules/ptsname_r-tests: New module.
* tests/test-ptsname_r.c: New file.
diff --git a/lib/openpty.c b/lib/openpty.c
index d9d9773..5fb5df3 100644
--- a/lib/openpty.c
+++ b/lib/openpty.c
@@ -64,7 +64,7 @@ openpty (int *amaster, int *aslave, char *name,
struct termios const *termp, struct winsize const *winp)
{
int master;
- char *slave_name;
+ char slave_name[256];
int slave;
# if HAVE__GETPTY /* IRIX */
@@ -93,8 +93,7 @@ openpty (int *amaster, int *aslave, char *name,
goto fail;
# if !HAVE__GETPTY /* !IRIX */
- slave_name = ptsname (master);
- if (slave_name == NULL)
+ if (ptsname_r (master, slave_name, sizeof slave_name))
goto fail;
# endif
diff --git a/lib/pt_chown.c b/lib/pt_chown.c
index ccc04fd..bbefe29 100644
--- a/lib/pt_chown.c
+++ b/lib/pt_chown.c
@@ -41,7 +41,8 @@ do_pt_chown (void)
struct group *p;
gid_t gid;
- /* Check that PTY_FILENO is a valid master pseudo terminal. */
+ /* Check that PTY_FILENO is a valid master pseudo terminal.
+ pt_chown is single-threaded, so no need to drag in ptsname_r. */
pty = ptsname (PTY_FILENO);
if (pty == NULL)
return errno == EBADF ? FAIL_EBADF : FAIL_EINVAL;
diff --git a/lib/unlockpt.c b/lib/unlockpt.c
index 6785487..f8abd68 100644
--- a/lib/unlockpt.c
+++ b/lib/unlockpt.c
@@ -30,8 +30,8 @@ unlockpt (int fd)
#if HAVE_REVOKE
/* MacOS X 10.3, OpenBSD 3.8 do not have the unlockpt function, but they
have revoke(). */
- char *name = ptsname (fd);
- if (name == NULL)
+ char name[256];
+ if (ptsname_r (fd, name, sizeof name))
return -1;
return revoke (name);
#else
diff --git a/modules/openpty b/modules/openpty
index 8d174da..0f99664 100644
--- a/modules/openpty
+++ b/modules/openpty
@@ -10,6 +10,7 @@ pty
extensions
fcntl-h [test $HAVE_OPENPTY = 0 || test $REPLACE_OPENPTY = 1]
posix_openpt [test $HAVE_OPENPTY = 0 || test $REPLACE_OPENPTY = 1]
+ptsname_r [test $HAVE_OPENPTY = 0 || test $REPLACE_OPENPTY = 1]
ioctl [test $HAVE_OPENPTY = 0 || test $REPLACE_OPENPTY = 1]
configure.ac:
diff --git a/modules/unlockpt b/modules/unlockpt
index c917964..063b575 100644
--- a/modules/unlockpt
+++ b/modules/unlockpt
@@ -10,7 +10,7 @@ Depends-on:
stdlib
extensions
fcntl-h [test $HAVE_UNLOCKPT = 0]
-ptsname [test $HAVE_UNLOCKPT = 0]
+ptsname_r [test $HAVE_UNLOCKPT = 0]
configure.ac:
gl_FUNC_UNLOCKPT
--
1.7.4.4
- Re: [PATCH 1/4] ptsname_r: new module, (continued)
- Re: [PATCH 1/4] ptsname_r: new module, Jim Meyering, 2011/11/10
- Re: [PATCH 1/4] ptsname_r: new module, Bruno Haible, 2011/11/10
- Re: [PATCH 1/4] ptsname_r: new module, Gary V. Vaughan, 2011/11/09
- Re: [PATCH 1/4] ptsname_r: new module, Bruno Haible, 2011/11/09
- Re: [PATCH 1/4] ptsname_r: new module, Gary V. Vaughan, 2011/11/09
- Re: [PATCH 1/4] ptsname_r: new module, Eric Blake, 2011/11/09
- Re: [PATCH 1/4] ptsname_r: new module, Karl Berry, 2011/11/09
[RFC PATCH 2.5/4] ptsname_r: work with POSIX isatty, for Solaris, Eric Blake, 2011/11/09
[PATCH 5/4] ptsname_r: use instead of ptsname,
Eric Blake <=