RFC: tunables failure indications...

Message ID xnlfrgq8n3.fsf@greed.delorie.com
State Committed
Commit a059f9505bbef1f22c6f52798a74184632929145
Headers

Commit Message

DJ Delorie Dec. 13, 2019, 8:21 p.m. UTC
  "Carlos O'Donell" <codonell@redhat.com> writes:
> Almost. _dl_fatal_printf is noreturn and calls _exit (127).

Done.

From b50d6a577bf2f118923ce0e1b159c4d659815405 Mon Sep 17 00:00:00 2001
From: DJ Delorie <dj@redhat.com>
Date: Fri, 13 Dec 2019 13:36:58 -0500
Subject: tunables: report sbrk() failure
  

Comments

Carlos O'Donell Dec. 13, 2019, 8:41 p.m. UTC | #1
On 12/13/19 3:21 PM, DJ Delorie wrote:
> "Carlos O'Donell" <codonell@redhat.com> writes:
>> Almost. _dl_fatal_printf is noreturn and calls _exit (127).
> 
> Done.
> 
> From b50d6a577bf2f118923ce0e1b159c4d659815405 Mon Sep 17 00:00:00 2001
> From: DJ Delorie <dj@redhat.com>
> Date: Fri, 13 Dec 2019 13:36:58 -0500
> Subject: tunables: report sbrk() failure
> 

LGTM for master if you proved this works by using gdb to set out to void
and confirmed it exits with the right error code and exits via _exit
(had a breakpoint on _exit and it triggers without showing exit on the
call chain).

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

> diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
> index e625ac1a7d..f0d7d42770 100644
> --- a/elf/dl-tunables.c
> +++ b/elf/dl-tunables.c
> @@ -45,12 +45,11 @@ tunables_strdup (const char *in)
>    while (in[i++] != '\0');
>    char *out = __sbrk (i);
>  
> -  /* FIXME: In reality if the allocation fails, __sbrk will crash attempting to
> -     set the thread-local errno since the TCB has not yet been set up.  This
> -     needs to be fixed with an __sbrk implementation that does not set
> -     errno.  */
> +  /* For most of the tunables code, we ignore user errors.  However,
> +     this is a system error - and running out of memory at program
> +     startup should be reported, so we do.  */
>    if (out == (void *)-1)
> -    return NULL;
> +    _dl_fatal_printf ("sbrk() failure while processing tunables\n");
>  
>    i--;
>  
>
  

Patch

diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index e625ac1a7d..f0d7d42770 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -45,12 +45,11 @@  tunables_strdup (const char *in)
   while (in[i++] != '\0');
   char *out = __sbrk (i);
 
-  /* FIXME: In reality if the allocation fails, __sbrk will crash attempting to
-     set the thread-local errno since the TCB has not yet been set up.  This
-     needs to be fixed with an __sbrk implementation that does not set
-     errno.  */
+  /* For most of the tunables code, we ignore user errors.  However,
+     this is a system error - and running out of memory at program
+     startup should be reported, so we do.  */
   if (out == (void *)-1)
-    return NULL;
+    _dl_fatal_printf ("sbrk() failure while processing tunables\n");
 
   i--;