mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] pthread_atfork: fix return value on malloc failure
@ 2022-11-12 13:31 Alexey Izbyshev
  2022-11-13 15:20 ` Szabolcs Nagy
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Izbyshev @ 2022-11-12 13:31 UTC (permalink / raw)
  To: musl

POSIX requires pthread_atfork to report errors via its return value,
not via errno. The only specified error is ENOMEM.
---
 src/thread/pthread_atfork.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/thread/pthread_atfork.c b/src/thread/pthread_atfork.c
index 76497401..2fbe23ca 100644
--- a/src/thread/pthread_atfork.c
+++ b/src/thread/pthread_atfork.c
@@ -1,3 +1,4 @@
+#include <errno.h>
 #include <pthread.h>
 #include "libc.h"
 #include "lock.h"
@@ -34,7 +35,7 @@ void __fork_handler(int who)
 int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
 {
 	struct atfork_funcs *new = malloc(sizeof *new);
-	if (!new) return -1;
+	if (!new) return ENOMEM;
 
 	LOCK(lock);
 	new->next = funcs;
-- 
2.37.2


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

* Re: [musl] [PATCH] pthread_atfork: fix return value on malloc failure
  2022-11-12 13:31 [musl] [PATCH] pthread_atfork: fix return value on malloc failure Alexey Izbyshev
@ 2022-11-13 15:20 ` Szabolcs Nagy
  2022-11-13 17:10   ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Szabolcs Nagy @ 2022-11-13 15:20 UTC (permalink / raw)
  To: musl

* Alexey Izbyshev <izbyshev@ispras.ru> [2022-11-12 16:31:01 +0300]:
> POSIX requires pthread_atfork to report errors via its return value,
> not via errno. The only specified error is ENOMEM.

this patch looks good.


> ---
>  src/thread/pthread_atfork.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/thread/pthread_atfork.c b/src/thread/pthread_atfork.c
> index 76497401..2fbe23ca 100644
> --- a/src/thread/pthread_atfork.c
> +++ b/src/thread/pthread_atfork.c
> @@ -1,3 +1,4 @@
> +#include <errno.h>
>  #include <pthread.h>
>  #include "libc.h"
>  #include "lock.h"
> @@ -34,7 +35,7 @@ void __fork_handler(int who)
>  int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
>  {
>  	struct atfork_funcs *new = malloc(sizeof *new);
> -	if (!new) return -1;
> +	if (!new) return ENOMEM;
>  
>  	LOCK(lock);
>  	new->next = funcs;
> -- 
> 2.37.2

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

* Re: [musl] [PATCH] pthread_atfork: fix return value on malloc failure
  2022-11-13 15:20 ` Szabolcs Nagy
@ 2022-11-13 17:10   ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2022-11-13 17:10 UTC (permalink / raw)
  To: musl

On Sun, Nov 13, 2022 at 04:20:23PM +0100, Szabolcs Nagy wrote:
> * Alexey Izbyshev <izbyshev@ispras.ru> [2022-11-12 16:31:01 +0300]:
> > POSIX requires pthread_atfork to report errors via its return value,
> > not via errno. The only specified error is ENOMEM.
> 
> this patch looks good.

Yes, looks good to me. Taking it with just one style thing changed
(not spelled out anywhere): generally source files keep the header for
the interface they're defining at the very top, with headers for
interfaces they use below that.

> 
> 
> > ---
> >  src/thread/pthread_atfork.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/thread/pthread_atfork.c b/src/thread/pthread_atfork.c
> > index 76497401..2fbe23ca 100644
> > --- a/src/thread/pthread_atfork.c
> > +++ b/src/thread/pthread_atfork.c
> > @@ -1,3 +1,4 @@
> > +#include <errno.h>
> >  #include <pthread.h>
> >  #include "libc.h"
> >  #include "lock.h"
> > @@ -34,7 +35,7 @@ void __fork_handler(int who)
> >  int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
> >  {
> >  	struct atfork_funcs *new = malloc(sizeof *new);
> > -	if (!new) return -1;
> > +	if (!new) return ENOMEM;
> >  
> >  	LOCK(lock);
> >  	new->next = funcs;
> > -- 
> > 2.37.2

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

end of thread, other threads:[~2022-11-13 17:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-12 13:31 [musl] [PATCH] pthread_atfork: fix return value on malloc failure Alexey Izbyshev
2022-11-13 15:20 ` Szabolcs Nagy
2022-11-13 17:10   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).