unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Adhemerval Zanella via Libc-alpha <libc-alpha@sourceware.org>
To: libc-alpha@sourceware.org, Florian Weimer <fweimer@redhat.com>
Subject: Re: [PATCH 2/3] Linux: unlockpt needs to fail with EINVAL, not ENOTTY (bug 26053)
Date: Thu, 13 Aug 2020 15:30:37 -0300	[thread overview]
Message-ID: <58e8ddb1-f821-6fac-77fb-44572dea9e7f@linaro.org> (raw)
In-Reply-To: <a5c22488f136c3532d4b0b30d5461c45bada08f7.1596611597.git.fweimer@redhat.com>



On 05/08/2020 04:14, Florian Weimer via Libc-alpha wrote:
> 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>

> ---
>  login/tst-grantpt.c                | 20 ++++++++++++++++----
>  sysdeps/unix/sysv/linux/unlockpt.c | 21 +++++----------------
>  2 files changed, 21 insertions(+), 20 deletions(-)
> 
> diff --git a/login/tst-grantpt.c b/login/tst-grantpt.c
> index 1d7a220fcf..8ca901ef94 100644
> --- a/login/tst-grantpt.c
> +++ b/login/tst-grantpt.c
> @@ -1,4 +1,4 @@
> -/* Test for grantpt error corner cases.
> +/* Test for grantpt, unlockpt error corner cases.
>     Copyright (C) 2001-2020 Free Software Foundation, Inc.
>     This file is part of the GNU C Library.
>  
> @@ -28,7 +28,7 @@
>  #include <support/temp_file.h>
>  #include <support/xunistd.h>
>  
> -/* Test grantpt with a closed descriptor.  */
> +/* Test grantpt, unlockpt with a closed descriptor.  */
>  static void
>  test_ebadf (void)
>  {
> @@ -48,9 +48,12 @@ test_ebadf (void)
>        printf ("grantpt(): expected: return = %d, errno = %d\n", -1, EBADF);
>        printf ("           got: return = %d, errno = %d\n", ret, err);
>      }
> +
> +  TEST_COMPARE (unlockpt (fd), -1);
> +  TEST_COMPARE (errno, EBADF);
>  }

Ok.

>  
> -/* Test grantpt on a regular file.  */
> +/* Test grantpt, unlockpt on a regular file.  */
>  static void
>  test_einval (void)
>  {
> @@ -68,10 +71,13 @@ test_einval (void)
>        printf ("           got: return = %d, errno = %d\n", ret, err);
>      }
>  
> +  TEST_COMPARE (unlockpt (fd), -1);
> +  TEST_COMPARE (errno, EINVAL);
> +
>    xclose (fd);
>  }
>  

Ok.

> -/* Test grantpt on a non-ptmx pseudo-terminal.  */
> +/* Test grantpt, unlockpt on a non-ptmx pseudo-terminal.  */
>  static void
>  test_not_ptmx (void)
>  {
> @@ -80,6 +86,9 @@ test_not_ptmx (void)
>    TEST_COMPARE (grantpt (ptmx), 0);
>    TEST_COMPARE (unlockpt (ptmx), 0);
>  
> +  /* A second unlock succeeds as well.  */
> +  TEST_COMPARE (unlockpt (ptmx), 0);
> +
>    const char *name = ptsname (ptmx);
>    TEST_VERIFY_EXIT (name != NULL);
>    int pts = open (name, O_RDWR | O_NOCTTY);

Ok.

> @@ -88,6 +97,9 @@ test_not_ptmx (void)
>    TEST_COMPARE (grantpt (pts), -1);
>    TEST_COMPARE (errno, EINVAL);
>  
> +  TEST_COMPARE (unlockpt (pts), -1);
> +  TEST_COMPARE (errno, EINVAL);
> +
>    xclose (pts);
>    xclose (ptmx);
>  }

Ok.

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

Ok.

  reply	other threads:[~2020-08-13 18:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-05  7:14 [PATCH 1/3] login/tst-grantpt: Convert to support framework, more error checking Florian Weimer via Libc-alpha
2020-08-05  7:14 ` [PATCH 2/3] Linux: unlockpt needs to fail with EINVAL, not ENOTTY (bug 26053) Florian Weimer via Libc-alpha
2020-08-13 18:30   ` Adhemerval Zanella via Libc-alpha [this message]
2020-08-05  7:14 ` [PATCH 3/3] Linux: Require properly configured /dev/pts for PTYs Florian Weimer via Libc-alpha
2020-08-13 18:53   ` Adhemerval Zanella via Libc-alpha
2020-08-13 18:21 ` [PATCH 1/3] login/tst-grantpt: Convert to support framework, more error checking Adhemerval Zanella via Libc-alpha
2020-08-13 18:31   ` Florian Weimer
2020-08-13 18:58     ` Adhemerval Zanella via Libc-alpha
  -- strict thread matches above, loose matches on Subject: below --
2020-05-27 10:14 [PATCH 0/3] Linux: Rework Linux PTY support Florian Weimer via Libc-alpha
2020-05-27 10:14 ` [PATCH 2/3] Linux: unlockpt needs to fail with EINVAL, not ENOTTY (bug 26053) Florian Weimer via Libc-alpha
2020-10-02 17:10   ` Adhemerval Zanella via Libc-alpha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=58e8ddb1-f821-6fac-77fb-44572dea9e7f@linaro.org \
    --to=libc-alpha@sourceware.org \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).