public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] support: Improve tst-support_descriptors compatibility with containers
@ 2026-05-04 13:24 Florian Weimer
  2026-05-04 13:59 ` Carlos O'Donell
  0 siblings, 1 reply; 2+ messages in thread
From: Florian Weimer @ 2026-05-04 13:24 UTC (permalink / raw)
  To: libc-alpha

If /dev/null is bind-mounted, /dev and /dev/null are on different
devices, so the expected failure has an additional line describe
the device change.

---
 support/tst-support_descriptors.c | 41 ++++++++++++++++++++++++++++++++-------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/support/tst-support_descriptors.c b/support/tst-support_descriptors.c
index 97d7284c69..d25cb7d67a 100644
--- a/support/tst-support_descriptors.c
+++ b/support/tst-support_descriptors.c
@@ -128,21 +128,48 @@ test_run (void)
   support_capture_subprocess_free (&proc);
   free (expected);
 
+  good = good && !support_record_failure_is_failed ();
+  proc = support_capture_subprocess (&subprocess_changed_descriptor, NULL);
+  good = good && support_record_failure_is_failed ();
+  support_record_failure_reset (); /* Discard the reported error.  */
+  report_subprocess_output ("subprocess_changed_descriptor", &proc);
+
   expected = xasprintf ("\nDifferences:\n"
                         "error: descriptor %d changed from \"/dev/null\""
                         " to \"/dev\"\n"
                         "error: descriptor %d changed ino ",
                         free_descriptor, free_descriptor);
-  good = good && !support_record_failure_is_failed ();
-  proc = support_capture_subprocess (&subprocess_changed_descriptor, NULL);
-  good = good && support_record_failure_is_failed ();
-  support_record_failure_reset (); /* Discard the reported error.  */
-  report_subprocess_output ("subprocess_changed_descriptor", &proc);
-  TEST_VERIFY (strstr (proc.out.buffer, expected) != NULL);
+  if (strstr (proc.out.buffer, expected) != NULL)
+    {
+      /* No change of device.  */
+      free (expected);
+    }
+  else
+    {
+      /* The device changed in addition to the inode number.  This
+         happens if /dev/null is bind-mounted from another file
+         system, so that /dev is on a difference device.  */
+      expected = xasprintf ("\nDifferences:\n"
+                            "error: descriptor %d changed from \"/dev/null\""
+                            " to \"/dev\"\n"
+                            "error: descriptor %d changed device ",
+                            free_descriptor, free_descriptor);
+      TEST_VERIFY (strstr (proc.out.buffer, expected) != NULL);
+      free (expected);
+
+      /* We assume that the inode number changes, although in theory
+         it is possible that the directory happens to have the same
+         inode number as the null device because it is on a different
+         file system.  */
+      expected = xasprintf ("\nerror: descriptor %d changed ino ",
+                            free_descriptor);
+      TEST_VERIFY (strstr (proc.out.buffer, expected) != NULL);
+      free (expected);
+    }
+
   support_capture_subprocess_check (&proc, "subprocess_changed_descriptor",
                                     0, sc_allow_stdout);
   support_capture_subprocess_free (&proc);
-  free (expected);
 }
 
 static int

base-commit: ef2e5453b166b9339fd92b685c10312b423be7eb


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

* Re: [PATCH] support: Improve tst-support_descriptors compatibility with containers
  2026-05-04 13:24 [PATCH] support: Improve tst-support_descriptors compatibility with containers Florian Weimer
@ 2026-05-04 13:59 ` Carlos O'Donell
  0 siblings, 0 replies; 2+ messages in thread
From: Carlos O'Donell @ 2026-05-04 13:59 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha

On 5/4/26 9:24 AM, Florian Weimer wrote:
> If /dev/null is bind-mounted, /dev and /dev/null are on different
> devices, so the expected failure has an additional line describe
> the device change.

LGTM.

Reviewed-by: Carlos O'Donell <carlos@redhat.com>

> ---
>   support/tst-support_descriptors.c | 41 ++++++++++++++++++++++++++++++++-------
>   1 file changed, 34 insertions(+), 7 deletions(-)
> 
> diff --git a/support/tst-support_descriptors.c b/support/tst-support_descriptors.c
> index 97d7284c69..d25cb7d67a 100644
> --- a/support/tst-support_descriptors.c
> +++ b/support/tst-support_descriptors.c
> @@ -128,21 +128,48 @@ test_run (void)
>     support_capture_subprocess_free (&proc);
>     free (expected);
>   
> +  good = good && !support_record_failure_is_failed ();
> +  proc = support_capture_subprocess (&subprocess_changed_descriptor, NULL);
> +  good = good && support_record_failure_is_failed ();
> +  support_record_failure_reset (); /* Discard the reported error.  */
> +  report_subprocess_output ("subprocess_changed_descriptor", &proc);
> +
>     expected = xasprintf ("\nDifferences:\n"
>                           "error: descriptor %d changed from \"/dev/null\""
>                           " to \"/dev\"\n"
>                           "error: descriptor %d changed ino ",
>                           free_descriptor, free_descriptor);
> -  good = good && !support_record_failure_is_failed ();
> -  proc = support_capture_subprocess (&subprocess_changed_descriptor, NULL);
> -  good = good && support_record_failure_is_failed ();
> -  support_record_failure_reset (); /* Discard the reported error.  */
> -  report_subprocess_output ("subprocess_changed_descriptor", &proc);
> -  TEST_VERIFY (strstr (proc.out.buffer, expected) != NULL);
> +  if (strstr (proc.out.buffer, expected) != NULL)
> +    {
> +      /* No change of device.  */
> +      free (expected);

OK. Same case as before.

> +    }
> +  else
> +    {

OK. New case that we're handling.

> +      /* The device changed in addition to the inode number.  This
> +         happens if /dev/null is bind-mounted from another file
> +         system, so that /dev is on a difference device.  */
> +      expected = xasprintf ("\nDifferences:\n"
> +                            "error: descriptor %d changed from \"/dev/null\""
> +                            " to \"/dev\"\n"
> +                            "error: descriptor %d changed device ",
> +                            free_descriptor, free_descriptor);

OK.

> +      TEST_VERIFY (strstr (proc.out.buffer, expected) != NULL);
> +      free (expected);
> +
> +      /* We assume that the inode number changes, although in theory
> +         it is possible that the directory happens to have the same
> +         inode number as the null device because it is on a different
> +         file system.  */
> +      expected = xasprintf ("\nerror: descriptor %d changed ino ",
> +                            free_descriptor);
> +      TEST_VERIFY (strstr (proc.out.buffer, expected) != NULL);

OK.

> +      free (expected);
> +    }
> +
>     support_capture_subprocess_check (&proc, "subprocess_changed_descriptor",
>                                       0, sc_allow_stdout);
>     support_capture_subprocess_free (&proc);
> -  free (expected);
>   }
>   
>   static int
> 
> base-commit: ef2e5453b166b9339fd92b685c10312b423be7eb
> 


-- 
Cheers,
Carlos.


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

end of thread, other threads:[~2026-05-04 13:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-04 13:24 [PATCH] support: Improve tst-support_descriptors compatibility with containers Florian Weimer
2026-05-04 13:59 ` Carlos O'Donell

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