diff options
author | Florian Weimer <fweimer@redhat.com> | 2020-10-07 10:48:10 +0200 |
---|---|---|
committer | Florian Weimer <fweimer@redhat.com> | 2020-10-07 10:56:00 +0200 |
commit | 0f9793a556675d67d7c1897553f92e7152d1e598 (patch) | |
tree | 4f938bc2e03c843f8651a7b3afb0022fdd268ced /sysdeps | |
parent | c42b7058a2f8dea5c0b95e64aa82ee1d62a2ba14 (diff) | |
download | glibc-0f9793a556675d67d7c1897553f92e7152d1e598.tar.gz glibc-0f9793a556675d67d7c1897553f92e7152d1e598.tar.xz glibc-0f9793a556675d67d7c1897553f92e7152d1e598.zip |
Linux: unlockpt needs to fail with EINVAL, not ENOTTY (bug 26053)
The EINVAL error code is mandated by POSIX and documented in the manual. Also clean up the unlockpt implementation a bit, assuming that TIOCSPTLCK is always defined. Enhance login/tst-grantpt to cover unlockpt corner cases. Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Diffstat (limited to 'sysdeps')
-rw-r--r-- | sysdeps/unix/sysv/linux/unlockpt.c | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/sysdeps/unix/sysv/linux/unlockpt.c b/sysdeps/unix/sysv/linux/unlockpt.c index 3a0ac7a96c..4d98abece0 100644 --- a/sysdeps/unix/sysv/linux/unlockpt.c +++ b/sysdeps/unix/sysv/linux/unlockpt.c @@ -27,22 +27,11 @@ int unlockpt (int fd) { -#ifdef TIOCSPTLCK - int save_errno = errno; int unlock = 0; - if (__ioctl (fd, TIOCSPTLCK, &unlock)) - { - if (errno == EINVAL) - { - __set_errno (save_errno); - return 0; - } - else - return -1; - } -#endif - /* If we have no TIOCSPTLCK ioctl, all slave pseudo terminals are - unlocked by default. */ - return 0; + int ret = __ioctl (fd, TIOCSPTLCK, &unlock); + if (ret != 0 && errno == ENOTTY) + /* POSIX mandates EINVAL for non-ptmx descriptors. */ + __set_errno (EINVAL); + return ret; } |