tst-spawn6.c: Skip if _PATH_TTY doesn't exist [BZ #28836]

Message ID 20220129154518.4192-1-hjl.tools@gmail.com
State Dropped
Headers
Series tst-spawn6.c: Skip if _PATH_TTY doesn't exist [BZ #28836] |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent
dj/TryBot-32bit success Build for i686

Commit Message

H.J. Lu Jan. 29, 2022, 3:45 p.m. UTC
  posix/tst-spawn6 fails with

error: xopen.c:28: open64 ("/dev/tty", 0x0, 0600): No such device or address

when there is no one logged in.  Skip tst-spawn6 if _PATH_TTY doesn't
exist.  This fixes BZ #28836.
---
 posix/tst-spawn6.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
  

Comments

Adhemerval Zanella Jan. 29, 2022, 8:04 p.m. UTC | #1
On 29/01/2022 12:45, H.J. Lu wrote:
> posix/tst-spawn6 fails with
> 
> error: xopen.c:28: open64 ("/dev/tty", 0x0, 0600): No such device or address
> 
> when there is no one logged in.  Skip tst-spawn6 if _PATH_TTY doesn't
> exist.  This fixes BZ #28836.
> ---
>  posix/tst-spawn6.c | 19 +++++++++++++++++--
>  1 file changed, 17 insertions(+), 2 deletions(-)
> 
> diff --git a/posix/tst-spawn6.c b/posix/tst-spawn6.c
> index 5f95bd1938..72fbab4db3 100644
> --- a/posix/tst-spawn6.c
> +++ b/posix/tst-spawn6.c
> @@ -30,10 +30,25 @@
>  #include <support/xunistd.h>
>  #include <sys/wait.h>
>  
> +static int
> +open_tty (int flags, mode_t mode)
> +{
> +  int ret = open64 (_PATH_TTY, flags, mode);
> +  if (ret < 0)
> +    {
> +      /* NB: Skip the test if _PATH_TTY doesn't exist.  */
> +      if (errno == ENXIO)
> +	FAIL_UNSUPPORTED ("\"%s\" doesn't exist", _PATH_TTY);
> +      FAIL_EXIT1 ("open64 (\"%s\", 0x%x, 0%o): %m",
> +		  _PATH_TTY, flags, mode);
> +    }
> +  return ret;
> +}
> +
>  static int
>  handle_restart (const char *argv1)
>  {
> -  int fd = xopen (_PATH_TTY, O_RDONLY, 0600);
> +  int fd = open_tty (O_RDONLY, 0600);
>  
>    /* If process group is not changed (POSIX_SPAWN_SETPGROUP), then check
>       the creating process one, otherwise check against the process group

I think that if tty can't be opened on the spawned process this is genuine
issue that should be reported.

> @@ -116,7 +131,7 @@ do_test (int argc, char *argv[])
>    if (restart)
>      return handle_restart (argv[1]);
>  
> -  int tcfd = xopen (_PATH_TTY, O_RDONLY, 0600);
> +  int tcfd = open_tty (O_RDONLY, 0600);
>  
>    /* Check getters and setters.  */
>    {

I will send an updated version of posix_spawn_file_actions_addtcsetpgrp_np
with this change.
  

Patch

diff --git a/posix/tst-spawn6.c b/posix/tst-spawn6.c
index 5f95bd1938..72fbab4db3 100644
--- a/posix/tst-spawn6.c
+++ b/posix/tst-spawn6.c
@@ -30,10 +30,25 @@ 
 #include <support/xunistd.h>
 #include <sys/wait.h>
 
+static int
+open_tty (int flags, mode_t mode)
+{
+  int ret = open64 (_PATH_TTY, flags, mode);
+  if (ret < 0)
+    {
+      /* NB: Skip the test if _PATH_TTY doesn't exist.  */
+      if (errno == ENXIO)
+	FAIL_UNSUPPORTED ("\"%s\" doesn't exist", _PATH_TTY);
+      FAIL_EXIT1 ("open64 (\"%s\", 0x%x, 0%o): %m",
+		  _PATH_TTY, flags, mode);
+    }
+  return ret;
+}
+
 static int
 handle_restart (const char *argv1)
 {
-  int fd = xopen (_PATH_TTY, O_RDONLY, 0600);
+  int fd = open_tty (O_RDONLY, 0600);
 
   /* If process group is not changed (POSIX_SPAWN_SETPGROUP), then check
      the creating process one, otherwise check against the process group
@@ -116,7 +131,7 @@  do_test (int argc, char *argv[])
   if (restart)
     return handle_restart (argv[1]);
 
-  int tcfd = xopen (_PATH_TTY, O_RDONLY, 0600);
+  int tcfd = open_tty (O_RDONLY, 0600);
 
   /* Check getters and setters.  */
   {