1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-10-12 19:04:54 +03:00

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>
This commit is contained in:
Florian Weimer
2020-10-07 10:48:10 +02:00
parent c42b7058a2
commit 0f9793a556
2 changed files with 21 additions and 20 deletions

View File

@@ -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;
}