public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] tst-spawn6.c: Skip if _PATH_TTY doesn't exist [BZ #28836]
@ 2022-01-29 15:45 H.J. Lu
  2022-01-29 20:04 ` Adhemerval Zanella
  0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2022-01-29 15:45 UTC (permalink / raw)
  To: libc-alpha

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
@@ -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.  */
   {
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-29 20:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-29 15:45 [PATCH] tst-spawn6.c: Skip if _PATH_TTY doesn't exist [BZ #28836] H.J. Lu
2022-01-29 20:04 ` Adhemerval Zanella

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).